summaryrefslogtreecommitdiff
path: root/sysutils/flexbackup/files/patch-flexbackup
blob: c4e7cafcd09c56b663a2820a37b9b96cbd483d05 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
--- flexbackup.orig	2003-10-10 16:12:09.000000000 +0200
+++ flexbackup	2011-07-06 18:55:24.000000000 +0200
@@ -133,6 +133,9 @@
 # tar has a limit of this many chars in its volume label
 $::tar_max_label = 99;
 
+# Define the prune hash to avoid warnings with perl 5.12
+use vars qw( %prune );
+
 # Get commandline flags
 %::opt = ();
 if (! &::GetOptions(\%::opt,
@@ -269,6 +272,7 @@
     untie(%::index);
 }
 
+system ('rm', '-rf', $cfg::tmpdir);
 exit(0);
 
 ######################################################################
@@ -441,7 +445,7 @@
 		# Get rid of trailing /
 		$dir = &nuke_trailing_slash($dir);
 
-		# If level is icremental for the set, each dir might
+		# If level is incremental for the set, each dir might
 		# have a different numeric level
 		if (!defined($::set_incremental)) {
 		    $level = $::level;
@@ -687,6 +691,8 @@
 		$filename .= ".zip";
 	    } elsif ($cfg::compress eq "compress") {
 		$filename .= ".Z";
+	    } elsif ($cfg::compress eq "lzma") {
+		$filename .= ".lzma";
 	    }
 	} elsif ($cfg::type eq "afio") {
 	    # tag these a little different, the archive file itself isn't a
@@ -701,6 +707,8 @@
 		$filename .= "-zip";
 	    } elsif ($cfg::compress eq "compress") {
 		$filename .= "-Z";
+	    } elsif ($cfg::compress eq "lzma") {
+		$filename .= "-lzma";
 	    }
 	}
 
@@ -811,6 +819,11 @@
 	($remove, @cmds) = &backup_filelist($label, $localdir, $title, $level, $remote);
     }
 
+	if(defined($remote)) {
+		# create our temporary directory as first remote command
+		unshift(@cmds, &maybe_remote_cmd("$::path{mkdir} -p $cfg::tmpdir", $remote));
+	}
+
     # Nuke any tmp files used in the above routines
     if ($remove ne '') {
 	push(@cmds, &maybe_remote_cmd("$::path{rm} -f $remove", $remote));
@@ -827,6 +840,11 @@
 	    push(@cmds, &maybe_remote_cmd("$::path{rm} -f $pkglist", $remote));
 	}
     }
+	
+	if(defined($remote)) {
+		# remove temporary directory as our last remote command
+		push(@cmds, &maybe_remote_cmd("$::path{rm} -rf $cfg::tmpdir", $remote));
+	}
 
     # Strip multiple spaces
     foreach my $cmd (@cmds) {
@@ -1035,7 +1053,7 @@
     } else {
 	$prunekey = $dir;
     }
-    if (defined(%{$::prune{$prunekey}})) {
+    if (defined($prune{$prunekey})) {
 	&log("| NOTE: \$prune is ignored for type=dump");
     }
 
@@ -1140,7 +1158,7 @@
     $cmd .= "$::path{afio} -o ";
     $cmd .= "$no_compress ";
     $cmd .= "-z ";
-    $cmd .= "-1 m ";
+    $cmd .= "-1 mC ";
     $cmd .= "$::afio_z_flag ";
     $cmd .= "$::afio_verb_flag ";
     $cmd .= "$::afio_sparse_flag ";
@@ -1286,8 +1304,8 @@
 	$cmd .= "$::unz";
     }
     $cmd .= "(";
-    $cmd .= "mkdir -p $::device ; ";
-    $cmd .= "cd $::device ; ";
+    $cmd .= "mkdir -p \"$::device\" ; ";
+    $cmd .= "cd \"$::device\" ; ";
     $cmd .= "$::path{cpio} -i ";
     $cmd .= "-m ";
     $cmd .= "-d ";
@@ -1336,9 +1354,8 @@
 
     # Have to take leading './' off to make rsync's include/exclude work right
     $cmd .= " | $::path{sed} -e \"s/\\.\\///g\" | ";
-
     $cmd .= "$::path{rsync} ";
-    $cmd .= "--include-from=- --exclude=* ";
+    $cmd .= "--files-from=- ";
     $cmd .= "--archive ";
     $cmd .= "$::rsync_verb_flag ";
     $cmd .= "--delete --delete-excluded ";
@@ -1353,7 +1370,7 @@
 	    $cmd .= "$remote:";
 	}
     }
-    $cmd .= "$dir/ $::device";
+    $cmd .= "\"$dir/\" \"$::device\"";
 
     push(@cmds, $cmd);
 
