I am not a Linux guru by any means but I know enough to get around. I am going to share with you my scripts for rotating the backups for a website that I manage. Anyone who knows a better way is welcome to share with me, but for now this is what I have and it works well enough for me.
Learning to write shell scripts was not actually that hard. I found a good resource on the syntax (grammar) which helped me figure out the rest. My script for rotating the daily backups is below. It really could be done in one long line using just the rsync command, but to make it more portable and readable I used a lot of variables. The script should be pretty well commented so you should be able to pick up on what everything is doing. Once you have the script copied you just need to create a cron job using crontab. If you have any questions or comments on this, please let me know.
#!/bin/bash
#
# daily backup script the rsync way
# command variables
# this makes it easier to transfer the script to different
# flavors of Linux/Unix. sometimes the locations of these
# commands are in different places.
RSYNC=/usr/bin/rsync
SSH=/usr/bin/ssh
CP=/bin/cp
# directory variables
# RDIR is the remote directory you will be copying the contents of.
# LDIR is the local directory you want to copy to.
# BACKUP is the backup folder that will hold everything.
RDIR=./www/
LDIR=~/backup
# remote host variable
# this is the remote host you are connecting to via ssh.
RHOST=hostname
# rsync exclude file
# this file must exist or it will cause an error. anything you don't
# want to include from the source you will add it as a line in this file.
EXCLUDED=$LDIR/excluded_backup
# rsync options variable
# these are the options used for rsync to get the kind of backups
# you want.
# -a is the archive option which will do a lot of different things
# for you.
# -z is for compression, and -H is for preserving the hard-links.
# --delete will delete any files on the destination that are no longer
# in the source directory.
OPTS="-azH --backup --delete --exclude-from=$EXCLUDED"
# finally the rsync command that should create 7 daily backups
$RSYNC -e $SSH $OPTS $RHOST:$RDIR $LDIR/daily-`date +%u`
Bookmarks about Rsync said
[...] – bookmarked by 1 members originally found by biofreak on 2008-11-09 Rotating Daily Backups using Rsync in Linux http://geekstar.wordpress.com/2008/08/17/rotating-daily-backups-using-rsync-in-linux/ – bookmarked [...]