将MAC文件夹与FAT外部驱动器同步进行备份 - Bash rsync命令在本地文件夹端外部驱动器文件夹之间具有不同的行为

时间:2016-10-05 16:21:08

标签: bash rsync

我正在从bash脚本运行此命令

rsync -avzh $SourceFolder/ $DestinationFolder

如果我将SourceFolder和DestinationFolder作为本地文件夹(都在我的MAC上)运行它,它的行为正确。这意味着它复制新文件并将较新版本覆盖到DestinationFolder。

如果我使用外部驱动器文件夹作为DestinationFolder运行脚本,它会复制并覆盖SourceFolder的整个内容。

我怎样才能避免这种情况,让脚本每次只覆盖较新版本的文件而不是SourceFolder的全部内容?

1 个答案:

答案 0 :(得分:0)

我不知道为什么这会被低估,可能是因为答案已经存在。无论如何,我认为这是一个特定的问题。

几个小时之后,这是我修复脚本的方法。关键在于--update--modify-window=1 rsync命令选项。

这是工作脚本(另外我要从外部文件中排除文件)。

#!/bin/sh

ScriptName=${0##*/}

# this script sync SourceFolder with DestinationFolder 
# to a FAT32 external drive, excluding files from ExcludeFile 

### --- EDIT FOLDERS HERE --- ###
SourceFolder='/Users/matteo'
DestinationFolder='/Volumes/HITACHI/MatteoMainFolderBackup'
ExcludeFile='/Users/matteo/.backupignore'

### --- DISPLAY SOME INFO --- ###
echo "Starting " $ScriptName
printf "WARNING! This script sync all files from SourceFolder to DestinationFolder \n"
echo "SourceFolder: " $SourceFolder
echo "DestinationFolder: " $DestinationFolder
echo "ExcludeFile: " $ExcludeFile
printf "### Start Syncing files ###\n"

### --- OPERATIONS --- ###
rsync   --archive \
        --delete \
        --delete-excluded \
        --exclude-from=$ExcludeFile \
        --modify-window=1 \
        --progress \
        --update \
        --verbose \
        $SourceFolder/ $DestinationFolder

### --- END --- ###
echo $ScriptName " ended"
相关问题