码迷,mamicode.com
首页 > 数据库 > 详细

[转载]Back up all of your mysql databases nightly

时间:2016-08-27 00:17:40      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:

原文地址: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 has MySQL’s root password in it, make sure that you chmod 700 to it so no one else can read it.

#!/bin/bash

DB_BACKUP="/backups/mysql_backup/`date +%Y-%m-%d`"
DB_USER="root"
DB_PASSWD="secretttt"
HN=`hostname | awk -F. {print $1}`

# Create the backup directory
mkdir -p $DB_BACKUP

# Remove backups older than 10 days
find /backups/mysql_backup/ -maxdepth 1 -type d -mtime +10 -exec rm -rf {} \;

# Backup each database on the system
for db in $(mysql --user=$DB_USER --password=$DB_PASSWD -e show databases -s --skip-column-names|grep -viE (staging|performance_schema|information_schema));
do mysqldump --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 way, we’re skipping tables ‘performance_schema’ and ‘information_schema’…
Then just call it from cron by creating a root cron entry:

30 3 * * * /usr/local/bin/mysql_backup.sh

(完)

[转载]Back up all of your mysql databases nightly

标签:

原文地址:http://www.cnblogs.com/zhangbao/p/5811951.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!