a pastebin project

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

  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

advertising

Create a Paste

Please enter your new post below (or upload a file instead):





Please note that information posted here will not expire by default. If you 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.

worth-right
fantasy-obligation