Reproduced Back up all of your MySQL databases nightly

Source: Internet
Author: User

Original address: http://www.linuxbrigade.com/back-up-all-of-your-mysql-databases-nightly/

Put the following into something like/usr/local/bin/mysql_backup.sh and since it have MySQL ' s root password in it, make Su Re that you chmod for it so no one else can read it.

#!/bin/Bashdb_backup="/backups/mysql_backup/' Date +%y-%m-%d '"Db_user="Root"db_passwd="SECRETTTT"HN=`hostname|awk-F.'{print $}'' # Create the backup directorymkdir-p $DB _backup# Remove backups older thanTen DaysFind/backups/mysql_backup/-maxdepth1-type D-mtime +Ten-execRM-RF {} \;# Backup each database on the system forDbinch$ (MySQL--user= $DB _user--password= $DB _passwd-e'Show Databases'-S--skip-column-names|grep-vie'(Staging|performance_schema|information_schema)'); DoMysqldump--user= $DB _user--password= $DB _passwd--events--opt--single-transaction $db |gzip>"$DB _backup/mysqldump-$HN-$db-$ (date +%y-%m-%d). GZ"; Done

By the, we ' re skipping tables ' performance_schema ' and ' information_schema ' ...
Then just call it from Cron by creating a root cron entry:

 - 3 * * */usr/local/bin/mysql_backup. SH

Finish

Reproduced Back up all of your MySQL databases nightly

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.