hpsaturn

Backup Incremental (TAR)

Oct 9th, 2012
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.49 KB | None | 0 0
  1. #!/bin/bash
  2. # full and incremental backup script
  3. # created 07 February 2000
  4. # Based on a script by Daniel O'Callaghan <[email protected]>
  5. # and modified by Gerhard Mourani <[email protected]>
  6. # and modified by Antonio Vanegas <[email protected]> @hpsaturn
  7.  
  8. #Change the 5 variables below to fit your computer/backup
  9.  
  10. COMPUTER=home                           # name of this computer
  11. ROOT=/mnt/samba/bkp
  12. DIRECTORIES=/home/xxx                   # directoris to backup
  13. BACKUPDIR=$ROOT/$COMPUTER               # where to store the backups
  14. TIMEDIR=$ROOT/$COMPUTER/last-full       # where to store time of full backup
  15. TAR=/bin/tar                            # name and locaction of tar
  16. IGNORE=$ROOT/$COMPUTER/ignorefiles      # list ignore
  17.  
  18. #You should not have to change anything below here
  19.  
  20. PATH=/usr/local/bin:/usr/bin:/bin
  21. DOW=`date +%a`                      # Day of the week e.g. Mon
  22. DOM=`date +%d`                      # Date of the Month e.g. 27
  23. DM=`date +%d%b`                         # Date and Month e.g. 27Sep
  24. DATE=`date +%Y%m%d`                     # Date format AAAAMMDD
  25.  
  26. # On the 1st of the month a permanet full backup is made
  27. # Every Sunday a full backup is made - overwriting last Sundays backup
  28. # The rest of the time an incremental backup is made. Each incremental
  29. # backup overwrites last weeks incremental backup of the same name.
  30. #
  31. # if NEWER = "", then tar backs up all files in the directories
  32. # otherwise it backs up files newer than the NEWER date. NEWER
  33. # gets it date from the file written every Sunday.
  34.  
  35.  
  36. # Monthly full backup
  37. if [ $DOM = "14" ]; then
  38.         NEWER=""
  39.         $TAR $NEWER -zcf $BACKUPDIR/bkp_$COMPUTER_$DATE.tar.gz --exclude-from=$IGNORE $DIRECTORIES
  40. fi
  41.  
  42. # Weekly full backup
  43. if [ $DOW = "Fri" ]; then
  44.         NEWER=""
  45.         NOW=`date +%d-%b`
  46.  
  47.         # Update full backup date (/tmp for samba)
  48.         echo $NOW > /tmp/$COMPUTER-full-date
  49.         mv /tmp/$COMPUTER-full-date $TIMEDIR/
  50.         # remove file if exist
  51.         FILE=$BACKUPDIR/$COMPUTER-$DOW.tar.gz
  52.         if [ -e $FILE ]; then
  53.           rm $FILE
  54.         fi
  55.         $TAR $NEWER -zcf $FILE --exclude-from=$IGNORE $DIRECTORIES
  56.  
  57. # Make incremental backup - overwrite last weeks
  58. else
  59.         # Get date of last full backup
  60.         NEWER="--newer `cat $TIMEDIR/$COMPUTER-full-date`"
  61.         # remove file if exist
  62.         FILE=$BACKUPDIR/$COMPUTER-$DOW.tar.gz
  63.         if [ -e $FILE ]; then
  64.           rm $FILE
  65.         fi
  66.         $TAR $NEWER -zcf $FILE --exclude-from=$IGNORE $DIRECTORIES
  67. fi
Advertisement
Add Comment
Please, Sign In to add comment