Guest User

Untitled

a guest
Nov 30th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #
  4. # Use this script to perform a backup of a MySQL database.
  5. #
  6.  
  7. # The database name
  8. db_name="database1"
  9.  
  10. # The host name of the MySQL database server; usually 'localhost'
  11. db_host="localhost"
  12.  
  13. # The port number of the MySQL database server; usually '3306'
  14. db_port="3306"
  15.  
  16. # The MySQL user to use when performing the database backup.
  17. db_user=""
  18.  
  19. # The password for the above MySQL user.
  20. db_pass=""
  21.  
  22. # Directory to which backup files will be written. Should end with slash ("/").
  23. backups_dir="/home/deploy/Backup/"
  24.  
  25. # The system username
  26. backups_user="deploy"
  27.  
  28. # Date/time included in the file names of the database backup files.
  29. datetime=$(date +'%Y-%m-%dT%H:%M:%S')
  30.  
  31. # Create database backup and compress using gzip.
  32. mysqldump -u $db_user -h $db_host -P $db_port --password=$db_pass $db_name | gzip -9 > $backups_dir$db_name--$datetime.sql.gz
  33.  
  34. # Set appropriate file permissions/owner.
  35. chown $backups_user:$backups_user $backups_dir*--$datetime.sql.gz
  36. chmod 0400 $backups_dir*--$datetime.sql.gz
Add Comment
Please, Sign In to add comment