Guest User

Untitled

a guest
Aug 9th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. jaquilina@EagleEyeT:~$ cat mysqlBackup.sh
  2. #!/bin/bash
  3.  
  4. #this script just gzips atm
  5. #tar what is gzipped
  6. #removed gzipped files once tar-ed
  7.  
  8. MyUSER="jonathan" # USERNAME
  9. MyPASS="" # PASSWORD
  10. MyHOST="localhost" # Hostname
  11.  
  12. # Linux bin paths, change this if it can not be autodetected via which command
  13. MYSQL="$(which mysql)"
  14. MYSQLDUMP="$(which mysqldump)"
  15. CHOWN="$(which chown)"
  16. CHMOD="$(which chmod)"
  17. GZIP="$(which gzip)"
  18.  
  19. # Backup Dest directory, change this if you have someother location
  20. DEST="/mnt/backup"
  21.  
  22. # Main directory where backup will be stored
  23. MBD="$DEST/mysql"
  24.  
  25. # Get hostname
  26. HOST="$(hostname)"
  27.  
  28. # Get data in dd-mm-yyyy format
  29. NOW="$(date +"%d-%m-%Y")"
  30.  
  31. # File to store current backup file
  32. FILE=""
  33. # Store list of databases
  34. DBS=""
  35.  
  36. # DO NOT BACKUP these databases
  37. IGGY="information_schema"
  38.  
  39. [ ! -d $MBD ] && mkdir -p $MBD || :
  40.  
  41. # Only root can access it!
  42. $CHOWN 0.0 -R $DEST
  43. $CHMOD 0600 $DEST
  44.  
  45. # Get all database list first
  46. DBS="$($MYSQL -u $MyUSER -h $MyHOST -p$MyPASS -Bse 'show databases')"
  47.  
  48. for db in $DBS
  49. do
  50. skipdb=-1
  51. if [ "$IGGY" != "" ];
  52. then
  53. for i in $IGGY
  54. do
  55. [ "$db" == "$i" ] && skipdb=1 || :
  56. done
  57. fi
  58.  
  59. if [ "$skipdb" == "-1" ] ; then
  60. FILE="$MBD/$db.$HOST.$NOW.tar"
  61. # do all inone job in pipe,
  62. # connect to mysql using mysqldump for select mysql database
  63. # and pipe it out to gz file in backup dir :)
  64. $MYSQLDUMP -u $MyUSER -h $MyHOST -p$MyPASS $db | $GZIP -9 > $FILE
  65. fi
  66. done
Advertisement
Add Comment
Please, Sign In to add comment