Linux_Rsyncリモート同期バックアップサーバ
目次
Remote Sync
機能:1.ディレクトリツリーとファイルシステム全体をミラーして保存できます.元のファイルの権限、時間、所有者、ソフト・ハード接続などを維持しやすい.ファイルはrcp,sshなどを用いて転送するもよいし,socketを介して直接接続するもよい.匿名転送General use for remote backup and backup localhost file into remote host(auto-periodical execute)Distinction of backup and copy:1をサポートする.backup:Update the data. 2. copy:Move all data to other space. RSyncはインクリメンタルバックアップを実現し、データの更新とリアルタイムバックアップを同期できます.RSyncホスト同期ネットワークYUMソース、ローカルローカルエリアネットワーク同期RSyncホストYUMソース.
同期のタイプ
ローカルモード
aディレクトリ内のファイルをrsyncを介して別のbディレクトリexampleに移動します.
rsync -av test /tmp
Attention:a./tmp/:tmpディレクトリをバックアップせず、tmpディレクトリの下のコンテンツのみをバックアップするb./tmp:tmpディレクトリと以下のコンテンツを完全にバックアップする
リモートモード
下部はSSHプロトコルexampleを使用しています.
rsync -av /tmp root@GoalHostIP:/root
RSyncリストモード
example:
rsync -a IP:cisco
RSyncサービスモード:
Rsync同期ソース、SSHソース->バックアップファイルのソースホスト
Setup RSync service
step1. Create RSync service configuration file by manual vim/etc/rsyncd.conf
#RSync configuration file
#Welcome file
motd file = /etc/rsyncd.motd
read>list = yes
uid=root
gid=root
use chroot = no
max connections = 5
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd/lock
#Specify share directory
[wwwroot]
path = /var/www/html
readonly = yes
auth users = jmilk
#user authentication file, store userName and password
secrets file = /etc/rsyncd.db
comment = rsync directory
step2. Create password file
echo "jmilk:fanguiju" >> /etc/rsyncd.db
chmod 600 /etc/rsyncd.db
step3. Start rsync service
rsync --deamon
How to use the rsync commands
rsyncコマンドオプション:
-av -z --delete --password-file=/etc/server -H
example:
#use rsync source:
rsync -avzH --delete backuper@:ip::wwwroot /var/www/html --> ::shareDirectory
#use ssh source in the client:
rsync -avzH root@RSyncServerIP:/syncDirectory /localhostBackupDirecttory
SSH Source create Key Pair:
ssh-keygen -t rsa
ssh-copy-id root@RSyncServerIP
RSync Source create Key Pair: vim/etc/rsyncd.conf
RSYNC_PASSWORD="pwd123"
RSync backup:
rsync -avzH -b --backup-dir=old root@SyncServerIP:/syncDirectory /localhostBackupDirectory
#old --> , /localostBackupDirectory
#-b --> backup mode
rsync -avzH -b --backup-dir='date+ "%Y%M%B%H%M%S"' root@SyncServerIP:/syncDirectory /localhostBackupDirectory #
rsync -avzH -b --backup-dir='date+ "%Y%M%B%H%M%S"' --exclude=up root@SyncServerIP:/syncDirectory /localhostBackupDirectory # up
inotify+rsync Real-time sync
inotifyメカニズム:ファイルシステムの変化を監視するSoftware:inotofy-tools(RSyncServerにインストール)inotify kernel parameter:
max_queue_events:
max_user_instances:
max_user_watches:
Setup inotify
tar zxvf inotify-tools -C /usr/local
cd /usr/local/inotify-tools
./confugure && make && make install
inotifywait -mrq -e modify,create,move,delete /data/ --exclude=/data/up/
#wait
#-e
#--exclude
BUG:コンパイルインストール中に上記のコマンドを実行すると、libinotifytoolsが発生する可能性があります.so.o:cannot open shared object file error解決方法:ln-S/usr/local/lib/libinotifytools.so.o/usr/lib64