2

Bash Script to backup all MySQL databases

 8 months ago
source link: https://gist.github.com/tleish/1c6e788c84f59200446b
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Instantly share code, notes, and snippets.

Last active January 4, 2024 12:21
Bash Script to backup all MySQL databases

Author

Daily Cron:

Backup Daily at 9:15 am using CRON

# min  hr mday month wday command
 15   9  *    *     *    /Users/[your user name]/scripts/auto_mysql_backup.sh

Restore from Backup

$ gunzip < [backupfile.sql.gz] | mysql -u [uname] -p[pass] [dbname]
$ gunzip [backupfile.sql.gz]
$ mysql -u [uname] -p[pass] [dbname] < [backupfile.sql]

Hello,

I do not program very well. How do I change this script to include in my backups the --routines option. Why in this way I make backups including all data, but my functions / S.Procedures are not included.

Thanks for all support!

Nice job!

Maybe you can implement dropbox_uploader script...

function backup_database(){
backup_file="$BACKUP_DIR/$TIMESTAMP.$database.sql.gz"
output+="$database => $backup_file\n"
echo_status "...backing up $count of $total databases: $database"
(mysqldump(mysql_login) $database | gzip -9 > $backup_file)
#upload to dropbox...
sh /home/user/dropbox_uploader.sh -f /home/user/.dropbox_uploader upload $backup_file /
}

The "dropbox_uploader" script is here: https://github.com/andreafabrizi/Dropbox-Uploader

very good gist, thanks

Excellent script 💯

Thanks

How would I modify this so I could specify the host and port?

@uSlackr Try adding -h YOURHOSTNAME -P YOURPORT on line 75.
Something like: $(mysqldump $(mysql_login) -h YOURHOSTNAME -P YOURPORT $database | gzip -9 > $backup_file)

Thanks. I'd figured this out but forgot to post back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK