gpt4 book ai didi

linux - 如何在备份脚本中实现进度条

转载 作者:太空宇宙 更新时间:2023-11-04 11:49:41 24 4
gpt4 key购买 nike

我有一个脚本可以备份整个系统,但我看不到它的进度。我在进度条脚本中找到了很多答案,但我不知道如何将它们实现到我的备份脚本中。

我的备份脚本:

#!/bin/bash

Backup_system="Backup_$(date +%Y-%m-%d).tar.gz"

# Record start time by epoch second
start=$(date '+%s')

# List of excludes in a bash array, for easier reading.
excludes=(--exclude=/$Backup_system)
excludes+=(--exclude=/proc)
excludes+=(--exclude=/lost+found)
excludes+=(--exclude=/sys)
excludes+=(--exclude=/mnt)
excludes+=(--exclude=/media)
excludes+=(--exclude=/dev)

if ! tar -czf "$Backup_system" "${excludes[@]}" /; then
status="tar failed"
elif ! mv "$Backup_system" ~/Backups ; then
status="mv failed"
else
status="success: size=$(stat -c%s ~/Backups/$Backup_system) duration=$((`date '+%s'` - $start))"
fi

# Log to system log; handle this using syslog(8).
logger -t Backup_system "$status"

最佳答案

您可以使用 pv,为每个文件制作一个进度条,如下所述: https://superuser.com/questions/168749/is-there-a-way-to-see-any-tar-progress-per-file

关于linux - 如何在备份脚本中实现进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56416454/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com