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
- Monday, June 8th, 2009 at 12:27:18pm MDT
- #!/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
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.