Simple rsync backupscript.

/ Published in: Bash
Save to your folder(s)

This script pulls in files with [rsync](, storing them locally with hardlinks for unchanged, and real files for changed -files.

* KEY=$HOME/.ssh/id_dsa_passwdless -- an id_rtsa key without a password. --adding this to remote authorized keys must be done with care: you will prbably want to whitelist one IP-adress.
* -- the host where to connect to using ssh, or rsync.
* RUSER=example-username -- the username on the host. Must have _read_ access in the SOURCE dit (see below).
* LPATH=$HOME/Archive/example-com/ -- where to place the backups
* RPATH=/var/www/example-com/ -- the to-be-backuped dir.

You probably want to add this as script (``) in `~/bin`, or any other directory available in `$PATH`. And then add it to crontab.

See a howto here:

Copy this code and paste it in your HTML
  1. #!/bin/sh
  3. RSYNC=/usr/bin/rsync
  4. SSH=/usr/bin/ssh
  5. KEY=$HOME/.ssh/id_dsa_passwdless
  6. RUSER=foo
  8. RPATH=/var/www/
  9. LPATH=$HOME/archive/example-com/
  11. date=`date "+%Y-%m-%dT%H:%M:%S"`
  13. $RSYNC -v -n -az -e "$SSH -i $KEY" --link-dest=$LPATH/current $RUSER@$RHOST:$RPATH $LPATH/back-$date
  15. rm $LPATH/current &&
  16. ln -s $LPATH/back-$date $LPATH/current


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.