5 Simpliest possible backup from remote host (with natcat as
6 only depenency) to ad-hoc remote server
8 Install on client with:
10 echo install | nc 127.0.0.1 9001 > bak ; chmod 755 bak
14 ./server.pl /path/to/backup 127.0.0.1
16 You will want to add following to C<~/.ssh/config>
18 RemoteForward 9001 localhost:9001
28 my ( $dir, $server_ip ) = @ARGV;
29 die "usage: $0 /backup/directory\n" unless $dir;
30 $server_ip ||= '127.0.0.1';
32 my $shell_client = <<__SHELL_CLIENT__;
34 echo `hostname -s` `pwd` \$* | nc $server_ip 9001
38 system 'git init' unless -e '.git';
40 my $server = IO::Socket::INET->new(
42 LocalAddr => $server_ip,
49 warn "dir: $dir listen: $server_ip:9001\n"
50 , "remote-host> echo install | nc $server_ip 9001 > bak ; chmod 755 bak\n"
54 while (my $client = $server->accept()) {
55 my ($hostname,$pwd,$command,$path,$message) = split(/\s+/,<$client>,5);
57 if ( $pwd eq 'install' ) {
58 warn "install on $hostname\n";
59 print $client $shell_client;
61 system 'ssh-copy-id', "root\@$hostname" if ! -d $hostname;
66 $path = "$pwd/$path" unless $path =~ m{^/};
68 warn "$hostname [$command] $path | $message\n";
74 mkpath "$hostname/$dir" unless -e "$hostname/$dir";
77 system "find $hostname -type f | sed 's,$hostname,,' > /tmp/$hostname.list";
78 system "rsync -avv --files-from /tmp/$hostname.list root\@$hostname:/ $hostname/"
79 } elsif ( $command eq 'add' ) {
80 system 'rsync', '-avv', "root\@$hostname:$path", "$hostname/$path";
81 system 'git', 'add', "$hostname/$path";
82 } elsif ( $command eq 'commit' ) {
83 system 'rsync', '-avv', "root\@$hostname:$path", "$hostname/$path" if $path;
84 $message ||= "$command $hostname $path";
85 system 'git', 'commit', '-m', $message, "$hostname/$path";
86 } elsif ( $command =~ m{(diff|status|log)} ) {
87 my $opt = '--summary' if $command eq 'log';
88 print $client `git $command $opt $hostname`;
89 } elsif ( $command eq 'revert' ) {
90 print $client `git checkout -- $hostname/$path`;
91 system 'rsync', '-avv', "$hostname/$path", "root\@$hostname:$path";
93 print $client "Unknown command: $command\n";