1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

rsyncしてみる

Posted at

rsync とは

ネットワークを通じて、ファイルやディレクトリをsyncするものです。
もちろんlocalでの使用もできます。

やってみる

構成

  • 構成

構成のイメージとしては以下になります。
サーバをまたいであるディレクトリ配下が同期される感じです。

12022-04-12 rsyncコマンド使ってみる - diagrams.net - Google.png

  • 設定
- 同期元 : 192.168.156.121 : /var/tmp/test
- 同期先 : 192.168.156.122 : /var/tmp/test_dir

同期元サーバの設定

  • 同期ディレクトリの作成
mkdir /var/tmp/test
  • rsyncのインストール
yum -y install rsync

同期先サーバの設定

  • 同期ディレクトリの作成
mkdir /var/tmp/test_dir
  • rsyncのインストール
yum -y install rsync
  • rsyncの設定

[testdir] : 名前をつけました。なんでもいいです。
path : 同期先のディレクトリを指定
hosts allow : 同期元のサーバを指定

vi /etc/rsyncd.conf
==========
[testdir]
path = /var/tmp/test_dir
hosts allow = 192.168.156.121
hosts deny = *
list = true
uid = root
gid = root
read only = false
==========
  • 起動・自動起動設定
service rsyncd start
service rsyncd enable

同期元サーバから同期をかける

  • あらかじめファイル置いておく
touch /var/tmp/test/a.txt
  • 同期を行う

rsync [オプション] 同期元ディレクトリ 同期先サーバ::任意の名前 で同期できます。

オプションは以下になります。
-a : アーカイブモード
-v : 動作内容の表示
-z : 転送中のデータを圧縮
--delete : 同期元にないファイルを同期先から削除する

rsync -avz --delete /var/tmp/test/ 192.168.156.122::testdir
sending incremental file list
./
a.txt

sent 107 bytes  received 45 bytes  304.00 bytes/sec
total size is 0  speedup is 0.00

勉強後イメージ

どっかでやったような気もするけど、ちょっと残したかったので書いてみた。
思ったよりオプションが豊富だった。

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?