Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

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 

  1. #!/bin/bash
  2. # Simple backup with rsync
  3.  
  4. # SOURCES and TARGET must end with slash
  5.  
  6. SOURCES="/root/ /etc/ /home/ /boot/"
  7. TARGET="/usr/local/backup/"
  8. LOGFILE="/root/backup.log"
  9. EXPIREDAYS=100
  10. RSYNC="--delete"
  11.  
  12. #SSHUSER="user"
  13. #SSHHOST="hostname"
  14.  
  15. ### do not edit ###
  16.  
  17. `/bin/date > $LOGFILE`
  18.  
  19. if [ -e $TARGET ]; then
  20.  LASTBACKUP=`/bin/ls -d $TARGET[[:digit:]]* 2>> $LOGFILE | /usr/bin/sort -r | /usr/bin/head -1  `
  21. fi
  22.  
  23. TODAY=$(/bin/date +%y%m%d)
  24.  
  25. EXPIRED=`/usr/bin/find $TARGET[[:digit:]]* -maxdepth 0 -ctime +$EXPIREDAYS  2>> $LOGFILE`
  26. for EX in `/bin/echo $EXPIRED`
  27. do
  28.   /bin/echo  "rm -rf $EX " >> $LOGFILE
  29.   `/bin/rm -rf $EX`
  30. done
  31.  
  32. for SOURCE in `/bin/echo $SOURCES`
  33. do
  34.   if [ "$LASTBACKUP" ]; then
  35.     INC="--link-dest=$LASTBACKUP$SOURCE"
  36.   fi
  37.   if [ "$SSHUSER" ] && [ "$SSHHOST" ]; then
  38.     SOURCEDIR="$SSHUSER@$SSHHOST:$SOURCE"
  39.   else
  40.     SOURCEDIR=$SOURCE
  41.   fi
  42.   `/bin/mkdir -p $TARGET$TODAY$SOURCE` >> $LOGFILE
  43.   echo "/usr/bin/rsync -av $RSYNC $INC $SOURCEDIR $TARGET$TODAY$SOURCE"  >> $LOGFILE
  44.   `/usr/bin/rsync -av $RSYNC $INC $SOURCEDIR $TARGET$TODAY$SOURCE >> $LOGFILE 2>> $LOGFILE`
  45. done

Paste Details

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.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



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.

worth-right
fantasy-obligation