Advertisement
Guest User

Untitled

a guest
Oct 13th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Suffix added at the end of the filename
  4. NOW=$(date +"%d%m%Y")
  5.  
  6. # Destination folder of all the dumps
  7. DEST="backups"
  8.  
  9. # Set mysql login info
  10. MUSER="root"
  11. MPASS=""
  12. MHOST="127.0.0.1"
  13.  
  14. # Guess binary names
  15. MYSQL="$(which mysql)"
  16. MYSQLDUMP="$(which mysqldump)"
  17. GZIP="$(which gzip)"
  18.  
  19. [ ! -d "${DEST}" ] && mkdir -p "${DEST}"
  20. # Get all db names
  21. DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
  22. for db in $DBS
  23. do
  24. FILE=${DEST}/${db}_${NOW}.gz
  25. $MYSQLDUMP --single-transaction -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE
  26. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement