Guest User

Untitled

a guest
Aug 12th, 2016
111
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /bin/bash
  2.  
  3. TIMESTAMP=$(date +"%F")
  4. BACKUP_DIR="/home/user/dumps/$TIMESTAMP"
  5. MYSQL_USER="dumper"
  6. MYSQL=/usr/bin/mysql
  7. MYSQL_PASSWORD="password"
  8. MYSQLDUMP=/usr/bin/mysqldump
  9.  
  10. export AZURE_STORAGE_ACCOUNT=
  11. export AZURE_STORAGE_ACCESS_KEY=
  12. export AZURE_CONTAINER=
  13. export AZURE_BLOB_NAME=$(date +"%F").sql.gz
  14.  
  15. echo 'start separate DB dumps'
  16. mkdir -p "$BACKUP_DIR/mysql"
  17.  
  18. databases=`$MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema)"`
  19.  
  20. for db in $databases; do
  21. $MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db | gzip > "$BACKUP_DIR/mysql/$db.gz"
  22. done
  23.  
  24. echo 'start --all-databases dump'
  25. /usr/bin/mysqldump --all-databases > "$BACKUP_DIR/all-databases.sql"
  26. /bin/gzip "$BACKUP_DIR/all-databases.sql"
  27.  
  28. echo 'zip all the dumps'
  29. /usr/bin/zip -r "$BACKUP_DIR.zip" $BACKUP_DIR
  30.  
  31. echo 'upload to azure storage'
  32. /usr/bin/nodejs /usr/local/bin/azure storage blob upload "$BACKUP_DIR.zip" $AZURE_CONTAINER $AZURE_BLOB_NAME
RAW Paste Data