mysql备份脚本
#!/bin/bash db_user=root db_password=123456 db_port=3306 db_host=127.0.0.1 db_datadir='/data/mysql/data' db_bak_dir='/data/mysql/backup' current_time=`date +%F` current_time_change=`date +%s` innobackupex --user=$db_user --password=$db_password --port=$db_port --host=$db_host --datadir=$db_datadir --stream=tar $db_bak_dir 2>$db_bak_dir/backup.log | gzip>$db_bak_dir/${current_time}-mysql-bak.tgz #只保留两天备份,清理过期备份 cd $db_bak_dir for i in `ls`;do file_create_time=`stat -c %Y $i` diff_file_create_time=`expr $current_time_change - $file_create_time` if [ $diff_file_create_time -gt 172800 ];then rm -rf $i fi done
安装xtrabackup见这篇文章:https://www.cnblogs.com/zcpeng/articles/15693848.html
本文来自博客园,作者:kuzane,转载请注明原文链接:https://www.cnblogs.com/kuzane/articles/15696829.html

浙公网安备 33010602011771号