Hosts:
- a: local
- b: remote
Local settings
Users and keys
a% sudo adduser b
...
a% sudo -H -u b sh -c 'cd $HOME && ssh-keygen -t rsa'
...
a$ scp ~b/.ssh/id_rsa.pub b:id_rsa.pub-b
rsnapshot
% sudo apt-get install rsnapshot
% sudo mkdir /var/backups/rsnapshot/
rsnapshot.conf
% sudo vi /etc/rsnapshot.conf
...
% diff -u ...
--- a/rsnapshot.conf
+++ b/rsnapshot.conf
...
# All snapshots will be stored under this root directory.
#
-snapshot_root /.snapshots/
+snapshot_root /var/backups/rsnapshot/
...
# Uncomment this to enable remote ssh backups over rsync.
#
-#cmd_ssh /path/to/ssh
+cmd_ssh /usr/bin/ssh
...
#include ???
#exclude ???
#exclude ???
+exclude /cdrom/
+exclude /dev/
+exclude /floppy/
+exclude /mnt/
+exclude /proc/
+exclude /sys/
+exclude /tmp/
+exclude /var/backups/rsnapshot/
+exclude /var/cache/
+exclude /var/run/
...
backup /home/ localhost/
backup /etc/ localhost/
backup /usr/local/ localhost/
...
+# b
+backup root@b:/ /b/ ssh_args=-o BatchMode=yes -i /home/b/.ssh/id_rsa
Remote settings
a% ssh b
...
b$ sudo vi /root/validate-rsync
...
b$ cat /root/validate-rsync
#!/bin/sh
case "$SSH_ORIGINAL_COMMAND" in
*\&*)
echo "Rejected"
;;
*\(*)
echo "Rejected"
;;
*\{*)
echo "Rejected"
;;
*\;*)
echo "Rejected"
;;
*\<*)
echo "Rejected"
;;
*\`*)
echo "Rejected"
;;
*\|*)
echo "Rejected"
;;
rsync\ --server*)
$SSH_ORIGINAL_COMMAND
;;
*)
echo "Rejected"
;;
esac
...
b$ sudo chmod +x /root/validate-rsync
b$ sudo cat id_rsa.pub-b >> /root/.ssh/authorized_keys
b$ sudo vi /root/.ssh/authorized_keys
b$ sudo cat /root/.ssh/authorized_keys
...
command="/root/validate-rsync" ssh-rsa ... == b@a
...
b$ sudo rm id_rsa.pub-b
Execution
Testing
a% sudo rsnapshot configtest
a% sudo rsnapshot -t -v hourly
a% sudo rsnapshot -v hourly
a% ls -al /var/backups/rsnapshot/
...
Registration to cron
--- a/cron.d/rsnapshot
+++ b/cron.d/rsnapshot
...
-# 0 */4 * * * root /usr/bin/rsnapshot hourly
-# 30 3 * * * root /usr/bin/rsnapshot daily
-# 0 3 * * 1 root /usr/bin/rsnapshot weekly
-# 30 2 1 * * root /usr/bin/rsnapshot monthly
+0 */4 * * * root /usr/bin/rsnapshot hourly
+30 3 * * * root /usr/bin/rsnapshot daily
+0 3 * * 1 root /usr/bin/rsnapshot weekly
+30 2 1 * * root /usr/bin/rsnapshot monthly
Tips
- rsnapshot:
- val1<TAB>val2<TAB>val3…
- dir/
- cron:
- Enable hourly, or nothing will ever happen.
See also
-
rsnapshot
http://rsnapshot.org/ -
Follow-up on remote filesystem snapshots with rsnapshot
http://blog.innerewut.de/2005/06/03/follow-up-on-remote-filesystem-snapshots-with-rsnapshot -
Using rsnapshot for File and Database Backups
http://www.ruzee.com/blog/2008/11/using-rsnapshot-for-file-and-database-backups
Other Articles
- 13 Oct 2017: 『テスト駆動開発』
- 19 Oct 2016: 『新装版 達人プログラマー 職人から名匠への道』
- 19 Aug 2016: 『プログラミングElixir』
- 20 Oct 2015: Migrating from git-media to git-lfs
- 04 Oct 2015: Git Large File Storageクライアントのインストール
- 12 Aug 2015: isbn.rb
- 22 Apr 2015: 「なるのか、なすのか?」(To Be Or To Do?)