efficient_backups_with_rsnapshot
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
efficient_backups_with_rsnapshot [2010/07/06 12:25] – tkbletsc | efficient_backups_with_rsnapshot [2010/07/12 06:04] (current) – tkbletsc | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Efficient backups with rsnapshot ====== | ====== Efficient backups with rsnapshot ====== | ||
- | (I need to write a full article here, but I don't have time now. | + | Basically, do this: http://troy.jdmz.net/rsnapshot/ |
- | reminder: on debian/ | + | Reminder: on debian/ |
- | ===== Backing up Windows hosts ===== | + | In place of his rickety '' |
+ | <code perl> | ||
+ | # | ||
+ | # Name: / | ||
+ | # Purpose: Restricts rsync to subdirectory declared in .ssh/ | ||
+ | # | ||
+ | # The client uses "rsync -av -e ssh src/ server: | ||
+ | # executes this program when .ssh/ | ||
+ | # For example: | ||
+ | # command=" | ||
+ | # command=" | ||
+ | # The former limits the remote client to a specific subdirectory of " | ||
+ | # and the latter allows read-only access to a different dirctory. | ||
- | Normally, all you'd need to do to make the server back up Windows hosts is to install Cygwin with SSH and rsync and set up SSH keys as normal. | + | use Socket; |
+ | use constant LOGFILE => '/ | ||
+ | my $Usage = << | ||
+ | Use 'command=" | ||
+ | in front of lines in $ENV{HOME}/.ssh/ | ||
+ | EOM | ||
- | So we'll set up **rsyncd**, | + | # Format of the envrionment variables set by sshd: |
+ | # SSH_ORIGINAL_COMMAND=rsync --server | ||
+ | # SSH_ORIGINAL_COMMAND=rsync --server --sender -vlogDtpr --partial | ||
+ | # SSH_CLIENT=client_addr client_port server_port | ||
- | First, install Cygwin with rsync and anything else you might like. | + | my $ro = (@ARGV |
+ | my $top1 = shift; | ||
+ | die "No subdirectory specified\n$Usage" | ||
+ | my $top2 = " | ||
- | Second, set up rsyncd as a service: | + | my $command = $ENV{SSH_ORIGINAL_COMMAND}; |
+ | die "Not invoked via sshd\n$Usage" | ||
- | | + | my ($cmd, |
+ | die "SSH_ORIGINAL_COMMAND=' | ||
+ | die "$0 -ro: sending to read-only directory $requested_target not allowed\n" | ||
+ | if $ro and $cmd !~ /^rsync --server | ||
- | Third, set up ''/ | + | my $dir = $requested_target; |
+ | $dir =~ tr|-~\\ _/ | ||
+ | $dir =~ s%/ | ||
- | < | + | # For " |
- | uid = nobody | + | # For "foo/bar" and "foo/anything/bar", interpret " |
- | gid = nobody | + | # path and "bar/" to be the specified path with trailing slash supplied. |
- | use chroot = no | + | |
- | max connections = 4 | + | |
- | syslog facility = local5 | + | |
- | pid file = /var/run/rsyncd.pid | + | |
- | read only = true | + | |
- | hosts allow = < | + | |
- | + | ||
- | [root] | + | |
- | path = / | + | |
- | auth users = < | + | |
- | secrets file = /etc/rsyncd.secrets | + | |
- | </file> | + | |
- | Populate the user list '' | + | my($target, |
+ | if ("/$dir" eq substr($top1, | ||
+ | $target = $top1; | ||
+ | } elsif ("/ | ||
+ | $target = $top2; | ||
+ | } elsif ($dir eq $top1 or index($dir, | ||
+ | $target = $dir; # Exact match or subdirectory | ||
+ | } elsif (substr($dir, | ||
+ | $target = " | ||
+ | $forced = 1; | ||
+ | } else { | ||
+ | $target = " | ||
+ | $forced = 1; | ||
+ | } | ||
- | < | + | $target =~ s#^//#/#; # program is dumb and sets root to '//' |
- | < | + | |
- | </file> | + | |
- | Then, on the backup server, create a file ''/ | + | if (-f LOGFILE and open LOG,'>>', |
+ | my $hhmm = sprintf " | ||
+ | my $host = $ENV{SSH_CLIENT} || 'unknown'; | ||
+ | $host =~ s/ .*//; # Keep only the client' | ||
+ | $host = gethostbyaddr(inet_aton($host), | ||
+ | $_ = sprintf "%-13s", | ||
+ | print LOG "$hhmm $_ [$command] =", | ||
+ | close LOG; | ||
+ | } | ||
- | < | + | exec "$cmd $target" |
- | < | + | # Note: This assumes that the rsync protocol will not be maliciously hijacked. |
- | </file> | + | </code> |
- | Now you can add backup lines to your rsnapshot.conf | + | For Windows targets, install cygwin' |
- | backup rsync://< | + | backup windowsuser@windowsbox-rsnapshot:/d/Documents windowsbox/ |
- | + | ||
- | The < | + | |
- | + | ||
- | If you want to back up something like your Firefox profile that will have certain files locked, exclude those files. | + | |
- | + | ||
- | backup rsync://< | + | |
- | + | ||
- | Remember that you don't need to escape spaces, since fields in this line are tab-separated. | + |
efficient_backups_with_rsnapshot.1278444344.txt.gz · Last modified: 2010/07/06 12:25 by tkbletsc