Guest User

Untitled

a guest
Oct 28th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # DOT Indonesia - dot.co.id
  4. # Daily backup Script
  5. # Samsul Ma'arif <mail@samsul.web.id>
  6. #
  7.  
  8. #set -x
  9.  
  10. TODAY=`date +"%Y-%m-%d"`
  11. YESTERDAY=`date -d "1 day ago" +"%Y-%m-%d"`
  12.  
  13. # How many days to keep? 7 is prefered
  14. OLDBACKUP=`date -d "7 days ago" +"%Y-%m-%d"`
  15.  
  16.  
  17. USERDIR="/home/situs/backup"
  18. # base directory to be backup
  19. SRCDIR="/home/situs/"
  20. DSTDIR="$USERDIR/$TODAY"
  21.  
  22. EXCLUDES="$USERDIR/exclude_list.txt"
  23. LOG="$USERDIR/BACKUP-$TODAY-success.log"
  24.  
  25. # DB access
  26. DBNAME="moodledb"
  27. DBUSER="moodleuser"
  28. DBPASSWORD="TWFsYW5nUmF5YUpheWEK"
  29. DBHOST="127.0.0.1"
  30.  
  31.  
  32. RSYNC="/usr/bin/rsync"
  33.  
  34.  
  35. # create destination directory if not exist
  36. if [ ! -d $DSTDIR ] ; then
  37. echo "Creating $DSTDIR" >> $LOG
  38. mkdir -p $DSTDIR
  39. fi
  40.  
  41. echo "backup to $DSTDIR/backup-daily.tar.gz" >> $LOG
  42. cd $SRCDIR
  43. tar -czf $DSTDIR/backup-daily.tgz public
  44.  
  45. # Backup Database
  46. echo "backup $DBNAME to $DSTDIR/$TODAY-$DBNAME.sql.gz" >> $LOG
  47. mysqldump --user=$DBUSER --password=$DBPASSWORD --lock-tables --databases $DBNAME | gzip -c > $DSTDIR/$TODAY-$DBNAME.sql.gz
  48.  
  49. # Delete older than 7 days
  50. if [ -d $USERDIR/$OLDBACKUP ]; then
  51. echo "deleting old backup $USERDIR/$OLDBACKUP" >> $LOG
  52. rm -rf $USERDIR/$OLDBACKUP
  53. else
  54. echo "Nothing to delete!" >> $LOG
  55. fi
  56.  
  57. echo "" >> $LOG
  58.  
  59. # Logging
  60. echo "\nBACKUP success $TODAY" >> $LOG
  61.  
  62. exit 0
Add Comment
Please, Sign In to add comment