auto extracter should now work
authorHeiko Schlittermann (ZARAFA.ctq.de) hs@schlittermann.de
Thu, 28 Apr 2011 17:13:30 +0200
changeset 54 628fe317b2c1
parent 53 1e29d8bd4ae2
child 55 72d1cbf6a26f
child 60 ab452b13bab6
auto extracter should now work
bin/ftbackup
--- a/bin/ftbackup	Thu Apr 28 12:48:05 2011 +0200
+++ b/bin/ftbackup	Thu Apr 28 17:13:30 2011 +0200
@@ -248,7 +248,7 @@
         $ENV{key} = $cf{KEY};
         my $dumper = open(my $dump, "-|") or do {
             print <<__HEAD;
-#! /bin/bash
+#! /bin/sh
 LC_ALL=C
 if test -t 1; then
     cat <<___
@@ -262,19 +262,28 @@
 DEVICE_NO  : $dev->{devno}
 
 # For recovery pass everything following the first
-# ^### START to "recover -rf -". Or do one of the following
+# ^#-- START to "recover -rf -". Or do one of the following
 # lines:
-#   sh <THIS SCRIPT> | restore -rf -
-#   sh <(ftpipe <URL>) -pass file:/dev/tty | restore -rf -
+#   sh <THIS SCRIPT>   | restore -rf -
+#   ftpipe <URL> | sh  | restore -rf -
+#   sh <(ftpipe <URL>) | restore -rf -
+#
+# The tool "ftpipe" can be found at https://keller.schlittermann.de/hg/beta/ftpipe
+# or there about.
 ___
     exit 0
 fi
+
+if test -t 0; then input="\$0"
+else input="/dev/fd/0"
+fi
+
 while read; do
-    test "\$REPLY" = "### START" \\
+    test "\$REPLY" = "#-- START" \\
 	&& exec openssl enc -d -blowfish "\$@"
-done <"\$0"
-
-### START
+done <\$input
+exit
+#-- START
 __HEAD
 
 
@@ -287,6 +296,7 @@
         };
 
         if ($ftp) {
+	    verbose("sending dump to " . $ftp->pwd . "/$file\n");
             $ftp->try(put => $dump, $file);
         }
         else {
@@ -426,12 +436,11 @@
 
 sub update_devnames($$$) {
 	my ($file, $from, $to) = @_;
-	open(my $f, "+>>", $file) or die "Can't open $file: $!\n";
+	open(my $f, "+>>" => $file) or die "Can't open $file: $!\n";
 	seek($f, 0, 0);
 	my $_ = join "", <$f>;
 	s/^$from\s/$to /mg;
 	truncate($f, 0);
-	# fix the dumpdates
 	print $f $_;		
 	close($f);
 }
@@ -559,14 +568,15 @@
 	push @{$dumps[$+{level}]} => { file => $_, date => $+{date}, stamp => str2time($+{date})};
     }
 
-    ### @dumps
 
     # sort the level 0 dumps by date and remove all but the last $keep
     # ones.
     # if we found level 0 dumps, we remove all level 1+ dumps older than
     # the oldest level 0 dump we'll remove
     @{$dumps[0]} = sort { $a->{stamp} <=> $b->{stamp} } @{$dumps[0]};
-    my @unlink = splice(@{$dumps[0]}, -1, @{$dumps[0]} - $keep);
+
+    ### @dumps
+    my @unlink = splice(@{$dumps[0]}, 0, -$keep);
 
     if ($dumps[1]) {
 	if (!@{$dumps[0]}) { push @unlink, @{@dumps[1..$#dumps]} }