User Tools

Site Tools


rsync

rsync

Simple method for creating incremental backups

# create directory for the initial backup
mkdir -p server_backup/current && cd server_backup/current
 
# these steps are needed for each backup
sudo rsync -avz --delete ---exclude '/proc/*' --exclude '/sys/*' -e ssh root@host_to_backup:/ .
cd ..
sudo cp -al current backup_2010-06-12

Example script

server_backup.sh
#!/bin/bash
 
SSH_HOST=myserver.example.com
SSH_USER=root
SSH_PATH=/
EXCLUDE_FILE=/home/foobar/bin/server_backup.exclude
 
##############################################
 
if [[ $UID == "0" ]]; then
	SUDO=
else
	SUDO=sudo
fi
 
SSH=ssh
RSYNC=rsync
RSYNC_OPTS="-avz --delete --exclude-from=${EXCLUDE_FILE}"
RSYNC_PATH=.
 
 
# do the job
$SUDO $RSYNC $RSYNC_OPTS -e $SSH ${SSH_USER}@${SSH_HOST}:${SSH_PATH} $RSYNC_PATH
server_backup.exclude
/dev/*
/proc/*
/sys/*
/tmp/*
/var/cache/apt/archives/*
cd server_backup/current
server_backup.sh
cd ..
sudo cp -al current backup_2010-12-04.1

For an extended version see my system backup script.

rsync.txt · Last modified: 2013-12-14 15:02 CET by dominik