I've made a backup bash script using rsync to sync files between my laptop and USB. Basically, I use rsync -uai x y to backup x to y. Now, the files transfer fine, but interestingly the script doesn't update old files on y with the newer versions from x. It just skips them. Isn't the -u switch supposed to over-write the old versions with the new one?
The script runs without any errors and the log files confirm that new files are being written, but old ones are being skipped rather than overwritten.
Any help is much appreciated.
. The full source code is attached below, but
- Code: Select all
# Purpose: For syncing files between two drives, where changes might occur
# on either. (I use it to backup documents between a PC and USB)
# Rsyncs $OLD-PATH to $NEW-PATH, ignoring newer files on $NEW-PATH. Then, rsyncs $NEW-PATH onto $OLD-PATH, ignoring newer files.
# The output is redirected to $logLocation, so you can grep through what's been copied later at your leisure.
# Usage: ./ backup-script.sh
# Author: Cammo
# Date: Mon 12 May 2014
# Version: 0.5
# Disclaimer: Feel free to use it, but don't blame me if your computer conks out.
# Enter your required params here...
chown $myName: $mountPoint; chown $myName: $logLocation
mount '/dev/sdb1' $mountPoint>>$logLocation
echo $(date +"%c")>>$logLocation
echo 'Hard drive path = ' $OldPath>>$logLocation
echo 'USB path = ' $NewPath>>$logLocation
echo "Starting backup from $OldPath to $NewPath" >>$logLocation
rsync -uai $OldPath $NewPath>>$logLocation
echo 'Syncing Old->New done'>>$logLocation
rsync -uai $NewPath $OldPath>>$logLocation
echo 'Syncing New->Old done'>>$logLocation
chown -R $myName: $NewPath>>$logLocation
echo 'taking ownership of new files -> done'>>$logLocation