时间:2021-07-01 10:21:17 帮助过:25人阅读
由于公司数据比较重要,隔一段时间就需要备份,就写了个简单的shell来维护下。。。
#!/bin/bash #backup database if [ $# -ge 1 ] ; then databaselist=$@ else databaselist="dodo_account dodo_edu" fi for database in $databaselist do if [ ! -e /home/guimingming/backup_databases/$database ] then mkdir -p /home/guimingming/backup_databases/$database fi mysqldump --opt -hxx.xx.xx.x -u{username} -p{pwd} $database |gzip > /home/guimingming/backup_databases/$database/$database$(date +"%Y-%m-%d %H:%M:%S").sql.gz if [ $? -eq 0 ] then echo "$(date +"%Y-%m-%d %H:%M:%S") Database ---$database--- Backup Successfully Completed\r\n" find /home/guimingming/backup_databases/$database/ -name $database\* -ctime +1 -exec rm -rf {} \; else echo "$(date +"%Y-%m-%d %H:%M:%S") Database ---$database--- Backup unsuccessfully,please check out the reason\r\n" fi done #!/bin/bash # 假设将database_name数据库名改为database_name_2_2016_06_28 # MyISAM直接更改数据库目录下的文件即可 mysql -uroot -e ‘create database if not exists database_name;‘ list_table=$(mysql -uroot -Nse "select table_name from information_schema.TABLES where TABLE_SCHEMA=‘database_name_2‘") for table in $list_table do mysql -uroot -e "rename table database_name_2.$table to database_name.$table" done #mysql -u root database_name_2<database_name_220160628-frm 0 3 * * 1 sh /usr/local/shell/backup_database.sh >/dev/null 2>&1 0 3 1 * * sh /usr/local/shell/backup_database.sh {param}>/dev/null 2>&1 原文:http://www.cnblogs.com/guixiaoming/p/7427076.html数据库备份的脚本,记录下,还需优化下
标签:usr mysqldump bsp com 记录 cti out 时间 data