Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2739955
  • 博文数量: 423
  • 博客积分: 7770
  • 博客等级: 少将
  • 技术积分: 4766
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-09 11:58
个人简介

Oracle/DB2/Postgresql/Mysql/Hadoop/Greenplum/Postgres-xl/Mongodb

文章分类

全部博文(423)

文章存档

2019年(3)

2018年(6)

2017年(27)

2016年(23)

2015年(30)

2014年(16)

2013年(31)

2012年(73)

2011年(45)

2010年(14)

2009年(30)

2008年(30)

2007年(63)

2006年(32)

分类: Mysql/postgreSQL

2014-06-07 19:57:55

[root@rhel6 sbin]# more mysqlbackup.sh
#If any of your tables run on InnoDB engine
#directory to store backups in
DST=/backup/dbback
# A regex, passed to egrep -v, for which databases to ignore
IGNREG='^snort$'
# The MySQL username and password
DBUSER=root
DBPASS=62201042
# Any backups older than this will be deleted first
KEEPDAYS=7

DATE=$(date  +%Y-%m-%d)

cd /usr/local/mysql

find ${DST} -type f -mtime +${KEEPDAYS} -exec rm -f {} \;
rmdir $DST/* 2>/dev/null

mkdir -p ${DST}/${DATE}
for db in $(echo 'show databases;' | /usr/local/mysql/bin/mysql -s -u ${DBUSER} -p${DBPASS} | egrep -v ${IGNREG}) ; do
        echo -n "Backing up ${db}... "
        /usr/local/mysql/bin/mysqldump --opt  --single-transaction -u ${DBUSER} -p${DBPASS} $db | gzip -c > ${DST}/${DATE}/${db}.sql.gz
        echo "Done."
done

exit 0

[root@rhel6 sbin]# cd /backup/dbback/2014-06-07/
[root@rhel6 2014-06-07]# ll
总用量 176
-rw-r--r-- 1 root root    353 6月   7 11:38 information_schema.sql.gz
-rw-r--r-- 1 root root 161767 6月   7 11:38 mysql.sql.gz
-rw-r--r-- 1 root root    354 6月   7 11:38 performance_schema.sql.gz
-rw-r--r-- 1 root root    649 6月   7 11:38 tankdb.sql.gz
-rw-r--r-- 1 root root    432 6月   7 11:38 test.sql.gz
[root@rhel6 2014-06-07]#
阅读(2002) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~