我rsync
的--dry-run
输出是:
% rsync --dry-run -avi --delete-after /home/blueray/Documents/rsync-test/src /home/blueray/Documents/rsync-test/dest
building file list ... done
.d..t...... src/
>f.st...... src/empty-asciidoc-document 3.adoc
>f+++++++++ src/empty-asciidoc-document 4.adoc
>f+++++++++ src/empty-asciidoc-document-renamed.adoc
*deleting src/empty-asciidoc-document.adoc
*deleting src/empty-asciidoc-document 2.adoc
sent 254 bytes received 27 bytes 562.00 bytes/sec
total size is 16 speedup is 0.06 (DRY RUN)
我正在寻找如下输出:
building file list ... done
.d..t...... src/
>f.st...... src/empty-asciidoc-document 3.adoc
>f+++++++++ src/empty-asciidoc-document 4.adoc
>f+++++++++ src/empty-asciidoc-document-renamed.adoc
*deleting src/empty-asciidoc-document.adoc
*deleting src/empty-asciidoc-document 2.adoc
sent 254 bytes received 27 bytes 562.00 bytes/sec
total size is 16 speedup is 0.06 (DRY RUN)
Warning: n files will be affected, do you want to continue?
到目前为止我想出的脚本是:
#!/bin/bash
affected_files=$(rsync --dry-run -avi --delete-after /home/blueray/Documents/rsync-test/src /home/blueray/Documents/rsync-test/dest)
echo $affected_files
number_of_affected_files=$(echo $affected_files | grep src | wc -l)
echo "Warning: ${number_of_affected_files} files will be affected, do you want to continue?"
while true; do
case $yn in
[Yy]* ) rsync -avi --delete-after /home/blueray/Documents/rsync-test/src /home/blueray/Documents/rsync-test/dest; break;;
[Nn]* ) exit;;
* ) read -p "Please answer yes or no: " yn;;
esac
done
然而,它有一些问题。$affected_files
不保持换行符。所以,该脚本不起作用。此外,我不确定是否$affected_files | grep src | wc -l
给出了受影响文件的实际数量。
我能做些什么?
答案1
OP在这里,我当前使用的脚本是:
#!/bin/bash
rsync -ab --dry-run --stats --human-readable --inplace --debug=NONE --log-file=rsync.log --backup-dir=rsync_bak.$(date +"%d-%m-%y_%I-%M-%S%P") --log-file-format='%t %f %o %M' --delete-after /home/blueray/Documents/rsync-testsrc /home/blueray/Documents/rsync-testdest | sed -e '1d;5,12d;14,17d'
echo -e "\nDo you want to continue?"
while true; do
case $yn in
[Yy]* ) rsync -ab --human-readable --inplace --info=PROGRESS2,BACKUP,DEL --debug=NONE --log-file=/home/blueray/Documents/rsync-testdest/rsync.log --backup-dir=rsync_bak.$(date +"%d-%m-%y_%I-%M-%S%P") --log-file-format='%t %f %o %M' --delete-after /home/blueray/Documents/rsync-testsrc /home/blueray/Documents/rsync-testdest; break;;
[Nn]* ) exit;;
* ) read -p "Please answer yes or no: " yn;;
esac
done