Advertisement
Guest User

Untitled

a guest
Apr 28th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #!/bin/bash
  2. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  3.  
  4. # Temporary Path where the archive will be created and stored before uploading to S3
  5. # Example: BACKUPPATH=/mnt
  6. BACKUPPATH=/
  7.  
  8. # Amazon S3 Bucket name
  9. # Example: S3BUCKET=production-database-backups
  10. S3BUCKET=
  11.  
  12. # Individual Database names separated by spaces.
  13. # Prefix underscore(_) with a backslash(\) in directory name.
  14. # Example: DATABASES=(db1 db2 db3 db\_4)
  15. DATABASES=()
  16.  
  17. # Individual Amazon S3 directories in the bucket separated by spaces.
  18. # Prefix underscore(_) with a backslash(\) in directory name.
  19. # Example: DIRECTORIES=(db1 db2 db3 db\_4)
  20. DIRECTORIES=()
  21.  
  22. # MySQL Hostname or IP Address
  23. MYSQL_HOSTNAME=127.0.0.1
  24.  
  25. # MySQL Username that has access to all the above databases
  26. MYSQL_USERNAME=root
  27.  
  28. # MySQL Password for the above user
  29. # if you use $ in password
  30. MYSQL_PASSWORD=''
  31.  
  32. ########################### END CONFIGURATION. EDIT BELOW AT YOUR OWN RISK ###########################
  33. INDEX=0
  34.  
  35. for database in ${DATABASES[@]}
  36. do
  37. FILENAME=$BACKUPPATH/$database\_`date '+%m-%d-%Y_%I-%p'`.sql.gz
  38. echo "==================================================================="
  39. echo "Backing up $database Database"
  40. sh -c `mysqldump --extended-insert -Q --opt -h $MYSQL_HOSTNAME -u$MYSQL_USERNAME -p$MYSQL_PASSWORD --databases $database | gzip > $FILENAME` 2>/dev/null
  41. echo "Uploading Archive to Amazon S3"
  42. sh -c "aws s3 cp $FILENAME s3://$S3BUCKET/${DIRECTORIES[$index]}/" > /dev/null
  43. echo "Cleaning Up..."
  44. rm -f $FILENAME
  45.  
  46. index=`expr $index + 1`
  47. done
  48.  
  49. echo "==================================================================="
  50. echo " All Databases Backup Complete"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement