mysql备份脚本
1.mysql备份脚本
#说明:此备份脚本是mysql部署在宿主机上,然后直接使用mysql命令备份。 #!/bin/bash #mysql_backup#### dbuser="root" dbpassword="123443" dbserver="172.16.33.52" dbname="openser" #dbname_callcenter="callcenter" # the directory for story your backup file. back_dir="/app/mysql_backup/" # date format for backup file (dd-mm-yyyy) time="$(date +"%d-%m-%Y")" # mysql, mysqldump and some other bin's path MKDIR="/bin/mkdir" RM="/bin/rm" MV="/bin/mv" GZIP="/bin/gzip" # get all databases cd /usr/bin /usr/bin/mysqldump -u $dbuser -p$dbpassword --default-character-set=utf8 --opt -R -E $dbname | $GZIP -9 > "$back_dir$time$dbname.gz" #/usr/bin/mysqldump -u $dbuser -p$dbpassword --default-character-set=utf8 --opt -R -E $dbname_callcenter | $GZIP -9 > "$back_dir$time$dbname_callcenter.gz" ###delete 7 days ago data find $back_dir -name "*openser.gz" -mtime +7 -exec rm -rf {} \; #find $back_dir -name "*callcenter.gz" -mtime +7 -exec rm -rf {} \;
2.mysql备份脚本 #说明:此脚本mysql部署在docker容器里,在外部直接备份。 #!/bin/bash #mysql_backup#### dbuser="root" dbpassword="ssss@1234" #dbserver="172.16.33.52" #dbname="aiboxcloud_test" dbname="aibox_cloud" #dbname_callcenter="callcenter" # the directory for story your backup file. back_dir="/data/backup/mysql_bak/" # date format for backup file (dd-mm-yyyy) date=$(date "+%Y%m%d%H") # get all databases docker exec -it mysql bash -c "mysqldump -u $dbuser -p$dbpassword --default-character-set=utf8 --opt -R -E $dbname > /${dbname}_${date}.sql" > /dev/null #docker exec -it mysql bash -c "mysqldump -uroot -pytx@1234 --opt -R -E aiboxcloud_test > aiboxcloud_test_20220923.sql" sleep 1 docker cp mysql:/${dbname}_${date}.sql $back_dir docker exec -it mysql bash -c "rm -f /${dbname}_${date}.sql" ###delete 7 days ago data find $back_dir -name "*.sql" -type f -mtime +3 | xargs rm -f