我有一个脚本可以备份整个系统,但我看不到它的进度。我找到了许多带有进度条脚本的答案,但我不知道如何将它们实现到我的备份脚本中。
我的备份脚本:
#!/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
无需使用
pv
使事情变得复杂,虽然非常好,但它会使吞吐量受到一点影响。更好的解决方案是使用 tar 自己的函数 --checkpoint=
和 --checkpoint-action
,如下所示:
tar -p -b1024 --record-size=1K --checkpoint=.100 --zstd -cf ${FNAME} ${DNAME}
请参阅 tar 手册。