@@ -1643,7 +1660,9 @@
     my $tmpfile = "$cfg::tmpdir/ar.$PROCESS_ID";
     my $remove = '';
 
-    &log("| NOTE: ar archives will not descend directories");
+    &log("| NOTE: ar archives will not recurse into subdirectories,");
+    &log("|       which makes them inappropriate for most backups.");
+    &log("|       Be sure this is what you want.");
 
     if (defined($remote) and ($level != 0)) {
 	my $time = &get_last_date($label, $level, 'numeric');
@@ -1667,11 +1686,13 @@
     $cmd = "cd \"$dir\" && ";
     $cmd .= &file_list_cmd( $dir, $stamp, 'newline', $level, $remote, '-maxdepth 1 ! -type d');
     $cmd .= "> $filelist; ";
+    # Escape any spaces in filenames. 
+    $cmd .= "$::path{sed} -i -e 's/ /\\\\ /g' $filelist; ";
 
     $cmd .= "$::path{ar} rc";
     $cmd .= "$::ar_verb_flag ";
     $cmd .= "$tmpfile ";
-    $cmd .= "`$::path{cat} $filelist`";
+    $cmd .= "\@$filelist ";
     $cmd .= "; $::path{cat} $tmpfile $::z";
 
     # Buffer both sides if remote
@@ -1785,12 +1806,9 @@
 
     $cmd = "cd \"$dir\" && ";
     $cmd .= &file_list_cmd( $dir, $stamp, 'newline', $level, $remote);
-    $cmd .= "> $filelist; ";
-
-    $cmd .= "$::path{lha} a";
+    $cmd .= " | $::path{lha} a";
     $cmd .= "$::lha_verb_flag ";
     $cmd .= "$tmpfile ";
-    $cmd .= "`$::path{cat} $filelist`";
     $cmd .= "; $::path{cat} $tmpfile $::z";
 
     # Buffer both sides if remote
@@ -2700,7 +2718,7 @@
     # First check if things are defined in the config file
     # Checks exist, true/false, or one of options
     &checkvar(\$cfg::type,'type','dump afio cpio tar star pax zip ar shar lha copy rsync filelist','tar');
-    &checkvar(\$cfg::compress,'compress','gzip bzip2 lzop compress zip false hardware','gzip');
+    &checkvar(\$cfg::compress,'compress','gzip bzip2 lzop compress zip false hardware lzma','gzip');
     &checkvar(\$cfg::compr_level,'compr_level','exist','4');
     &checkvar(\$cfg::verbose,'verbose','bool','true');
     &checkvar(\$cfg::sparse,'sparse','bool','true');
@@ -2750,8 +2768,10 @@
     $::path{'find'} = &checkinpath('find');
     $::path{'dd'} = &checkinpath('dd');
     $::path{'printf'} = &checkinpath('printf');
+    $::path{'mkdir'} = &checkinpath('mkdir');
+	$::path{'sed'} = &checkinpath('sed');
 
-    push(@::remoteprogs,($::path{'touch'},$::path{'rm'},$::path{'find'},$::path{'printf'}));
+    push(@::remoteprogs,($::path{'touch'},$::path{'rm'},$::path{'find'},$::path{'printf'},$::path{'mkdir'}));
 
     # Check device (or dir)
     $::ftape = 0;
@@ -3001,6 +3021,16 @@
 	    $::z = " | $::path{zip} -$cfg::compr_level - -";
 	    $::unz = "$::path{funzip} | ";
 	}
