Guest User

Untitled

a guest
Nov 25th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. #!/bin/sh
  2. #----------------------------------------------------------------
  3. # Daily Backup Routine - Backup and Sync to Dropbox
  4. # This script creates a backup using today's date, then deleted
  5. # any backups made 3 days ago. If run every day it will ensure
  6. # you have a week's worth of backups of your MySQL databases and
  7. # zPanel web directories.
  8. #
  9. # Uses whatever Dropbox account is running on the server.
  10. #
  11. # Written by Richard Ferreira for the backup of zPanel websites.
  12. # Contact me - richard[at]beetle001.com
  13. #----------------------------------------------------------------
  14. #
  15. # Before we get started, we should set some parameters. We'll need these for later.
  16. # The webserver's datafiles:
  17. WEBDIR="/var/zpanel/hostdata/"
  18. # Where do we want the backup to go? (SET THIS - IT'S A TEMP FOLDER)
  19. BACKUP="/root/backup-temp"
  20. # Where is our dropbox folder? (SET THIS TO YOUR ABSOLUTE BACKUP PATH)
  21. DROPBOX="/root/Dropbox/Backups
  22. # What do we want our date to look like?
  23. NOW=$(date +"%d-%m-%Y")
  24. # We need to know the date 3 days ago to purge any backups that were made 3 days ago.
  25. # This ensures we don't keep unnecessarily old backups.
  26. # It doesn't matter if it skips one every now and then - we'll just have to check manually from time to time.
  27. # If you want to keep more days backups, change the "3 days ago" to "x days ago"
  28. DAYSAGO=$(date --date="3 days ago" +"%d-%m-%Y")
  29. # What should our file backup look like?
  30. WEBFILE="webdirs-full-$NOW.tar.gz"
  31. # Our MySQL Login information and some paths (we'll use 'which' to make sure we get them):
  32. SQLUSER="root"
  33. # Don't forget to change the root password here!
  34. SQLPASS="xxxxxxxxxxxx"
  35. SQLHOST="localhost"
  36. MYSQL="$(db-name)"
  37. MYSQLDUMP="$(db-name)"
  38. GZIP="$(.gz)"
  39. #
  40. # Let's just, for sanity's sake, make sure our temp backup folder exists.
  41. mkdir $BACKUP
  42. # DON'T EDIT ANYTHING BELOW THIS LINE
  43. #----------------------------------------------------------------
  44. # Now let's start!
  45. # Let's get the databases that we want to backup.
  46. DBS="$($MYSQL -u $SQLUSER -h $SQLHOST -p$SQLPASS -Bse 'show databases')"
  47. # Now let's dump them to .sql files and put them in our backup directory.
  48. for db in $DBS
  49. do
  50. FILE=$BACKUP/mysql-$db.$NOW.gz
  51. $MYSQLDUMP -u $SQLUSER -h $SQLHOST -p$SQLPASS $db | $GZIP -9 > $FILE
  52. done
  53. #
  54. # Let's shove the whole webserver directory into a tarball and throw that in with the sql files:
  55. tar -zcvf /root/backup/$WEBFILE $WEBDIR
  56. # That's all done - we should put the backups on Copy by putting them into our Copy folder.
  57. # First let's make a folder for today.
  58. mkdir $DROPBOX/$NOW
  59. # Copy our backups into it.
  60. cp -R $BACKUP/* $DROPBOX/Asterix/$NOW
  61. # We can delete the backup we made 3 days ago from Copy now.
  62. rm -rf $DROPBOX/$DAYSAGO
  63. # And clear out the temporary director for next time.
  64. rm $BACKUP/*
  65. # Job well done!
  66. # Have a beer and relax!
  67.  
  68. DROPBOX="/root/Dropbox/Backups
  69.  
  70. MYSQL="/usr/bin/mysql"
  71. MYSQLDUMP="/usr/bin/mysqldump"
  72. GZIP="/bin/gzip"
  73.  
  74. $ which mysql
  75. /usr/bin/msql
  76. $ which gzip
  77. /bin/gzip
Add Comment
Please, Sign In to add comment