Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

BackupScript

By: choatichwisper on Nov 17th, 2012  |  syntax: Bash  |  size: 0.70 KB  |  views: 340  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/sh
  2. USERNAME=myUsername
  3. DIR_TO_BACKUP=/home/$USERNAME
  4. HOW_MANY=3
  5. BACKUP_LOCATION=/media/2tdrive
  6. DATE=`date +%Y-%m-%d`
  7. FILENAME="$USERNAME_$DATE.tar.gz"
  8.  
  9. OLD_DATE=`date -d "-$HOW_MANY days" "+%Y-%m-%d"`
  10. OLD_FILE="$USERNAME_$OLD_DATE.tar.gz"
  11. BACKUP_FILE=$BACKUP_LOCATION/$FILENAME
  12. OLD_BACKUP_FILE=$BACKUP_LOCATION/$OLD_FILE
  13.  
  14. echo "Creating backup file $BACKUP_FILE"
  15. tar czf $BACKUP_FILE $DIR_TO_BACKUP 2>>error_$DATE.log
  16.  
  17. if [ -f $BACKUP_FILE ]
  18. then
  19.     echo "Backup Done"
  20. else
  21.     echo "Something went wrong"
  22.     `cat error_$DATE.log`
  23. fi
  24.  
  25. if [ -f $OLD_BACKUP_FILE ]
  26.     then
  27.     echo "Removing File that is $HOW_MANY days old"
  28.     rm $OLD_BACKUP_FILE
  29.     echo "Removed $OLD_FILE"
  30. fi