Monday, February 18, 2013

Backing up Windows 7 with rsync

I needed to back up my wife Michelle's computer to our server. I tried using the native Windows 7 backup/restore client with a samba share, it failed twice in ten hours. The Windows 7 backup/restore client does work flawlessly to an external  drive, but; that was not my current goal. Instead of trying a third time, I tried another backup client over ftp, it was not quite what I wanted.

 I decided to go with what I know,Linux, rsync and samba. What I wanted to do was only mount the share during the backup. I also did not want rsync to run if the share did not mount because if rsync ran it would delete the previous backup since I am using the "--delete" flag and the "/mnt/PC" directory would be empty.  If it did mount I want it to log the results and unmount the share when done. Here is the script I came up with

#mounts share to be backed up exits if not mounted
mount -t cifs -o username=USER,password=PASSWORD // /mnt/PC >> logtest && 
#performs backup and logs results 
rsync -r -t -v --delete --safe-links --progress /mnt/PC/ /mnt/backup/PC | tail >> backuplog; 
#will attempt to unmount share whether it is mounted or not 
umount -l /mnt/PC; 
#adds timestamp to log file
date >> backuplog

This was the final link in the backup chain for my wifes data. Her computer is already using RAID1, backing up to Carbonite and the Windows 7 backup/restore client to an external drive. The Windows 7 backup/restore client did save us when Michelle's hard drive failed last year. I replaced the hard drive and used the Windows 7 backup to restore her computer.  We have done all of this because she is focusing on her photography business "Shell Burdine Photography" this year. I want her and her clients images/data to be safe.