Guest User

Untitled

a guest
Dec 11th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Fill this in
  4. DB_USER=""
  5. DB_PASSWORD=""
  6. DB_HOST="localhost"
  7. DB_PORT="3306"
  8.  
  9. S3_BUCKET=""
  10. SECRET_KEY=""
  11.  
  12.  
  13.  
  14. # Basic variables
  15. mysqlpass="$DB_PASSWORD"
  16. mysqluser="$DB_USER"
  17. mysqlhost="$DB_HOST"
  18. mysqlport="$DB_PORT"
  19. bucket="s3://$S3_BUCKET"
  20. secret_key="$SECRET_KEY"
  21.  
  22. # Timestamp (sortable AND readable)
  23. stamp=`date +"%s - %A %d %B %Y @ %H%M"`
  24.  
  25. # List all the databases
  26. databases=`mysql -u $DB_USER -p$mysqlpass -P $DB_PORT -h $DB_HOST -e "SHOW DATABASES;" | tr -d "| " | grep -v "\(Database\|information_schema\|performance_schema\|sys\|mysql\|test\)"`
  27.  
  28. # Feedback
  29. echo -e "Dumping to \e[1;32m$bucket/$stamp/\e[00m"
  30.  
  31. # Loop the databases
  32. for db in $databases; do
  33.  
  34. # Define our filenames
  35. filename="$stamp - $db.sql.gpg"
  36. tmpfile="/tmp/$filename"
  37. object="$bucket/$stamp/$filename"
  38.  
  39. # Feedback
  40. echo -e "Filename: $tmpfile"
  41. echo -e "Destination: $object"
  42. echo -e "\e[1;34m$db\e[00m"
  43.  
  44. # Dump and gpg encrypt
  45. echo -e " creating \e[0;35m$tmpfile\e[00m"
  46. mysqldump -u root -p$mysqlpass --force --opt --databases "$db" | gzip -c > "$tmpfile"
  47.  
  48. # Upload
  49. echo -e " uploading..."
  50. s3cmd put "$tmpfile" "$object"
  51.  
  52. # Delete
  53. rm -f "$tmpfile"
  54.  
  55. done;
  56.  
  57. # Jobs a goodun
  58. echo -e "\e[1;32mJobs a goodun\e[00m"
Add Comment
Please, Sign In to add comment