时间:2021-07-01 10:21:17 帮助过:43人阅读
#!/bin/bash
pdate=`date +%F-%H`
user_name=root
host_name=localhost
db_name=typecho
db_pass=asdqwe123
prefix=wz
db_biao=typecho_contents
##备份库##
quanku() {
mysqldump -u$user_name -p$db_pass -P3306 $db_name > /data/backup/${pdate}.sql
tar czf /data/backup/${prefix}${pdate}.sql.tgz /data/backup/${pdate}.sql &> /dev/null
}
##备份表##
biao() {
mysqldump -u $user_name -p $db_pass -P3306 $db_name $db_biao > /data/backup/${db_biao}${pdate.sql}
tar czf /data/backup/${prefix}${pdate}.sql.tgz /data/backup/${db_biao}${pdate.sql} &> /dev/null
}
$1
加入计划任务 vim /etc/crontab
*/60 * * * * root sh /root/shell/mysql.sh quanku
/30 * root sh /root/shell/mysql.sh biao
重启
systemctl restart crond
mysql 备份数据库
标签:数据库 localhost mys emctl mysq mysqldump 备份表 crontab type