Paste Description for Incremental rsync backup script
This script allows multiple sources and one target. SSH support is optional. In the $TARGET folder you will get YYMMDD folders. The contents will always be hardlinked to the folder of the previous day (if they are the same). This saves alot of spaces. The EXPIREDAYS variable allows you to set the amount of days you want to keep in your backup-folder.
Incremental rsync backup script
- #!/bin/bash
- # Simple backup with rsync
- # SOURCES and TARGET must end with slash
- SOURCES="/root/ /etc/ /home/ /boot/"
- TARGET="/usr/local/backup/"
- LOGFILE="/root/backup.log"
- EXPIREDAYS=100
- RSYNC="--delete"
- #SSHUSER="user"
- #SSHHOST="hostname"
- ### do not edit ###
- `/bin/date > $LOGFILE`
- if [ -e $TARGET ]; then
- LASTBACKUP=`/bin/ls -d $TARGET[[:digit:]]* 2>> $LOGFILE | /usr/bin/sort -r | /usr/bin/head -1 `
- fi
- TODAY=$(/bin/date +%y%m%d)
- EXPIRED=`/usr/bin/find $TARGET[[:digit:]]* -maxdepth 0 -ctime +$EXPIREDAYS 2>> $LOGFILE`
- for EX in `/bin/echo $EXPIRED`
- do
- /bin/echo "rm -rf $EX " >> $LOGFILE
- `/bin/rm -rf $EX`
- done
- for SOURCE in `/bin/echo $SOURCES`
- do
- if [ "$LASTBACKUP" ]; then
- INC="--link-dest=$LASTBACKUP$SOURCE"
- fi
- if [ "$SSHUSER" ] && [ "$SSHHOST" ]; then
- SOURCEDIR="$SSHUSER@$SSHHOST:$SOURCE"
- else
- SOURCEDIR=$SOURCE
- fi
- `/bin/mkdir -p $TARGET$TODAY$SOURCE` >> $LOGFILE
- echo "/usr/bin/rsync -av $RSYNC $INC $SOURCEDIR $TARGET$TODAY$SOURCE" >> $LOGFILE
- `/usr/bin/rsync -av $RSYNC $INC $SOURCEDIR $TARGET$TODAY$SOURCE >> $LOGFILE 2>> $LOGFILE`
- done