This post is a bit different than most of mine, but I had to put it somewhere.

I back up several Windows 2003 servers with BackupPC and rsync over ssh.  This is basically how I do it.

  • Download cygwin 1.7+ from the regular place
  • Install the default system, plus the following: cygrunsrv, openssh, and rsync
  • I also install joe (my editor of choice), and procps (for top)
  • Start a cygwin shell and type:
# ssh-host-config -y
# cygrunsrv -S sshd
  • 5. I then attempt to ssh into my backupPC system from cygwin, just a nice test, and creates the .ssh directory for me.
  • 6. Copy BackupPC’s public key over
# scp root@backuppc:/var/lib/backuppc/BackupPCkey.pub ~/.ssh/authorized_keys
  • Install the following scripts to Administrators home directory

pre-backuppc.sh

#!/bin/bash
# script to create shadow copies of Windows drives and export them to a
# drive letter for BackupPC backup
# the shadow copies get mount to c:\shadow\(drive letter).  The directory
# structure must exist

# Launches passed input via 'at' to get around $USERNAME=SYSTEM
# problem under ssh login where the shell lacks permsisions to run
# commmands like vshadow or dosdev
function at_launch ()
{
    local h m s wait1 command
    if [ $3 != "" ] ; then
        command="${1} ${2} >> ${3}"
    else
        command="${1} ${2}"
    fi

    set -- $(date +"%H %M %S")
        h=$((10#$1))  #Note explicitly use base 10 so that 08 and 09 not interpreted as bad octal
    	m=$((10#$2 +1)) #Advance minutes by 1
    	s=$((10#$3))
    	wait1=$((60 - $s))
    [ $s -gt 55 ] && let "m += 1" "wait1 += 60" # Make sure >5 seconds left
    [ $m -ge 60 ] && let "m %= 60" "h += 1" #Overflow minutes
    let "h %= 24"
       	at $h:$m $(cygpath -w $(which bash.exe)) -c \"$command\"
#       	> /dev/null

    echo Running \'$command\' at $h:$m
    return $wait1
}

# create the command to shadow the drive, and wait 2 minutes plus the seconds
# before the at command runs before returning (make sure shadow copy is made)
function shadow_drive ()
{
    date
    echo Shadowing Drive $@
    local wait1
    drive=$@

    at_launch "/cygdrive/c/WINDOWS/vshadow.exe -p" $drive "/home/Administrator/vshadow-out"
    wait1=$?
    let "wait1 += 120"
    echo sleeping for $wait1
    sleep $wait1
    date
    echo done sleep
}

# get the guids from the vshow-out file and place them into the shadow-guids
# file for the post-backuppc scripts use (and hours for mapping to directory)
function get_guids ()
{
    echo Getting shadow copy GUIDS
    cat ~/vshadow-out | grep "* SNAPSHOT ID" | awk '{print $5}' >> ~/shadow-guids
}

function map_shadow ()
{
    echo Mapping GUID $1 to $2
    local wait1
    local guid="$1"
    local dir="$2"
    at_launch /cygdrive/c/WINDOWS/vshadow.exe -el=$guid,$dir "/home/Administrator/map.out"
    wait1=$?
    let "wait1 +=30"
    sleep $wait1
}

date

# get rid of the guids file if it exists
rm ~/shadow-guids
rm ~/vshadow-out
rm ~/map.out

sleep 10

# create the snapshots
shadow_drive c:
shadow_drive h:
shadow_drive j:

# get the guids into a single file
get_guids

loop=0

# create the shadow directory structure AFTER we make the shadow copies
# the post-backuppc.sh script deletes this tree after removing the mounts
mkdir /cygdrive/c/shadow
mkdir /cygdrive/c/shadow/c
mkdir /cygdrive/c/shadow/h
mkdir /cygdrive/c/shadow/j

# loop throuh the guids and map to mount point
# assumes guids in file are in order of shadows created
while read line ;
do
   if [ $loop == 0 ] ; then
       map_shadow $line "c:\\\\\shadow\\\\\c"
   fi

   if [ $loop == 1 ] ; then
       map_shadow $line "c:\\\\\shadow\\\\\h"
   fi

   if [ $loop == 2 ] ; then
       map_shadow $line "c:\\\\\shadow\\\\\j"
   fi

   let "loop += 1"
done < ~/shadow-guids

post_backuppc.sh

#!/bin/bash

# script to delete the shadow copies used by backuppc

while read line ;
do
  vshadow -ds=$line
done < ~/shadow-guids

# now clean up the directory structure
#rmdir /cygdrive/c/shadow

8. In the BackupPC config for the system (I use the web page to edit the config) Add the following

DumpPreUserCmd: $sshPath -c blowfish -q -x -l Administrator swtwd01.norscan.com /usr/bin/bash -l -c /home/Administrator/pre-backuppc.sh
DumpPostUserCmd:$sshPath -c blowfish -q -x -l Administrator swtwd01.norscan.com /usr/bin/bash -l -c /home/Administrator/post-backuppc.sh

* sometime between the release of Cygwin 1.7 and the current version, ssh login became case sensitive.  I used to log in with ‘-l administrator’ and now I have to log in with ‘-l Administrator’.  That one set me back a bit.

Once you do a change to the backups, make sure you do a full backup right away.  It’s a good test, and backuppc doesn’t like it’s backup directory structure changed during incrementals.

I’m now looking into the information found here: http://www.goodjobsucking.com/?p=219 to see if I can do a psuedo bare-metal restore on the servers.

And that’s it. I have BackupPC backup /cygdrive/c/shadow, and all is well. Now, if someone can tell me how to color/syntax highlight bash code in WordPress, I’d be happy.