rsync是一款快速增量备份工具,只传送有差别的数据块,所以速度很快。
Usage: rsync [OPTION]... SRC [SRC]... DEST
or rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST
or rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST
or rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST
or rsync [OPTION]... [USER@]HOST:SRC [DEST]
or rsync [OPTION]... [USER@]HOST::SRC [DEST]
or rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]
当源(SRC)是一个目录时,带斜线(/)与不带斜线的处理是不同的。
不带斜线 -- 目录自身也会同步到目的(DEST)下。 即 rsync -a src_folder dest_folder,结果会有dest_folder/src_folder
带斜线 -- 目录自身不同步。
下面是几个实验:
# mkdir -p src/folder1 dst && touch src/folder1/file1 src/file2 dst/fileX
# find . -exec ls -Fd {} \;
./
./dst/
./dst/fileX
./src/
./src/file2
./src/folder1/
./src/folder1/file1
src不带斜线:(dst下面也有src了)
# rsync -a src dst
# find . -exec ls -Fd {} \;
./
./dst/
./dst/src/
./dst/src/file2
./dst/src/folder1/
./dst/src/folder1/file1
./dst/fileX
./src/
./src/file2
./src/folder1/
./src/folder1/file1
# rm -rf src dst && mkdir -p src/folder1 dst && touch src/folder1/file1 src/file2 dst/fileX
# rsync -a src/folder1 dst
# find . -exec ls -Fd {} \;
./
./dst/
./dst/fileX
./dst/folder1/
./dst/folder1/file1
./src/
./src/file2
./src/folder1/
./src/folder1/file1
src/带斜线:
# rm -rf src dst && mkdir -p src/folder1 dst && touch src/folder1/file1 src/file2 dst/fileX
# rsync -a src/ dst
# find . -exec ls -Fd {} \;
./
./dst/
./dst/fileX
./dst/file2
./dst/folder1/
./dst/folder1/file1
./src/
./src/file2
./src/folder1/
./src/folder1/file1
删除src中没有的文件:
# rm -rf src dst && mkdir -p src/folder1 dst && touch src/folder1/file1 src/file2 dst/fileX
# rsync -a --delete src/ dst
# find . -exec ls -Fd {} \;
./
./dst/
./dst/file2
./dst/folder1/
./dst/folder1/file1
./src/
./src/file2
./src/folder1/
./src/folder1/file1
阅读(3565) | 评论(0) | 转发(0) |