Heim  >  Artikel  >  Datenbank  >  使用rsync进行MySQL增量备份

使用rsync进行MySQL增量备份

WBOY
WBOYOriginal
2016-06-07 17:18:271088Durchsuche

mysql_back.sh脚本中的相关参数解释。expect -c中的-c全拼为command命令的含义,也就是说-c 后面跟的是相关的命令,但这些命令要

一、环境描述(使用rsync进行mysql的增量备份)

192.168.0.2为备份服务器

192.168.0.3为需要经常备份的mysql数据库

二、主要配置

1.备份服务器配置
useradd mysql_db -d /data/bak
passwd rsync_server
#密码我配置的为“123”

2.mysql服务器配置
vi mysql_back.sh
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
binlog_dir=/data/mysql/3306/logs
#delete old binlog FileList
if [ -f $binlog_dir/mysql-bin.index ];then
 rm -f $binlog_dir/mysql-bin.index
fi
passwd="123"
ls -l $binlog_dir |grep  mysql-bin| awk '{print $8}' >/data/mysql/3306/logs/binlog/mysql-bin.index
Rsync_exec(){
        expect -c "
        set timeout 600;
        spawn rsync -rpogtv --progress --files-from=$binlog_dir/binlog/mysql-bin.index $binlog_dir mysql_db@192.168.0.2:/data/bak
        expect {
                \"*yes/no*\" {send \"yes\r\";exp_continue}
                \"*password*\" {send \"$passwd\r\";}
        }
        expect eof;"
}
Rsync_exec
 
3.赋予mysql_back.sh可执行的权利,添加计划任务即可使用。
 
//mysql_back.sh脚本中的相关参数解释。expect -c中的-c全拼为command命令的含义,也就是说-c 后面跟的是相关的命令,但这些命令要用" "引起来。set timeout设置了脚本的超时为600秒,spawn为运行系统命令的开始模式。rsync -rpogtv中r表示递归进入目录,p表示保留文件原来的权限,o表示保留文件原来的拥有者,g表示保留文件原来的所属组,,t表示保留文件原来创建或修改后的时间,v表示增加冗长信息,--progress表示显示rsync的过程,--files-from表示从哪里获取需要进行rsync的文件。expect 在这里使用的目的是为了避免交互式,其中\"*yes/no*\"两端的\为其后面跟着的"的转义符,*为任意匹配,eof表示程序的结束。

linux

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn