Advertisement
Guest User

Mysql Backup

a guest
Feb 5th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.32 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=('sasty')
  12.  
  13. # The host name of the MySQL database server; usually 'localhost'
  14. db_host="127.0.0.1"
  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="root"
  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="C:/Users/Kapil/backup/"
  27.  
  28. backups_user=""
  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.         C:/xampp/mysql/bin/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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement