标签:mis this leave app mkdir mysql null png iss
vi mysqldump_bak.sh
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
export LANG=en_US.UTF-8
time="$(date +"%Y%m%d%H%M%S")"
savedir=/cloud/backup/mysql/$time
mkdir -p "$savedir"
cd "$savedir"
/usr/bin/mysqldump -h 127.0.0.1 -uroot -p123456 paas_portal > paas_portal_"$time".sql
/usr/bin/mysqldump -h 127.0.0.1 -uroot -p123456 paas_permission > paas_permission_"$time".sql
/usr/bin/mysqldump -h 127.0.0.1 -uroot -p123456 paas_bpm > paas_bpm_"$time".sql
/usr/bin/mysqldump -h 127.0.0.1 -uroot -p123456 paas_message_center > paas_message_center_"$time".sql
示例如下(需要在my.cnf下添加 [mysqldump] user password)
添加脚本 vi /data/app/mysqldump/mysqldump_bak.sh
#!/bin/sh
# This is a ShellScript For Auto DB Backup and Delete old Backup
# back path
backupdir=/data/databackup
time=` date +%Y%m%d%H `
#MYSQL_PWD=$(admindev123$%^) && mysqldump -u root -p$(admindev123$%^) cmccepidemic | gzip > $backupdir/cmccepidemic$time.sql.gz
mysqldump cmccepidemic | gzip > $backupdir/cmccepidemic$time.sql.gz
#keep leave 7 days
find $backupdir -name "name_*.sql.gz" -type f -mtime +7 -exec rm {} \; > /dev/null 2>&1
对docker中的mysql备份
Vi back.sh (编写备份shell脚本)
#!/bin/bash
rm -f /data/epidemic-data-$(date -d -5day +%Y%m%d-*).sql
DATE=`date +%Y%m%d-%H%M`
BACK_DATA=epidemic-data-${DATE}
# mysql-db 是数据库的 docker 名称, xxxpwd 是 root 用户密码, app-db 是要备份的数据名称
docker exec -i mysql mysqldump epidemic -uroot -padmindev123$%^ > /data/${BACK_DATA}.sql
修改
/etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
#添加如下
20 3 * * * root sh /data/app/mysqldump/mysqldump_bak.sh
也可以将多个数据库写成数据 ,如 db = (“paas_portal” “paas_permission” “paas_message_center”)
进行备份,对备份进行压缩 如
/usr/bin/mysqldump -h 127.0.0.1 -uroot -p123456 paas_message_center |gzip > paas_message_center_"$time".sql
gunzip < ./dmdb-20180601.sql.gz | mysql -uroot -p123456 databaseName
Centos7 mysqldump定时任务,对mysql定时备份数据
标签:mis this leave app mkdir mysql null png iss
原文地址:https://www.cnblogs.com/hanby/p/14172091.html