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 `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 ($pwd,$command,$path,$message) = split(/\s+/,<$client>,4);
56 my $ip = $client->peerhost;
58 if ( $pwd eq 'install' ) {
59 warn "install on $ip\n";
60 print $client $shell_client;
62 system 'ssh-copy-id', "root\@$ip" if ! -d $ip;
67 $path = "$pwd/$path" unless $path =~ m{^/};
69 warn "$ip [$command] $path | $message\n";
75 mkpath "$ip/$dir" unless -e "$ip/$dir";
78 system "find $ip -type f | sed 's,$ip,,' > /tmp/$ip.list";
79 system "rsync -avv --files-from /tmp/$ip.list root\@$ip:/ $ip/"
80 } elsif ( $command eq 'add' ) {
81 system 'rsync', '-avv', "root\@$ip:$path", "$ip/$path";
82 system 'git', 'add', "$ip/$path";
83 } elsif ( $command eq 'commit' ) {
84 system 'rsync', '-avv', "root\@$ip:$path", "$ip/$path" if $path;
85 $message ||= "$command $ip $path";
86 system 'git', 'commit', '-m', $message, "$ip/$path";
87 } elsif ( $command =~ m{(diff|status|log)} ) {
88 my $opt = '--summary' if $command eq 'log';
89 print $client `git $command $opt $ip`;
90 } elsif ( $command eq 'revert' ) {
91 print $client `git checkout -- $ip/$path`;
92 system 'rsync', '-avv', "$ip/$path", "root\@$ip:$path";
94 print $client "Unknown command: $command\n";