SHARE
TWEET

Untitled

a guest Jul 21st, 2017 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. USER="<mysql username>"
  4. PASSWORD="<mysql pass>"
  5. OUTPUTDIR="<output for files>"
  6. MYSQLDUMP="/usr/bin/mysqldump"
  7. MYSQL="/usr/bin/mysql"
  8. RSYNC="/usr/bin/rsync"
  9.  
  10. # clean up any old backups - save space
  11. rm $OUTPUTDIR/* > /dev/null 2>&1
  12.  
  13. # get a list of databases
  14. databases=`$MYSQL --user=$USER --password=$PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
  15.  
  16. # dump each database in turn
  17. for db in $databases; do
  18.     $MYSQLDUMP --force --opt --user=$USER --password=$PASSWORD --databases $db > "$OUTPUTDIR/$db.bak"
  19.     gzip $OUTPUTDIR/$db.bak
  20. done
  21.  
  22. # make a file containing backup time
  23.  
  24. date > $OUTPUTDIR/date
  25.  
  26. rsync -e 'ssh -p 22' -az $OUTPUTDIR/* <user@ip>:/backup/mysql
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top