Sunday, March 8, 2009

Backing up Windows Vista with Free Software

I’ve been attempting to deal with the sad state of backup affairs that Windows Vista is in.  I have one computer with a spare hard drive that I could easily dump files to.  This computer is running Vista Basic which contains a backup program that can only be manually invoked and which only does partial backups.  I have another computer running Vista Home Premium which can automate backups but has no spare hard drive and I’m suffering from well documented issues with Vista and sharing remote disks.
I looked for free or cheap programs to help me automate this task but most would have been difficult to recover from; as they used ZIP archives.   I preferred a “rsync” based solution as thats what I use under Linux with great success.  So here are the steps I used to get it working.  This is a collection of bits of information I found all over the web.

Cygwin Setup

The first step was to install Cygwin.  Using the Cygwin SETUP.EXE, make sure and install the “rsnapshot” program.  This program automates using rsync to backup the hard drive (using hard links to save space) and also doing the housework of rotating directories over time.
It is *very* important that after installing cygwin that you tell it to not use NT-style security.  You will run into unsolvable file permission issues with your backed up files unless you do this next step.  Navagate to My Computer->Properties->Advanced->Environment Variables->System Variables.   Either edit or add “CYGWIN = nontsec tty".
Another option would be to investigate cwrsync.  It basically automates the above steps for you; installing a mini-cygwin environment within its own directory tree.

Shadow Copy Support

All versions of Vista include support for creating Shadow versions of drives.  This allows you to see a file system in a consistent state at some exaxt point in time.  I believe it also allows you to open/read files that applications already have opened.  Window’s Backup and most commercial backup programs make us of this feature.
Microsoft has a command line program that allows you to hook into this feature.  You can request to create a shadow copy of a drive and mount it to a drive letter.  I’ve found that backing up a shadow drive is infinitely more stable then backing up an live drive.
The steps later require installing this command line program.  Install the Volume Shadow Copy Service SDK.

rsnapshot setup

Edit /etc/rsnapshot.conf to your liking.  Here are some options that I used to backup my C: drive (shadowed as a J: drive) to my F: drive .
snapshot_root /cygdrive/f
exclude_file /etc/rsnapshot.exclude
logfile /cygdrive/f/snapshot.log
one_fs
no_create_root 1
backup /cygdrive/j/ localhost/ 
Next, you’ll need to create the file /etc/rsnapshot.exclude file that is referenced above.  It contains a list of Vista’s default junction points and will prevent copying the same file multiple times and prevent infinit recursion error messages from being printed.
#References:
#http://codydunne.blogspot.com/2008/09/rsyncd-exclusions-for-using-backuppc-on.h
tml
#http://www.svrops.com/svrops/articles/jpoints.htm

#Junction points or symlinks
- /cygdrive/j/Users/All Users
- /cygdrive/j/Users/Default User
- /cygdrive/j/Users/All Users/Application Data
- /cygdrive/j/Users/All Users/Desktop
- /cygdrive/j/Users/All Users/Documents
- /cygdrive/j/Users/All Users/Favorites
- /cygdrive/j/Users/All Users/Start Menu
- /cygdrive/j/Users/All Users/Templates
- /cygdrive/j/Users/Public/Documents/My Music
- /cygdrive/j/Users/Public/Documents/My Pictures
- /cygdrive/j/Users/Public/Documents/My Videos
- /cygdrive/j/ProgramData/Application Data
- /cygdrive/j/ProgramData/Desktop
- /cygdrive/j/ProgramData/Documents
- /cygdrive/j/ProgramData/Favorites
- /cygdrive/j/ProgramData/Start Menu
- /cygdrive/j/ProgramData/Templates
- /cygdrive/j/Documents and Settings

#Excludes these junction points common to every user profile
- /cygdrive/j/Users/*/Application Data
- /cygdrive/j/Users/*/Cookies
- /cygdrive/j/Users/*/Local Settings
- /cygdrive/j/Users/*/My Documents
- /cygdrive/j/Users/*/NetHood
- /cygdrive/j/Users/*/PrintHood
- /cygdrive/j/Users/*/Recent
- /cygdrive/j/Users/*/SendTo
- /cygdrive/j/Users/*/Start Menu
- /cygdrive/j/Users/*/Templates
- /cygdrive/j/Users/*/AppData/Local/Application Data
- /cygdrive/j/Users/*/AppData/Local/History
- /cygdrive/j/Users/*/AppData/Local/Temporary Internet Files
- /cygdrive/j/Users/*/Documents/My Music
- /cygdrive/j/Users/*/Documents/My Pictures
- /cygdrive/j/Users/*/Documents/My Videos

#Temporary and in-user user data
- /cygdrive/j/Users/*/AppData/Local/Microsoft/Windows/Temporary Internet Files
- /cygdrive/j/Users/*/AppData/Local/Temp
- /cygdrive/j/Users/*/NTUSER.DAT
- /cygdrive/j/Users/*/ntuser.dat.LOG1
- /cygdrive/j/Users/*/ntuser.dat.LOG2
- /cygdrive/j/Users/*/AppData/Local/Microsoft/Windows/UsrClass.dat
- /cygdrive/j/Users/*/AppData/Local/Microsoft/Windows/UsrClass.dat.LOG1
- /cygdrive/j/Users/*/AppData/Local/Microsoft/Windows/UsrClass.dat.LOG2
- /cygdrive/j/Users/*/AppData/Local/Microsoft/Windows Defender/FileTracker
- /cygdrive/j/Users/*/AppData/Local/Mozilla/Firefox/Profiles/*/Cache
- /cygdrive/j/Users/*/AppData/Roaming/Microsoft/Windows/Recent
- *.lock

#Installation folders and system data
/cygdrive/j/Program Files
/cygdrive/j/Windows
/cygdrive/j/$Recycle.Bin
/cygdrive/j/MSOCache
/cygdrive/j/System Volume Information
/cygdrive/j/autoexec.bat
/cygdrive/j/bootmgr
/cygdrive/j/BOOTSECT.BAK
/cygdrive/j/config.sys
/cygdrive/j/hiberfil.sys
/cygdrive/j/pagefile.sys

Scripts to perform copy

The following script should be used as a template.  You will need a script for each “interval” line in your /etc/rsnapshot.conf and it needs to pass in “hourly”, “daily”, “weekly”, or “monthly” to the rsnapshot program.
The script will create a shadow version of the C: drive and map it to drive J:.  It will then invoke rsnapshot to backup the J: drive and afterwards delete the showdow drive.
#!/bin/sh
### Change to temporary directory so that we have a known location
### of temporary files created in local directory.
cd /tmp
### Create shadow drive of C: and store off its ID
###
/cygdrive/c/Program\ Files/Microsoft/VSSSDK72/TestApps/vshadow/bin/release-serve
r/vshadow.exe -p -nw -script=vars.bat c:
SHADOW_ID_1=`grep SHADOW_ID_1 vars.bat | sed "s/.*=//"`
### Map to drive J:
###
/cygdrive/c/Program\ Files/Microsoft/VSSSDK72/TestApps/vshadow/bin/release-serve
r/vshadow.exe -el=$SHADOW_ID_1,J:
### Run backup
###
/usr/bin/rsnapshot daily >> /cygdrive/f/rsnapshot.stdout 2>&1
### Delete shadown drive
###
/cygdrive/c/Program\ Files/Microsoft/VSSSDK72/TestApps/vshadow/bin/release-serve
r/vshadow.exe -ds=$SHADOW_ID_1
### Go back to temporary directory and clean up files.
###
cd /tmp
rm vars.bat

Scheduling Backups

You can use Window’s Scheduled Tasks tool to run the above script at the intervals of your chosing.  Start->Accessories->System Tools->Scheduled Tasks.
The command line to use is basic form shown below.  Replace with the filename you created using above script template.
c:\cygwin\bin\bash.exe /path/to/rsnapshot_xxx.sh
Note: Just because you run the “weekly” interval on a given day each week, you still need to run the “daily” interval that same day.  Same thing applies for all intervals.

Automating emails to cancel iCalendar events

In a follow up to my post about emailing iCalendar requests,you may wish to send out an automated email to cancel that request and have the user automatically be prompted to remove it as well.  That can be handled with minor modification to the previous script and .ics files.

First, find the following piece of code:
icspart = MIMEBase('text', 'calendar', **{'method' : 'REQUEST', 'name' : 'meeting.ics'})
and change that to a CANCEL method:
icspart = MIMEBase('text', 'calendar', **{'method' : 'CANCEL', 'name' : 'meeting.ics'})
Next, in the original .ics file, change any line with METHOD: to read METHOD:CANCEL and any line with STATUS: to read STATUS:CANCELLED.