Guest User

Untitled

a guest
Apr 16th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #
  4. # Use this script to perform backups of one or more MySQL databases.
  5. #
  6.  
  7. # Databases that you wish to be backed up by this script. You can have any number of databases specified; encapsilate each database name in single quotes and separate each database name by a space.
  8. #
  9. # Example:
  10. # databases=( '__DATABASE_1__' '__DATABASE_2__' )
  11. databases=()
  12.  
  13. # The host name of the MySQL database server; usually 'localhost'
  14. db_host="localhost"
  15.  
  16. # The port number of the MySQL database server; usually '3306'
  17. db_port="3306"
  18.  
  19. # The MySQL user to use when performing the database backup.
  20. db_user="backups"
  21.  
  22. # The password for the above MySQL user.
  23. db_pass=""
  24.  
  25. # Directory to which backup files will be written. Should end with slash ("/").
  26. backups_dir="/home/backups/db/"
  27.  
  28. backups_user="backups"
  29.  
  30. # Date/time included in the file names of the database backup files.
  31. datetime=$(date +'%Y-%m-%dT%H:%M:%S')
  32.  
  33. for db_name in ${databases[@]}; do
  34. # Create database backup and compress using gzip.
  35. mysqldump -u $db_user -h $db_host -P $db_port --password=$db_pass $db_name | gzip -9 > $backups_dir$db_name--$datetime.sql.gz
  36. done
  37.  
  38. # Set appropriate file permissions/owner.
  39. chown $backups_user:$backups_user $backups_dir*--$datetime.sql.gz
  40. chmod 0400 $backups_dir*--$datetime.sql.gz
Add Comment
Please, Sign In to add comment