Skip to content

Instantly share code, notes, and snippets.

@tmc
Created March 7, 2009 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmc/75158 to your computer and use it in GitHub Desktop.
Save tmc/75158 to your computer and use it in GitHub Desktop.
#!/bin/sh
num=21 # 3 weeks
for h in albert; do
date=`date +%Y%m%d-%H%M%S`
dir=/home/backup/$h.d
manifest=$dir/manifest
# Find the most recent backup
touch $manifest
newest=`tail -n 1 $manifest`
if [ -z "$newest" ]; then
linkarg=""
else
linkarg="--link-dest=$dir/$newest"
fi
# Perform the backup
rsync $linkarg -a --filter=". $dir/rsync.inc" --filter="- *" $h:/ $dir/$date
# If we have too many backups, delete the oldest
lines=`wc -l < $manifest`
if [ $lines -gt $num ]; then
oldest=`sed 1q $manifest`
rm -rf $dir/$oldest
sed 1d $manifest > $manifest.new
mv $manifest.new $manifest
fi
echo $date >> $manifest
rm /home/backup/$h && ln -s $h.d/$date /home/backup/$h
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment