Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 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. MYSQL_PASSWORD=
  30.  
  31. ########################### END CONFIGURATION. EDIT BELOW AT YOUR OWN RISK ###########################
  32. INDEX=0
  33.  
  34. for database in ${DATABASES[@]}
  35. do
  36. FILENAME=$BACKUPPATH/$database\_`date '+%m-%d-%Y_%I-%p'`.sql.gz
  37. echo "==================================================================="
  38. echo "Backing up $database Database"
  39. sh -c "mysqldump --extended-insert -Q --opt -h $MYSQL_HOSTNAME -u$MYSQL_USERNAME -p$MYSQL_PASSWORD --databases $database | gzip > $FILENAME" 2>/dev/null
  40. echo "Uploading Archive to Amazon S3"
  41. sh -c "aws s3 cp $FILENAME s3://$S3BUCKET/${DIRECTORIES[$index]}/" > /dev/null
  42. echo "Cleaning Up..."
  43. rm -f $FILENAME
  44.  
  45. index=`expr $index + 1`
  46. done
  47.  
  48. echo "==================================================================="
  49. echo "
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement