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;
66 $path = "$pwd/$path" unless $path =~ m{^/};
68 warn "$ip [$command] $path | $message\n";
71 system 'ssh-copy-id', "root\@$ip";
78 mkpath "$ip/$dir" unless -e "$ip/$dir";
81 system "find $ip -type f | sed 's,$ip,,' > /tmp/$ip.list";
82 system "rsync -avv --files-from /tmp/$ip.list root\@$ip:/ $ip/"
83 } elsif ( $command eq 'add' ) {
84 system 'rsync', '-avv', "root\@$ip:$path", "$ip/$path";
85 system 'git', 'add', "$ip/$path";
86 } elsif ( $command eq 'commit' ) {
87 system 'rsync', '-avv', "root\@$ip:$path", "$ip/$path";
88 $message ||= "$command $ip $path";
89 system 'git', 'commit', '-m', $message, "$ip/$path";
90 } elsif ( $command =~ m{(diff|status|log)} ) {
91 print $client `git $command $ip`;
93 print $client "Unknown command: $command\n";