One of the few things for I still have to switch to Windows is backup.
As I wrote before, for that job I have put up a small bat file that relies on robocopy to do the job.
Finally I came up with a similar shell script for Linux that does the same job using rsync.
Now the backup script on Linux reads the same list file as the backup script on Windows (my NTFS drives are mounted in Linux).
It looks like this
#!/bin/sh
TARGET=/media/SAMSUNG/BACKUP
SYNC='rsync -rptgovF --delete --delete-excluded'
# Backup Windows drives
LIST=/home/peter/Documents/Documents/Backup/backup.lst
cat $LIST | fromdos | sed s/\\\\/\\//g | while read -r line
do
echo BACKUP $line
case "$line" in
C:*) $SYNC "/media/Windows 7${line#C:}/" "$TARGET${line#C:}";;
D:*) $SYNC "/media/Data${line#D:}/" "$TARGET${line#D:}";;
esac
done
# Backup Linux drive
echo BACKUP /home/peter
$SYNC /home/peter/ "$TARGET/home/peter"
The F option tells rsync to look for file .rsync-filter in each directory. If it is present it specifies files to exclude from that directory.
In a typical UNIX way several commands are chained via pipes.
fromdos is used to convert the text file from Windows to UNIX format, i.e. strip CR chars as they would cause problems later on.
sed is used to replace all back slashes to forward slashes.
${line#C:} and {line#D:} macros produce the path without the drive.
UNIX shell scripting proved once again to be very powerful.
No comments:
Post a Comment