Not wanting to hard-code passwords, I needed to do a little research in key exchanges for ssh/scp. What I came up with is this...
Initial setup:
1. Install Cygwin. Make sure to select the additional ssh, bzip2, and vim.
2. Generate ssh keys:
ssh-keygen -t rsa1(I will admit that I'm not sure which of these keys are actually required, so I simply generate all three.) Note that if you provide no passphrase, it will not be required in the script -- hint, hint.
ssh-keygen -t rsa
ssh-keygen -t dsa
3. Copy ssh keys to the Linux server:
cat *.pub | ssh user@server "cat > ~/.ssh/authorized_keys"
Now you need to script the backup of files. Here's a copy of my backup script:
#!/bin/bashYou'll note that I see the
PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin
echo "Starting backup @ $(date)"
cd /cygdrive/c/Documents\ and\ Settings/Rob/My\ Documents
tar cjf - --exclude Emulators --exclude "Virtual CD*" * 2>/tmp/backup-errors.log |
ssh user@server "cat >rob/backup-new.tbz"
ssh user@server "cd ~/rob/
rm -f backup-old-2.tbz
mv -f backup-old-1.tbz backup-old-2.tbz
mv -f backup-current.tbz backup-old-1.tbz
mv backup-new.tbz backup-current.tbz
ls -lh"
echo "Completed backup @ $(date)"
echo -n "Press [ENTER]: "
read X
PATH - that's because launching from the XP scheduler gives a different environment than from the typical Cygwin environment. Also, the tar pipes the backup file directly into SSH and it gets written to a file on the Linux server. Finally, I move the files around to keep 3 weeks of backup.Schedule the script: This is in the Windows XP control panel, Scheduled Tasks. Create a new task, start it in
c:\cygwin\bin (where-ever Cygwin is installed). Then, I found it easiest to browse to the shell script and select it and then prepend bash to that value. My Run entry looks like this:bash "C:\Documents and Settings\Rob\My Documents\bin\backup-rob.sh"That's it! Test it a few times. Make sure you can
untar it. Wait to make sure the scheduler kicks it off.

No comments:
Post a Comment