MySQL Auto Backup shell

Source: Internet
Author: User

#!/bin/bash

#数据库配置信息
#db_user = root
#db_password = Wdmima
#db_host = localhost

#备份目录
Backup_dir =/root/database/

#获取当前时间
Timestr = ' Date +%y%m%d '

#mysql command
#MYSQL = "/usr/local/mysql/bin/mysql"
#MYSQLDUMP = "/usr/local/mysql/bin/mysqldump"

#测试备份目录是否可写不可写则报错
Test! -W $backup _dir && echo "Error: $backup _dir in un-writeable." && exit 0


#测试备份目录中的最新备份文件夹是否存在, if it does not exist, create
Test! -D "/root/database/backup.0" && mkdir "/root/database/backup.0"

Echo $time

#制定要备份的数据库
For DB in www.mesuca.com vip.mesuca.com
Do
/usr/local/mysql/bin/mysqldump-u Root-pwdmima $db > "/root/database/backup.0/$db. ' Date +%y%m%d '. sql '
Done


#检测最旧的备份数据库是否存在, if you delete the
Test-d "/ROOT/DATABASE/BACKUP.7" && rm-rf "/ROOT/DATABASE/BACKUP.7"

#循环修改备份目录编号, record the old and new levels
for int in 6 5 4 3 2 1 0
Do
if (test-d "/root/database/backup. $int")
Then
# nint = ' expr $int + 1 '
#echo "$backup _dir/backup. $int"
#echo "$backup _dir/backup. $next _int"
MV "/root/database/backup. $int" "/root/database/backup. ' Expr $int + 1 '"
Fi
Done

Exit 0

This article is from the "Jinghong" blog, please be sure to keep this source http://haocaige.blog.51cto.com/1319521/1611507

MySQL Auto Backup shell

Related Article

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.