Return to Snippet

Revision: 22805
at February 4, 2010 06:23 by berkes


Updated Code
#!/bin/sh

RSYNC=/usr/bin/rsync
SSH=/usr/bin/ssh
KEY=$HOME/.ssh/id_dsa_passwdless
RUSER=foo
RHOST=ssh.example.com
RPATH=/var/www/
LPATH=$HOME/archive/example-com/

date=`date "+%Y-%m-%dT%H:%M:%S"`

$RSYNC -v -n -az -e "$SSH -i $KEY" --link-dest=$LPATH/current [email protected]$RHOST:$RPATH $LPATH/back-$date

rm $LPATH/current && 
 ln -s $LPATH/back-$date $LPATH/current

Revision: 22804
at February 4, 2010 06:15 by berkes


Updated Code
#!/bin/sh

RSYNC=/usr/bin/rsync
SSH=/usr/bin/ssh
KEY=$HOME/.ssh/id_dsa_passwdless
RUSER=foo
RHOST=ssh.example.com
RPATH=/var/www/
LPATH=$HOME/archive/example-com/

date=`date "+%Y-%m-%dT%H:%M:%S"`

$RSYNC -v -n -az -e "$SSH -i $KEY" --link-dest=$LPATH/current [email protected]$RHOST:$RPATH $LPATH/back-$date

rm $SOURCE/current && 
 ln -s $LPATH/back-$date $LPATH/current

Revision: 22803
at January 22, 2010 16:05 by berkes


Initial Code
#!/bin/bash

HOST=ssh.example.com
REMOTEUSER=example-username
DEST=$HOME/Archive/example-com/
SOURCE=/var/www/example-com/

DATE=`date "+%Y-%m-%dT%H:%M:%S"`

rsync -az --link-dest=$DEST/current [email protected]$HOST:$SOURCE $DEST/back-$DATE

rm $SOURCE/current && ln -s $DEST/back-$DATE $DEST/current

Initial URL
webschuur.com

Initial Description
This script pulls in files with [rsync](http://samba.anu.edu.au/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.
* RHOST=ssh.example.com -- 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 (`backup_example-com.sh`) in `~/bin`, or any other directory available in `$PATH`. And then add it to crontab.

See a howto here: http://troy.jdmz.net/rsync/index.html

Initial Title
Simple rsync backupscript.

Initial Tags
backup, unix, linux

Initial Language
Bash