Bash Script to backup all MySQL databases
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.
Instantly share code, notes, and snippets.
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
-
35
Problem Sometimes things that seem complicated are much easier then you think and this is the power of using T-SQL to take care of repetitive tasks. One of these tasks may be the need to backup all databases o...
-
12
Bash script to perform super-fast file transfer using netcat and tar Aug 5, 2013 Updated 06-Aug-2013 : Script updated to transfer multiple files in single command [
-
10
Bash scripts. Almost anyone needs to write one sooner or later. Almost no one says “yeah, I love writing them”. And that’s why almost everyone is putting low attention while writing them. I won’t try to make you a Bash expert (since...
-
11
Create Script from Bash History Submitted by NanoDano on Wed, 11/21/2012 - 11:04...
-
17
Send mail with a BASH Shell Script Posted: 2007-06-10 - Last updated: 2019-06-05 Tagged
-
8
Bash Script 的好習慣這篇給了一份 bash script 用的 tempalte,但更重要的反而是裡面提到的 best practice:「Minimal safe Bash script template」。首先是不...
-
12
How to write a backup script with Bash Rob Marti Feb 26, 2021 8 Minute Read Linux System...
-
3
Backup Databases on Kubernetes With VolumeSnapshots Back to the Blog
-
4
Introduction: In this blog, we will learn in detail on how to back up SAP HANA databases with HSR enabled (for High Availability purpose) that are running on Azure virtual machines (VMs) to an Azure Backup Recovery Services vault by using...
-
4
Bash scripts to backup all databases in a MySQL server with the option to exclude some databases. · GitHub ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK