Bash Backup Script


/ Published in: Bash
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #!/bin/sh
  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.  
  7. #Change the 5 variables below to fit your computer/backup
  8.  
  9. COMPUTER=deep # name of this computer
  10. DIRECTORIES="/home" # directoris to backup
  11. BACKUPDIR=/backups # where to store the backups
  12. TIMEDIR=/backups/last-full # where to store time of full backup
  13. TAR=/bin/tar # name and locaction of tar
  14.  
  15. #You should not have to change anything below here
  16.  
  17. PATH=/usr/local/bin:/usr/bin:/bin
  18. DOW=`date +%a` # Day of the week e.g. Mon
  19. DOM=`date +%d` # Date of the Month e.g. 27
  20. DM=`date +%d%b` # Date and Month e.g. 27Sep
  21.  
  22. # On the 1st of the month a permanet full backup is made
  23. # Every Sunday a full backup is made - overwriting last Sundays backup
  24. # The rest of the time an incremental backup is made. Each incremental
  25. # backup overwrites last weeks incremental backup of the same name.
  26. #
  27. # if NEWER = "", then tar backs up all files in the directories
  28. # otherwise it backs up files newer than the NEWER date. NEWER
  29. # gets it date from the file written every Sunday.
  30.  
  31.  
  32. # Monthly full backup
  33. if [ $DOM = "01" ]; then
  34. NEWER=""
  35. $TAR $NEWER -cf $BACKUPDIR/$COMPUTER-$DM.tar $DIRECTORIES
  36. fi
  37.  
  38. # Weekly full backup
  39. if [ $DOW = "Sun" ]; then
  40. NEWER=""
  41. NOW=`date +%d-%b`
  42.  
  43. # Update full backup date
  44. echo $NOW > $TIMEDIR/$COMPUTER-full-date
  45. $TAR $NEWER -cf $BACKUPDIR/$COMPUTER-$DOW.tar $DIRECTORIES
  46.  
  47. # Make incremental backup - overwrite last weeks
  48. else
  49.  
  50. # Get date of last full backup
  51. NEWER="--newer `cat $TIMEDIR/$COMPUTER-full-date`"
  52. $TAR $NEWER -cf $BACKUPDIR/$COMPUTER-$DOW.tar $DIRECTORIES
  53. fi

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.