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 10.60.0.92 9001 > bak ; chmod 755 bak
20 my $dir = shift @ARGV || die "usage: $0 /backup/directory\n";
23 system 'git init' unless -e '.git';
25 my $server = IO::Socket::INET->new(
32 while (my $client = $server->accept()) {
33 my ($pwd,$command,$path,$message) = split(/\s+/,<$client>,4);
34 my $ip = $client->peerhost;
37 $path = "$pwd/$path" unless $path =~ m{^/};
39 if ( $command eq 'install' ) {
40 print $client '#!/bin/sh',$/,'echo `pwd` $* | nc 10.60.0.92 9001',$/;
44 warn "$ip [$command] $path | $message\n";
47 system 'ssh-copy-id', "root\@$ip";
54 mkpath "$ip/$dir" unless -e "$ip/$dir";
57 system "find $ip -type f | sed 's,$ip,,' > /tmp/$ip.list";
58 system "rsync -avv --files-from /tmp/$ip.list root\@$ip:/ $ip/"
59 } elsif ( $command eq 'add' ) {
60 system 'rsync', '-avv', "root\@$ip:$path", "$ip/$path";
61 system 'git', 'add', "$ip/$path";
62 } elsif ( $command eq 'commit' ) {
63 system 'rsync', '-avv', "root\@$ip:$path", "$ip/$path";
64 $message ||= "$command $ip $path";
65 system 'git', 'commit', '-m', $message, "$ip/$path";
66 } elsif ( $command =~ m{(diff|status|log)} ) {
67 print $client `git $command $ip`;
69 print $client "Unknown command: $command\n";