Section Next | Prev


2.5.3 ディレクトリ同期(rsync)

【機能説明】
rsync は二つのディレクトリ内容の同期を行います。増分ではなく差分を管理でき、ネットワークを介した別システムのディレクトリも操作できます。

【入力フォーマット】
rsync[オプション]ディレクトリ1 ディレクトリ2
ディレクトリに「ホスト名:ディレクトリ」を指定する事でネットワークを介した同期ができます。

【主なオプション】

【実行例】
  1. dir1 と同じ構造の dir2 を作成
    	[student@h006 ~]$ ls dir1 dir2
    	dir1:
    	a.dat  data.cpio  name.data  name.list  versions.txt
    
    	dir2:
    	[student@h006 ~]$ rsync -av dir1/ dir2/
    	# ディレクトリの場合は最後に / を付ける。
    	sending incremental file list
    	./
    	a.dat
    	data.cpio
    	name.data
    	name.list
    	versions.txt
    
    	sent 1,568 bytes  received 114 bytes  3,364.00 bytes/sec
    	total size is 1,173  speedup is 0.70
    
  2. 更新されたファイルのみ同期
    	# touch を使ってタイムスタンプを更新
    	[student@h006 ~]$ touch dir1/data.cpio 
    	[student@h006 ~]$ ls -l dir?
    	dir1:
    	合計 20
    	-rw-rw-r-- 1 student student   8  7月 22 10:13 a.dat
    	-rw-rw-r-- 1 student student 512  7月 22 10:30 data.cpio
    	-rw-r--r-- 1 student student  43  7月 22 10:09 name.data
    	-rw-rw-r-- 1 student student  43  7月 22 10:09 name.list
    	-rw-rw-r-- 1 student student 567  7月 22 10:09 versions.txt
    
    	dir2:
    	合計 20
    	-rw-rw-r-- 1 student student   8  7月 22 10:13 a.dat
    	-rw-rw-r-- 1 student student 512  7月 22 10:11 data.cpio
    	-rw-r--r-- 1 student student  43  7月 22 10:09 name.data
    	-rw-rw-r-- 1 student student  43  7月 22 10:09 name.list
    	-rw-rw-r-- 1 student student 567  7月 22 10:09 versions.txt
    	[student@h006 ~]$ rsync -av dir1/ dir2/
    	sending incremental file list
    	data.cpio
    
    	sent 732 bytes  received 35 bytes  1,534.00 bytes/sec
    	total size is 1,173  speedup is 1.53
    
  3. 削除された内容の反映
    	[student@h006 ~]$ rm dir1/data.cpio
    	[student@h006 ~]$ rsync -av --delete dir1/ dir2/
    	sending incremental file list
    	deleting data.cpio
    	./
    
    	sent 152 bytes  received 28 bytes  360.00 bytes/sec
    	total size is 661  speedup is 3.67
    
  4. ネットワークを介した同期
    	[student@h006 ~]$ rsync -av dir1/ ycos:dir1/
    	ycos2@ycos2.sakura.ne.jp's password: 
    	sending incremental file list
    	./
    	a.dat
    	name.data
    	name.list
    	versions.txt
    
    	sent 960 bytes  received 98 bytes  49.21 bytes/sec
    	total size is 661  speedup is 0.62
    

Section Next | Prev

Copyright 2007-2018 ycosSystems Bkup/Body253.html