Advertisement
Guest User

Untitled

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