Friday, November 12, 2010

Rsync and vim

Monday and Tuesday was vim. Apparently you can run a command inside vim by adding ! before it. Seems very nice for when your physically work at a server and you don't have to close out of vim. Another very awesome feature is that you can split your windows vertically or horizontally in vim to display two files or the same one. You either run split or vsplit and the file after it if you want the window to have another file. Most of the time I don't need this since I can just ssh multiple times but as before this could be a big help when interacting directly with a server. Onto rsync.

Jeff wants a backup in place for our LTSP and he pointed me towards rsync. Rsync copies files but as implied it syncs them so it only overwrites a file if it has changed so less bandwidth is wasted and time. It can also retain file permissions which is cool beans. It will also be run as cron job so it occurs every night. I've researched it and this seems to be the most comprehensive article on rysnc and cron.

What will happen is I will generate ssh keys for our servers because without them it isn't possible for the LTSP server to run the script without entering a password. Once the keys are in place and the ssh config is modified I will create a script along the lines of this.

#!/bin/bash

SOURCEPATH=’/source/directory’
DESTPATH=’/destination’
DESTHOST=’123.123.123.123′
DESTUSER=’destuser’
LOGFILE=’rsync.log’

echo $’\n\n’ >> $LOGFILE
rsync -av –rsh=ssh $SOURCEPATH $DESTUSER@$DESTHOST:$DESTPATH 2>&1 >> $LOGFILE
echo “Completed at: `/bin/date`” >> $LOGFILE

I'm debating whether to just make the script one line or use this one where you modify the variables. After that I will use crontab to have the script run ever night and backup the home directory and everything will be hunky dory. Or so I hope.