export RSYNC_RSH="ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no" # include/excludeが効かない場合 #RSYNC_COMMAND="nice rsync -vauz --copy-links --bwlimit=8192 --timeout=600 --include='*/' --include='*.gz' --include='*.log' --exclude='*' /src /dest" # うまく効く場合 RSYNC_COMMAND="nice rsync -vauz --copy-links --bwlimit=8192 --timeout=600 --include=*/ --include=*.gz --include=*.log --exclude=* /src /dest" $RSYNC_COMMAND
touch src/test.log rsync -avz src/ dest/ stat src/test.log File: `src/test.log' Size: 679 Blocks: 8 IO Block: 4096 通常ファイル Device: fd00h/64768d Inode: 412733 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 501/user01) Gid: ( 501/user01) Access: 2016-06-28 12:42:46.000000000 +0900 Modify: 2016-06-28 12:42:39.000000000 +0900 Change: 2016-06-28 12:42:46.458377859 +0900 echo "add: $(date)" >> 0/test.log rsync -avz --partial --append src/ dest/ stat src/test.log File: `src/test.log' Size: 727 Blocks: 8 IO Block: 4096 通常ファイル Device: fd00h/64768d Inode: 412733 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 501/user01) Gid: ( 501/user01) Access: 2016-06-28 12:44:06.000000000 +0900 Modify: 2016-06-28 12:43:15.000000000 +0900 Change: 2016-06-28 12:44:06.435473384 +0900
sudo rsync -vauz --bwlimit=8192 --timeout=600 --include '*/' --include '*.gz' --exclude '*' -e 'ssh -i /home/user01/.ssh/id_rsa -o StrictHostKeyChecking=no' /var/log/ user01@dest-host:/opt/log/$(hostname -s)/
cat include.txt # for home + user01/*** + user02/*** # all exclude - * rsync -avz --include-from include.txt /home/ /backup/
rsync -avz --include 'user01' --include '*.gz' --exclude '*'
あまり巨大なファイルを転送しようとすると停止する場合がある。
また、cronで実行する場合、rsyncのデフォルトは「--timeout=0」なので永遠に待つ場合があるので必ず付ける。
--bwlimit=8192 --timeout=600
rsync -avz -e "ssh -i 秘密鍵.pem -o StrictHostKeyChecking=no" 111.222.333.444:/home/hoge/test ./test
readonly SSH_OPTION="-o StrictHostKeyChecking=no -i 秘密鍵.pem" readonly RSYNC_RSH="ssh $SSH_OPTION" export RSYNC_RSH rsync -avz 111.222.333.444:/home/hoge/test ./test
sudo -E -u user rsync ...