+    } elsif ($cfg::compress eq "lzma") {
+	$::path{'lzma'} = &checkinpath($cfg::compress);
+	push(@::remoteprogs, $::path{$cfg::compress});
+	if ($cfg::compr_level !~ m/^[123456789]$/) {
+	    push(@::errors,"\$compr_level must be set to 1-9");
+	} else {
+	    $::z = " | $::path{$cfg::compress} -$cfg::compr_level ";
+	}
+	$::unz = "$::path{$cfg::compress} -d | ";
+
     } else {
 	$::z = "";
 	$::unz = "";
@@ -3059,12 +3089,11 @@
 	    $::read_cmd = "$bufcmd $read_flags";
 
 	} elsif ($cfg::buffer eq "mbuffer") {
-
 	    $::path{'mbuffer'} = &checkinpath('mbuffer');
 	    push(@::remoteprogs, $::path{'mbuffer'});
 
 	    my $megs = $cfg::buffer_megs . "M";
-	    my $bufcmd = "$::path{mbuffer} -q -m $megs -p $cfg::buffer_fill_pct $mbuffer_blk_flag ";
+		my $bufcmd  = "$::path{mbuffer} -q -m $megs -P $cfg::buffer_fill_pct $mbuffer_blk_flag ";
 
 	    $::buffer_cmd = " | $bufcmd";
 	    $::write_cmd = "$bufcmd -f -o ";
@@ -3075,7 +3104,6 @@
 	    }
 	}
     } else {
-
 	# If buffering disabled, use dd or cat depending on if blocking turned off on not
 	if ($cfg::blksize eq '0') {
 	    $::buffer_cmd = "";
@@ -3252,6 +3280,10 @@
 		$::afio_z_flag = "-P $::path{$cfg::compress} -Q -c -Z";
 		$::afio_unz_flag = "-P $::path{$cfg::compress} -Q -d -Q -c -Z";
 
+	    } elsif ($cfg::compress eq "lzma") {
+		$::afio_z_flag = "-P $::path{$cfg::compress} -Q -$cfg::compr_level -Z";
+		$::afio_unz_flag = "-P $::path{$cfg::compress} -Q -d -Z";
+
 	    }
 	    $::unz = ""; # Reset & just use this for reading the archive file.
 
@@ -3415,7 +3447,7 @@
 	$::path{'lha'} = &checkinpath('lha');
 	push(@::remoteprogs, $::path{'lha'});
 
-	if ($cfg::compress =~ /^(gzip|bzip2|lzop|compress|zip)$/) {
+	if ($cfg::compress =~ /^(gzip|bzip2|lzop|compress|zip|lzma)$/) {
 	    warn("Using type \"lha\" with compress=$cfg::compress makes no sense");
 	    warn("Setting compression to false");
 	    $::unz = "";
@@ -3442,6 +3474,15 @@
 	push(@::errors,"\$tmpdir $cfg::tmpdir is not writable");
     }
 
+	$cfg::hostname = `hostname`;
+	chomp($cfg::hostname);
+
+	# Use a subdirectory of the user-specified directory as our tmpdir
+	# Also note that we make it closer to globally unique as we sometimes
+	# use this variable for remote systems, so PID isn't enough
+    $cfg::tmpdir = $cfg::tmpdir .'/flexbackup.'.$$.'.'.$cfg::hostname;
+    mkdir ($cfg::tmpdir) || die "Can't create temporary directory, $!";
+
     # Levels
     if (defined($::opt{'level'}) and
 	(defined($::opt{'incremental'}) or
@@ -3781,7 +3822,7 @@
 
     # Try and guess file types and commpression scheme
     # might as well since we are reading from a file in this case
-    if ($file =~ m/\.(dump|cpio|tar|star|pax|a|shar|filelist)\.(gz|bz2|lzo|Z|zip)$/) {
+    if ($file =~ m/\.(dump|cpio|tar|star|pax|a|shar|filelist)\.(gz|bz2|lzo|Z|zip|lzma)$/) {
 	$cfg::type = $1;
 	$cfg::compress = $2;
 	$cfg::type =~ s/^a$/ar/;
@@ -3789,16 +3830,18 @@
 	$cfg::compress =~ s/bz2/bzip2/;
 	$cfg::compress =~ s/lzo/lzop/;
 	$cfg::compress =~ s/Z/compress/;
+	$cfg::compress =~ s/lzma/lzma/;
 	&log("| Auto-set to type=$cfg::type compress=$cfg::compress");
 	&optioncheck();                  # redo to set a few variables over
 
-    } elsif ($file =~ m/\.afio-(gz|bz2|lzo|Z|zip)$/) {
+    } elsif ($file =~ m/\.afio-(gz|bz2|lzo|Z|zip|lzma)$/) {
 	$cfg::type = "afio";
 	$cfg::compress = $1;
 	$cfg::compress =~ s/gz/gzip/;
 	$cfg::compress =~ s/bz2/bzip2/;
 	$cfg::compress =~ s/lzo/lzop/;
 	$cfg::compress =~ s/Z/compress/;
+	$cfg::compress =~ s/lzma/lzma/;
 	&log("| Auto-set to type=$cfg::type compress=$cfg::compress");
 	&optioncheck();                  # redo to set a few variables over
 
@@ -4841,25 +4884,32 @@
     } else {
 	$prunekey = $dir;
     }
-
-    if (defined(%{$::prune{$prunekey}})) {
+    if (defined($prune{$prunekey})) {
+		my $rex;
 	# FreeBSD needs -E (above) and no backslashes around the (|) chars
 	if ($::uname =~ /FreeBSD/) {
-	    $cmd .= '-regex "\./(';
-	    $cmd .= join('|', keys %{$::prune{$prunekey}});
-	    $cmd .= ')/.*" ';
-	} else {
-	    $cmd .= '-regex "\./\(';
-	    $cmd .= join('\|', keys %{$::prune{$prunekey}});
-	    $cmd .= '\)/.*" ';
-	}
-	$cmd .= '-prune -o ';
+			$rex  = '"\./(';
+			$rex .= join('|', keys %{$::prune{$prunekey}});
+			$rex .= ')"';
+		} else {
+			$rex  = '"\./\(';
+			$rex .= join('\|', keys %{$::prune{$prunekey}});
+			$rex .= '\)"';
+		}
+		# Show what the darn thing is constructing for prune expressions.
+        (my $temp = $rex) =~ s/\\([()|])/$1/g;
+		&log("| \"find\" regex for pruning (shell escaping omitted for clarity) is:");
+		&log("|     $temp");
+		$cmd .= '-regex ' . $rex . ' -prune -o ';
     } else {
+		# Show what the darn thing is constructing for prune expressions.
+		&log("| No pruning defined for this tree.");
 	# Can't use find -depth with -prune (see single unix spec etc)
 	# (not toally required anyway, only if you are archiving dirs you
 	# don't have permissions on and are running as non-root)
 	$cmd .= "-depth ";
     }
+    &line();
 
     $cmd .= "$::mountpoint_flag ";
     $cmd .= "! -type s ";
@@ -5229,6 +5279,7 @@
     my $tmp_script = "$cfg::tmpdir/buftest.$host.$PROCESS_ID.sh";
     my $retval = 0;
     my $pipecmd;
+	my $explicit_success;
 
     $buffer_cmd =~ s:^\s*\|\s*::;
     $buffer_cmd =~ s:\s*\|\s*$::;
@@ -5236,14 +5287,14 @@
     # Create a script which tests the buffer program
     open(SCR,"> $tmp_script") || die;
     print SCR "#!/bin/sh\n";
-    print SCR "tmp_data=/tmp/bufftest\$\$.txt\n";
-    print SCR "tmp_err=/tmp/bufftest\$\$.err\n";
+    print SCR "tmp_data=\$(mktemp $cfg::tmpdir/data.XXXXXXXXXX)\n";
+    print SCR "tmp_err=\$(mktemp $cfg::tmpdir/err.XXXXXXXXXX)\n";
     print SCR "echo testme > \$tmp_data\n";
     print SCR "$buffer_cmd > /dev/null 2> \$tmp_err < \$tmp_data\n";
     print SCR "res=\$?\n";
     print SCR "out=\`cat \$tmp_err\`\n";
     print SCR "if [ \$res -eq 0 ]; then\n";
-    print SCR "   echo successful\n";
+    print SCR "    echo \"successful\"\n";
     print SCR "else\n";
     print SCR "   echo \"unsuccessful: exit code \$res: \$out\" \n";
     print SCR "fi\n";
@@ -5254,14 +5305,22 @@
 	print $::msg "| Checking '$cfg::buffer' on this machine... ";
 	$pipecmd = "sh $tmp_script ";
     } else {
+	$pipecmd = 
+        "$::remoteshell $host '$::path{mkdir} -p $cfg::tmpdir'; " .
+        "cat $tmp_script | ($::remoteshell $host 'cat > $tmp_script; " .
+        "sh $tmp_script; rm -rf $cfg::tmpdir')";
 	print $::msg "| Checking '$cfg::buffer' on host $host... ";
-	$pipecmd =  "cat $tmp_script | ($::remoteshell $host 'cat > $tmp_script; sh $tmp_script; rm -f $tmp_script')";
     }
 
     if (!defined($::debug)) {
-
 	open(PIPE,"$pipecmd |") || die;
+
+	$explicit_success = 0;
 	while (<PIPE>) {
+		if (/^successful$/) {
+			$explicit_success = 1;
+			last;
+		}
 	    if (/^unsuccessful: exit code (\d+): (.*)/) {
 		$retval = $1;
 		my $out = $2;
@@ -5290,11 +5349,15 @@
 	print $::msg "\n(debug) $pipecmd\n";
     }
 
-    if ($retval == 0) {
+	if ($explicit_success) {
 	print $::msg "Ok\n";
     }  else {
+		if ($retval == 0) {
+		    push(@::errors, "Unanticipated problems encountered testing '$cfg::buffer' on host '$host'.");
+		}  else {
 	print $::msg "Failed!\n";
     }
+	}
     unlink("$tmp_script");
 
     return($retval);
@@ -5396,10 +5459,10 @@
 	    my $shell = $1;
 	    my $ver = $2;
 	    if ($shell eq 'bash') {
-		if ($ver =~ m/^2/) {
-		    $::shelltype{$host} = 'bash2';
-		} else {
+		if ($ver =~ m/^1/) {
 		    $::shelltype{$host} = 'bash1';
+		} else {
+		    $::shelltype{$host} = 'bash2';
 		}
 	    } else {
 		$::shelltype{$host} = $shell;
@@ -5686,3 +5749,5 @@
 
     return($spinner[$index]);
 }
+
+