summaryrefslogtreecommitdiffstats
path: root/system/flexbackup/flexbackup-debian.patch
blob: 4e205efb566d39df4bba07def8a28ce7ddf2a833 (plain)
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
--- flexbackup	2003-10-11 03:12:09.000000000 +1300
+++ ../flexbackup-debian	2022-03-06 14:08:05.918918275 +1300
@@ -269,6 +269,7 @@
     untie(%::index);
 }
 
+system ('rm', '-rf', $cfg::tmpdir);
 exit(0);
 
 ######################################################################
@@ -687,6 +688,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 +704,8 @@
 		$filename .= "-zip";
 	    } elsif ($cfg::compress eq "compress") {
 		$filename .= "-Z";
+	    } elsif ($cfg::compress eq "lzma") {
+		$filename .= "-lzma";
 	    }
 	}
 
@@ -811,6 +816,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 +837,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 +1050,7 @@
     } else {
 	$prunekey = $dir;
     }
-    if (defined(%{$::prune{$prunekey}})) {
+    if ($::prune{$prunekey}) {
 	&log("| NOTE: \$prune is ignored for type=dump");
     }
 
@@ -1057,7 +1072,7 @@
     }
 
     $cmd = '';
-    $cmd .= "dump -$level ";
+    $cmd .= "$::path{dump} -$level ";
     $cmd .= "$::dump_blk_flag ";
     if ($cfg::dump_use_dumpdates eq "true") {
 	$cmd .= "-u ";
@@ -1117,7 +1132,7 @@
     if (($cfg::compress !~ /^(false|hardware)$/) and ($cfg::afio_nocompress_types ne "")) {
 	$cmd = "$::path{printf} \"$cfg::afio_nocompress_types\" > $tmpnocompress";
 	push(@cmds, &maybe_remote_cmd($cmd, $remote));
-	$no_compress = "-E $tmpnocompress";
+	$no_compress = "-E +$tmpnocompress";
 	$remove .= " $tmpnocompress";
     }
 
@@ -1140,7 +1155,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 ";
@@ -1390,11 +1405,11 @@
     $cmd .= "| ";
 
     $cmd .= "$::path{tar} --create ";
+    $cmd .= "--no-recursion ";
     $cmd .= "--null ";
     $cmd .= "--files-from=- ";
     $cmd .= "--ignore-failed-read ";
     $cmd .= "--same-permissions ";
-    $cmd .= "--no-recursion ";
     $cmd .= "--totals ";
     if ($cfg::label ne 'false') {
 	if (length($title) > $::tar_max_label) {
@@ -2670,7 +2685,7 @@
     }
 
     # Flag old config file
-    if (defined(@cfg::filesystems) or defined($cfg::mt_var_blksize)) {
+    if (@cfg::filesystems or defined($cfg::mt_var_blksize)) {
 	# so strict shuts up
 	my $junk = @cfg::filesystems;
 	$junk = $cfg::mt_var_blksize;
@@ -2700,7 +2715,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 +2765,9 @@
     $::path{'find'} = &checkinpath('find');
     $::path{'dd'} = &checkinpath('dd');
     $::path{'printf'} = &checkinpath('printf');
+    $::path{'mkdir'} = &checkinpath('mkdir');
 
-    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;
@@ -2890,11 +2906,11 @@
     # Traverse mountpoints?
     &checkvar(\$cfg::traverse_fs,'traverse_fs','false local all','false');
     if ($cfg::traverse_fs eq "local") {
-	$::mountpoint_flag = "! -fstype nfs ! -fstype smbfs ! -fstype bind ! -fstype proc ! -fstype devpts ! -fstype devfs ! -fstype tmpfs";
+	$::late_mountpoint_flag = "! -fstype nfs ! -fstype smbfs ! -fstype bind ! -fstype proc ! -fstype devpts ! -fstype devfs ! -fstype tmpfs";
     } elsif ($cfg::traverse_fs eq "all") {
-	$::mountpoint_flag = "! -fstype proc ! -fstype devpts ! -fstype devfs ! -fstype tmpfs";
+	$::late_mountpoint_flag = "! -fstype proc ! -fstype devpts ! -fstype devfs ! -fstype tmpfs";
     } else {
-	$::mountpoint_flag = "-xdev";
+	$::early_mountpoint_flag = "-xdev";
     }
 
     # Block size
@@ -3001,6 +3017,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 = "";
@@ -3224,7 +3250,7 @@
 	&checkvar(\$cfg::afio_echo_block,'afio_echo_block','bool','false');
 	&checkvar(\$cfg::afio_compress_cache_size,'afio_compress_cache_size','exist','2');
 	&checkvar(\$cfg::afio_compress_threshold,'afio_compress_threshold','exist','3');
-	&checkvar(\$cfg::afio_nocompress_types,'afio_nocompress_types','exist','mp3 MP3 Z z gz gif zip ZIP lha jpeg jpg JPG taz tgz deb rpm bz2 lzo');
+	&checkvar(\$cfg::afio_nocompress_types,'afio_nocompress_types','exist','.lzo');
 
 	$::path{'afio'} = &checkinpath('afio');
 	push(@::remoteprogs, $::path{'afio'});
@@ -3252,6 +3278,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 +3445,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 +3472,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 +3820,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 +3828,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
 
@@ -4842,7 +4883,11 @@
 	$prunekey = $dir;
     }
 
-    if (defined(%{$::prune{$prunekey}})) {
+    if (defined($::early_mountpoint_flag)) {
+	$cmd .= "$::early_mountpoint_flag ";
+    }
+
+    if ($::prune{$prunekey}) {
 	# FreeBSD needs -E (above) and no backslashes around the (|) chars
 	if ($::uname =~ /FreeBSD/) {
 	    $cmd .= '-regex "\./(';
@@ -4861,7 +4906,9 @@
 	$cmd .= "-depth ";
     }
 
-    $cmd .= "$::mountpoint_flag ";
+    if (defined($::late_mountpoint_flag)) {
+	$cmd .= "$::late_mountpoint_flag ";
+    }
     $cmd .= "! -type s ";
 
     if (defined($otherarg)) {
@@ -5236,8 +5283,8 @@
     # 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=$cfg::tmpdir/buftest.$host.$$.txt\n";
+    print SCR "tmp_err=$cfg::tmpdir/buftest.$host.$$.err\n";
     print SCR "echo testme > \$tmp_data\n";
     print SCR "$buffer_cmd > /dev/null 2> \$tmp_err < \$tmp_data\n";
     print SCR "res=\$?\n";
@@ -5255,7 +5302,8 @@
 	$pipecmd = "sh $tmp_script ";
     } else {
 	print $::msg "| Checking '$cfg::buffer' on host $host... ";
-	$pipecmd =  "cat $tmp_script | ($::remoteshell $host 'cat > $tmp_script; sh $tmp_script; rm -f $tmp_script')";
+	$pipecmd =  "cat $tmp_script | ($::remoteshell $host 'mkdir -p $cfg::tmpdir;
+ 		     cat - > $tmp_script; sh $tmp_script; rm -rf $cfg::tmpdir')";
     }
 
     if (!defined($::debug)) {
@@ -5287,6 +5335,8 @@
 	close (PIPE);
 
     } else {
+	print $::msg "\n(debug) 'buffer' test script:\n($tmp_script)\n\n"
+	      . `cat $tmp_script`;
 	print $::msg "\n(debug) $pipecmd\n";
     }