首頁>Linux>source

我的 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 是否提供實際數量的受影响檔案。

我该怎麼办?

最新回復
  • 5月前
    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
    

  • arch linux:笔記本電脑關機的原因
  • make:確定makefile配方的型別