rsync+cronによる自動バックアップ設定
rsyncは簡単です。
バックアップ機からシェルを叩く場合
rsync -avz -e ssh --delete master-host:/path/to/master-dir/ /path/to/backup-dir/
あとは、これをシェル化して、cronに登録するのですが、パスワード無しでsshで接続できるようにしておかないと、自動実行できません。
この辺りを参考にしました。
マスター側の設定
# diff -u /etc/ssh/sshd_config.orig /etc/ssh/sshd_config --- sshd_config.orig 2009-11-19 18:51:08.000000000 +0900 +++ sshd_config 2009-11-19 18:05:54.000000000 +0900 @@ -36,28 +36,28 @@ # Authentication: #LoginGraceTime 2m -#PermitRootLogin yes +PermitRootLogin yes #StrictModes yes #MaxAuthTries 6 -#RSAAuthentication yes -#PubkeyAuthentication yes +RSAAuthentication no +PubkeyAuthentication no #AuthorizedKeysFile .ssh/authorized_keys # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts -#RhostsRSAAuthentication no +RhostsRSAAuthentication no # similar for protocol version 2 -#HostbasedAuthentication no +HostbasedAuthentication yes # Change to yes if you don't trust ~/.ssh/known_hosts for # RhostsRSAAuthentication and HostbasedAuthentication #IgnoreUserKnownHosts no # Don't read the user's ~/.rhosts and ~/.shosts files -#IgnoreRhosts yes +IgnoreRhosts no # To disable tunneled clear text passwords, change to no here! #PasswordAuthentication yes -#PermitEmptyPasswords no +PermitEmptyPasswords no PasswordAuthentication yes # Change to no to disable s/key passwords #ChallengeResponseAuthentication yes @@ -110,7 +110,6 @@ #PidFile /var/run/sshd.pid #MaxStartups 10 #PermitTunnel no -#ChrootDirectory none # no default banner path #Banner /some/path # vi ~/.shosts backup-host root
バックアップ機の設定
# diff -u ssh_config.orig ssh_config --- ssh_config.orig 2009-11-19 18:15:25.000000000 +0900 +++ ssh_config 2009-11-19 18:16:10.000000000 +0900 @@ -50,3 +50,8 @@ SendEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES SendEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT SendEnv LC_IDENTIFICATION LC_ALL + +# someone add +Host fsdev1 +HostbasedAuthentication yes +PreferredAuthentications hostbased,publickey,password # cat /path/to/backup.sh #!/bin/sh RSYNC='rsync -avz -e ssh --delete' HOST='master-host' $RSYNC $HOST:/path/to/master-dir/ /path/to/backup-dir/ # crontab -l 0 2 * * * /path/to/backup.sh > /dev/null 2>&1
上の場合、毎日2時に同期を取るように設定しています。