remove old tmp files
authorHeiko Schlittermann (CTQ) <hs@schlittermann.de>
Mon, 01 Aug 2011 15:52:37 +0200
changeset 123 0c6e454093df
parent 122 51a8543685bb
child 124 6c90a6e8646c
child 128 2e8c48130af7
remove old tmp files
bin/ftbackup
--- a/bin/ftbackup	Mon Aug 01 15:40:43 2011 +0200
+++ b/bin/ftbackup	Mon Aug 01 15:52:37 2011 +0200
@@ -206,6 +206,7 @@
             # FIXME: currently we simply run a full dump every FULL_CYCLE
             # days, the intermediate dumps are level 1
             foreach (reverse sort $ftp->ls) {
+		next if /\.tmp-\d+$/;
                 next if not /^(?<date>.*)\.(?<level>\d+)$/;
 		next if not $ftp->size(0) and str2time($+{date}) < $^T;
                 $last[$+{level}] = str2time $+{date};
@@ -323,7 +324,7 @@
 
         if ($ftp) {
             verbose("sending dump to " . $ftp->pwd . "/$file.tmp-$^T\n");
-            $ftp->try(put => $dump, $file);
+            $ftp->try(put => $dump, "$file.tmp-$^T");
 	    $ftp->try(rename => "$file.tmp-$^T", $file);
         }
         else {
@@ -642,6 +643,11 @@
     my @dumps;
 
     foreach ($ftp->ls) {
+	if (/\.tmp-(?<timestamp>\d+)$/ and $+{timestamp} < $^T) {
+	    INFO "removing old tmp file $_";
+	    $ftp->delete($_);
+	    next;
+	};
         /^(?<date>.*)\.(?<level>\d+)$/ or next;
 	if (not $ftp->size($_) and str2time($+{date}) < $^T) {
 	    INFO "removing old zero size backup $_";