Os 7 shell编程数据库分库分表备份+任务定时计划

做mysql主从

见前两篇博客

数据库备份shell脚本

[root@localhost ~]# vim /shell/backup_mysql.sh

#!/bin/bash
date=`date +%Y-%m-%d`

database=`mysql -uroot -p123456 -e "show databases;" | grep -v Database`

for db in $database
do
        [ -d /opt/$date/$db ] || mkdir -p /opt/$date/$db

        mysqldump -uroot -p123456 --skip-lock-tables $db > /opt/$date/$db.sql
        table=`mysql -uroot -p123456 -e "show tables from $db" | grep -v Tables`
        for t in $table
        do
                mysqldump -uroot -p123456 --skip-lock-tables $db $t > /opt/$date/$db/$t.sql
        done
done

任务定时

[root@localhost ~]# crontab -e

00 00 * * * /shell/backup_mysql.sh

查看定时任务

[root@localhost ~]# crontab -l
00 00 * * * /shell/backup_mysql.sh

你可能感兴趣的:(shell)