rsync in linux
1) rsync in linux
1@@@@ local
@@@
@@@<1> use rsync, remote or local synchron target file. case1
@@@
Case1: source and target have the same filename, but content are differents.
Then you run the rsync, What is the result?
[root@station78 ~]# ls -R source_file/ target_file/
source_file/:
file1 file2
target_file/:
file1 file2
@@@source dir:
[root@station78 ~]# cd source_file/
[root@station78 source_file]# cat file1
111
222
333
[root@station78 source_file]# cat file2
111
222
333
@@@target dir:
[root@station78 ~]# cd target_file/
[root@station78 target_file]# cat file1
111
222
[root@station78 target_file]# cat file2
111111111111111111111111111111111
@@@
@@@Testing contents
[root@station78 ~]# rsync -avz source_file/ target_file/
sending incremental file list
./
file1
file2
sent 162 bytes received 53 bytes 430.00 bytes/sec
total size is 24 speedup is 0.11
[root@station78 ~]# cd target_file/
[root@station78 target_file]# cat file1
111
222
333
[root@station78 target_file]# cat file2
111
222
333
@@@
@@@<2> local case2
@@@
Case2: source and target have different filename, then What's the result?
@@@source dir:
[root@station78 ~]# cd source_file/
[root@station78 source_file]# cat file1
111
222
333
[root@station78 source_file]# cat file2
111
222
333
@@@target dir:
[root@station78 target_file]# pwd
/root/target_file
[root@station78 target_file]# ls
file3
[root@station78 target_file]# cat file3
xxxx
@@@Testing
[root@station78 ~]# rsync -avz source_file/ target_file/
sending incremental file list
./
file1
file2
sent 162 bytes received 53 bytes 430.00 bytes/sec
total size is 24 speedup is 0.11
@@@
@@@Result: file3 do not be removed, and add file1 and file2.
[root@station78 ~]# cd target_file/
[root@station78 target_file]# ls
file1 file2 file3
[root@station78 target_file]# cat file1
111
222
333
[root@station78 target_file]# cat file2
111
222
333
[root@station78 target_file]# cat file3
xxxx
2@@@@ remote
the same, just add user@[hostname|ip]:dir
like
rsync -avz root@station15:/root/sourcedir /root/targetdir
rsync -avz /root/sourcedir root@station78:/root/targetdir
Bear in mind:
It is the files in source directory were copy to the target directory,
if there are the same filename in target dir,
then cover it by the file in source directory,
if there are not the same filename in target dir,
then do nothing.
3@@@@ When we need this tool?
You backup something big.
such as
When I backup my Documents to my moving disk, It is very convenient and speed.
You could use this in your shell script, then the shell script could be run in
crontab for daily backup something. It is magic.
1@@@@ local
@@@
@@@<1> use rsync, remote or local synchron target file. case1
@@@
Case1: source and target have the same filename, but content are differents.
Then you run the rsync, What is the result?
[root@station78 ~]# ls -R source_file/ target_file/
source_file/:
file1 file2
target_file/:
file1 file2
@@@source dir:
[root@station78 ~]# cd source_file/
[root@station78 source_file]# cat file1
111
222
333
[root@station78 source_file]# cat file2
111
222
333
@@@target dir:
[root@station78 ~]# cd target_file/
[root@station78 target_file]# cat file1
111
222
[root@station78 target_file]# cat file2
111111111111111111111111111111111
@@@
@@@Testing contents
[root@station78 ~]# rsync -avz source_file/ target_file/
sending incremental file list
./
file1
file2
sent 162 bytes received 53 bytes 430.00 bytes/sec
total size is 24 speedup is 0.11
[root@station78 ~]# cd target_file/
[root@station78 target_file]# cat file1
111
222
333
[root@station78 target_file]# cat file2
111
222
333
@@@
@@@<2> local case2
@@@
Case2: source and target have different filename, then What's the result?
@@@source dir:
[root@station78 ~]# cd source_file/
[root@station78 source_file]# cat file1
111
222
333
[root@station78 source_file]# cat file2
111
222
333
@@@target dir:
[root@station78 target_file]# pwd
/root/target_file
[root@station78 target_file]# ls
file3
[root@station78 target_file]# cat file3
xxxx
@@@Testing
[root@station78 ~]# rsync -avz source_file/ target_file/
sending incremental file list
./
file1
file2
sent 162 bytes received 53 bytes 430.00 bytes/sec
total size is 24 speedup is 0.11
@@@
@@@Result: file3 do not be removed, and add file1 and file2.
[root@station78 ~]# cd target_file/
[root@station78 target_file]# ls
file1 file2 file3
[root@station78 target_file]# cat file1
111
222
333
[root@station78 target_file]# cat file2
111
222
333
[root@station78 target_file]# cat file3
xxxx
2@@@@ remote
the same, just add user@[hostname|ip]:dir
like
rsync -avz root@station15:/root/sourcedir /root/targetdir
rsync -avz /root/sourcedir root@station78:/root/targetdir
Bear in mind:
It is the files in source directory were copy to the target directory,
if there are the same filename in target dir,
then cover it by the file in source directory,
if there are not the same filename in target dir,
then do nothing.
3@@@@ When we need this tool?
You backup something big.
such as
When I backup my Documents to my moving disk, It is very convenient and speed.
You could use this in your shell script, then the shell script could be run in
crontab for daily backup something. It is magic.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.