Last active
December 13, 2021 22:02
-
-
Save chill117/6243212 to your computer and use it in GitHub Desktop.
Revisions
-
chill117 revised this gist
Jul 6, 2014 . 1 changed file with 13 additions and 20 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,47 +1,40 @@ #!/bin/bash # # Use this script to perform backups of one or more MySQL databases. # # 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. # # Example: # databases=( '__DATABASE_1__' '__DATABASE_2__' ) databases=() # The host name of the MySQL database server; usually 'localhost' db_host="localhost" # The port number of the MySQL database server; usually '3306' db_port="3306" # The MySQL user to use when performing the database backup. db_user="backups" # The password for the above MySQL user. db_pass="" # Directory to which backup files will be written. Should end with slash ("/"). backups_dir="/home/backups/db/" backups_user="backups" # Date/time included in the file names of the database backup files. datetime=$(date +'%Y-%m-%dT%H:%M:%S') for db_name in ${databases[@]}; do # Create database backup and compress using gzip. mysqldump -u $db_user -h $db_host -P $db_port --password=$db_pass $db_name | gzip -9 > $backups_dir$db_name--$datetime.sql.gz done # Set appropriate file permissions/owner. chown $backups_user:$backups_user $backups_dir*--$datetime.sql.gz chmod 0400 $backups_dir*--$datetime.sql.gz -
Charles Hill renamed this gist
Aug 15, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Charles Hill renamed this gist
Aug 15, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Charles Hill created this gist
Aug 15, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ #!/bin/bash # # Use this script to perform backups on one or more MySQL databases. # # 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. # # Example: # databases=( '__DATABASE_1__' '__DATABASE_2__' ) databases=( ) # The host name of the MySQL database server; usually 'localhost' db_host="localhost" # The MySQL user to use when performing the database backup. db_user="" # The password for the above MySQL user. db_pass="" # Host name of the remote server to which the database backup files will be uploaded. # To skip the upload step, leave this blank. remote_host="" # The user that will be used when connecting to the remote server. # # Note: # You will need to set up Passwordless SSH with the remote server. remote_user="" # Date/time included in the file names of the database backup files. datetime=$(date +'%Y-%m-%dT%H:%M:%S') for db_name in ${databases[@]}; do # Create database backup and compress using gzip. mysqldump -u $db_user -h $db_host --password=$db_pass $db_name | gzip -9 > /home/backups/db/$db_name--$datetime.sql.gz done # Set strictest possible file permissions. chown root:root /home/backups/db/*--$datetime.sql.gz chmod 000 /home/backups/db/*--$datetime.sql.gz if [ "$remote_host" != '' ]; then # Use secure copy to upload backup files to remote server. scp /home/backups/db/*--$datetime.sql.gz $remote_user@$remote_host:/home/backups/db/ fi