关于rsync的介绍网上有很多,这里直接说一下如何使用rsync
本次使用rsync的是将备份文件拉取一份到异地机房,只保留一份
1.首先安装rsync yum install rsync 2.配置rsyncd.conf(如果没有自行创建) [root@005---1 ~]# cat /etc/rsyncd.conf uid = root gid = root use chroot = yes strict modes = false pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock #### log file = /var/log/rsyncd.log transfer logging = true log format= "%o [%a] %m (%u) %f %l %b %c reverse lookup = no ignore errors = true read only = false strict modes = yes list = false max connections = 100 timeout = 1800 [backup] path = /backup auth users = backup secrets file = /etc/rsyncd.d/pass.server [mysqlbackup] path = /mysqlbackup auth users = backup secrets file = /etc/rsyncd.d/pass.server 3.配置密码文件(如果没有自行创建) [root@005---1 ~]# cat /etc/rsyncd.d/pass.server backup:backup 4.授权 [root@005---1 ~]# chmod 600 /etc/rsyncd.d/pass.server 5.启动 /usr/bin/rsync --daemon --config=/etc/rsyncd.conf [root@005---1 ~]# ps -ef|grep rsync root 334 30589 0 16:50 pts/7 00:00:00 grep --color=auto rsync root 2305 1 0 Jul01 ? 00:00:00 /usr/bin/rsync --daemon --config=/etc/rsyncd.conf 6.定时同步脚本rsync_bakcup.sh [root@cpe-172-100-1-86 ~]# cat /opt/scripts/rsync_bakcup.sh #!/bin/sh today=`date --date='0 days ago' +%Y_%m_%d` echo $today find /data/backup/mongodbbackup/20* -type d -mtime +0|xargs -l rm -rf \; find /data/backup/oraclebackup/rman/20* -type d -mtime +0|xargs -l rm -rf \; find /data/backup/mysqlbackup/xtrabackup/backup172.200.239.150_3306/20* -type d -mtime +0|xargs -l rm -rf \; find /data/backup/mysqlbackup/xtrabackup/backup172.200.239.185_3306/20* -type d -mtime +0|xargs -l rm -rf \; find /data/backup/mysqlbackup/xtrabackup/backup172.200.239.186_3306/20* -type d -mtime +0|xargs -l rm -rf \; find /data/backup/mysqlbackup/xtrabackup/backup172.200.239.198_3306/20* -type d -mtime +0|xargs -l rm -rf \; find /data/backup/mysqlbackup/xtrabackup/backup172.200.250.140_3306/20* -type d -mtime +0|xargs -l rm -rf \; echo "mongodb ..." /usr/bin/rsync -vzrtopg -P backup@172.200.239.187::backup/mongodb_backup/$today /data/backup/mongodbbackup --bwlimit=300000 --password-file=/etc/rsyncd.d/pass.server echo "oracle rman backup" /usr/bin/rsync -vzrtopg -P backup@172.200.239.187::backup/rman/$today /data/backup/oraclebackup/rman --bwlimit=300000 --password-file=/etc/rsyncd.d/pass.server today=`date --date='0 days ago' +%Y-%m-%d` echo $today echo "backup172.200.239.185_3306" /usr/bin/rsync -vzrtopg -P backup@172.200.239.187::backup/xtrabackup/backup172.200.239.185_3306/$today /data/backup/mysqlbackup/xtrabackup/backup172.200.239.185_3306 --bwlimit=300000 --password-file=/etc/rsyncd.d/pass.server echo "backup172.200.239.186_3306" /usr/bin/rsync -vzrtopg -P backup@172.200.239.187::backup/xtrabackup/backup172.200.239.186_3306/$today /data/backup/mysqlbackup/xtrabackup/backup172.200.239.186_3306 --bwlimit=300000 --password-file=/etc/rsyncd.d/pass.server echo "backup172.200.250.140_3306" /usr/bin/rsync -vzrtopg -P backup@172.200.239.187::backup/xtrabackup/backup172.200.250.140_3306/$today /data/backup/mysqlbackup/xtrabackup/backup172.200.250.140_3306 --bwlimit=300000 --password-file=/etc/rsyncd.d/pass.server echo "backup172.200.239.150_3306" /usr/bin/rsync -vzrtopg -P backup@172.200.239.187::mysqlbackup/xtrabackup/backup172.200.239.150_3306/$today /data/backup/mysqlbackup/xtrabackup/backup172.200.239.150_3306 --bwlimit=300000 --password-file=/etc/rsyncd.d/pass.server echo "backup172.200.239.198_3306" /usr/bin/rsync -vzrtopg -P backup@172.200.239.187::mysqlbackup/xtrabackup/backup172.200.239.198_3306/$today /data/backup/mysqlbackup/xtrabackup/backup172.200.239.198_3306 --bwlimit=300000 --password-file=/etc/rsyncd.d/pass.server