Think before you speak, read before you think.

rsync使用方法

by

in
服务器1:192.168.1.1
服务器2:192.168.1.2
要求:
将192.168.1.1的abc目录同步到192.168.1.2上的/tmp/temp下
rsync -a [email protected]:/home/bak/abc /tmp/temp/

如果端口为非22,则加上 -e 'ssh -p 537', –progress显示进度

rsync -a --progress -e 'ssh -p 537' [email protected]:/data/jpuyy.com /home/bak/

rsync增量备份

增量硬链备份,对比bk1,如果有增量则备份到bk2中

rsync -au myadmin bk1
rsync -au --link-dest=/root/bk1 myadmin bk2

实际增量备份脚本

#!/bin/bash

cur_date=`date +%F`
rsync="/usr/bin/rsync"
args="-au --bwlimit=30000 --copy-links"
user='root'
local_dir='/data/all_web_backup/abc.com/'

IFS=' '
while read project ip path
do
# rsync loop , project one by one
mkdir -p $local_dir/$project
last_rsync=`ls $local_dir/$project | grep -P "\d{4}-\d{2}-\d{2}" | sort | tail -1`
if [ -d "$local_dir/$project/$last_rsync" ]; then
$rsync $args -e 'ssh -p 22' --link-dest=$local_dir/$project/$last_rsync $user@$ip:$path $local_dir/$project/$cur_date
else
$rsync $args -e 'ssh -p 22' $user@$ip:$path $local_dir/$project/$cur_date
fi
done < backup_list

backup_list的内容需要如下格式

 bbs 192.168.1.5 /home/www/abc/bbs

rsync的时候同步到远端并exclude .git目录

rsync -r --exclude=.git . /var/www/html/jpuyy.com

控制传输带宽

rsync --bwlimit=kb/second source dest

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *