This repository has been archived by the owner on May 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
/
pve-5.1-48-diff-backup-addon
executable file
·530 lines (481 loc) · 19.4 KB
/
pve-5.1-48-diff-backup-addon
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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
#!/bin/bash
echo "Proxmox VE 5.1 - differential backup support, v3"
echo "Kamil Trzcinski, http://ayufan.eu/, [email protected]"
echo ""
function pve_manager_patch() {
cat <<"EOF"
diff --git a/js/pvemanagerlib.js b/js/pvemanagerlib.js
index 7a92574..d2bca5b 100644
--- a/js/pvemanagerlib.js
+++ b/js/pvemanagerlib.js
@@ -29885,6 +34015,25 @@ Ext.define('PVE.dc.BackupEdit', {
name: 'mode'
},
{
+ xtype: 'numberfield',
+ fieldLabel: gettext('Max Backups'),
+ name: 'maxfiles',
+ minValue: 0,
+ maxValue: 365,
+ value: me.create ? '1' : undefined,
+ allowBlank: false
+ },
+ {
+ xtype: 'numberfield',
+ fieldLabel: gettext('Full Backup Every'),
+ name: 'fullbackup',
+ emptyText : gettext('Days'),
+ minValue: 0,
+ maxValue: 60,
+ value: me.create ? '0' : undefined,
+ allowBlank: true
+ },
+ {
xtype: 'proxmoxcheckbox',
fieldLabel: gettext('Enable'),
name: 'enabled',
EOF
}
function pve_perl_patch() {
cat <<"EOF"
commit db024dafec523ff9d3ed9dc99e6cffa8f054766f
Author: Kamil Trzciński <[email protected]>
Date: Tue Apr 3 22:46:53 2018 +0200
pve differential backups 5.1-48
diff --git a/LXC/Create.pm b/LXC/Create.pm
index cf73dba..03fe8e1 100644
--- a/LXC/Create.pm
+++ b/LXC/Create.pm
@@ -75,7 +75,7 @@ sub restore_archive {
'.xz' => '-J',
'.lzo' => '--lzop',
);
- if ($archive =~ /\.tar(\.[^.]+)?$/) {
+ if ($archive =~ /\.tar(\.[^.]+)?(--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo))?)?$/) {
if (defined($1)) {
@compression_opt = $compression_map{$1}
or die "unrecognized compression format: $1\n";
@@ -106,6 +106,14 @@ sub restore_archive {
$cmd = [ ['cstream', '-t', $bwlimit*1024], $cmd ];
}
+ if (my $fullbackup = PVE::Storage::get_full_backup($archive)) {
+ print "extracting from differential archive, using full backup '$fullbackup'\n";
+ $cmd = [
+ [ "pve-xdelta3", "-q", "-d", "-c", "-R", "-s", $fullbackup, $archive ],
+ [ @$userns_cmd, 'tar', 'xpf', '-', '--numeric-owner', '--totals', '--sparse', '-C', $rootdir, '--skip-old-files', '--anchored', '--exclude' , './dev/*' ]
+ ];
+ }
+
if ($archive eq '-') {
print "extracting archive from STDIN\n";
} else {
diff --git a/QemuServer.pm b/QemuServer.pm
index 6c457e5..64abfc8 100644
--- a/QemuServer.pm
+++ b/QemuServer.pm
@@ -5339,8 +5339,18 @@ sub tar_archive_read_firstfile {
die "ERROR: file '$archive' does not exist\n" if ! -f $archive;
+ my $cmd = undef;
+
+ if ($archive =~ m!([^/]*vzdump-([a-z]*)-(\d*)-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|(tar(\.(gz|lzo))?)))--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo))?$!) {
+ my $fullbackup = $archive;
+ $fullbackup =~ s!([^/]*vzdump-([a-z]+)-(\d+)-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|(tar(\.(gz|lzo))?)))--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo))?!$1!;
+ $cmd = "-|pve-xdelta3 -q -d -c -R -s '$fullbackup' '$archive' |tar t|";
+ } else {
+ $cmd = "-|tar tf '$archive'|";
+ }
+
# try to detect archive type first
- my $pid = open (my $fh, '-|', 'tar', 'tf', $archive) ||
+ my $pid = open (my $fh, $cmd) ||
die "unable to open file '$archive'\n";
my $firstfile = <$fh>;
kill 15, $pid;
@@ -5384,20 +5394,20 @@ sub restore_archive {
my $format = $opts->{format};
my $comp;
- if ($archive =~ m/\.tgz$/ || $archive =~ m/\.tar\.gz$/) {
+ if ($archive =~ m/\.tgz$/ || $archive =~ m/\.tar\.gz(--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo))?)?$/) {
$format = 'tar' if !$format;
$comp = 'gzip';
- } elsif ($archive =~ m/\.tar$/) {
+ } elsif ($archive =~ m/\.tar(--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo))?)?$/) {
$format = 'tar' if !$format;
- } elsif ($archive =~ m/.tar.lzo$/) {
+ } elsif ($archive =~ m/.tar.lzo(--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo))?)?$/) {
$format = 'tar' if !$format;
$comp = 'lzop';
- } elsif ($archive =~ m/\.vma$/) {
+ } elsif ($archive =~ m/\.vma(--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo))?)?$/) {
$format = 'vma' if !$format;
- } elsif ($archive =~ m/\.vma\.gz$/) {
+ } elsif ($archive =~ m/\.vma\.gz(--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo))?)?$/) {
$format = 'vma' if !$format;
$comp = 'gzip';
- } elsif ($archive =~ m/\.vma\.lzo$/) {
+ } elsif ($archive =~ m/\.vma\.lzo(--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo))?)?$/) {
$format = 'vma' if !$format;
$comp = 'lzop';
} else {
@@ -5687,6 +5697,15 @@ sub restore_vma_archive {
$add_pipe->($cmd);
}
+ if ($archive =~ m!([^/]*vzdump-([a-z]*)-(\d*)-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(vma(\.(gz|lzo))?))--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo))?$!) {
+ my $fullbackup = $archive;
+ $fullbackup =~ s!([^/]*vzdump-([a-z]+)-(\d+)-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(vma(\.(gz|lzo))?))--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo))?!$1!;
+ print "extracting from differential archive, using full backup '$fullbackup'\n";
+ $readfrom = '-';
+ my $uncomp = ["pve-xdelta3", "-q", "-d", "-c", "-R", "-s", $fullbackup, '-'];
+ $add_pipe->($uncomp);
+ }
+
my $tmpdir = "/var/tmp/vzdumptmp$$";
rmtree $tmpdir;
@@ -5971,8 +5990,17 @@ sub restore_tar_archive {
# tar option "xf" does not autodetect compression when read from STDIN,
# so we pipe to zcat
- my $cmd = "zcat -f|tar xf " . PVE::Tools::shellquote($archive) . " " .
- PVE::Tools::shellquote("--to-command=$tocmd");
+ my $cmd = undef;
+
+ if ($archive =~ m!([^/]*vzdump-([a-z]*)-(\d*)-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|(tar(\.(gz|lzo))?)))--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo))?$!) {
+ my $fullbackup = $archive;
+ $fullbackup =~ s!([^/]*vzdump-([a-z]+)-(\d+)-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|(tar(\.(gz|lzo))?)))--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo))?!$1!;
+ print "extracting from differential archive, using full backup '$fullbackup'\n";
+ $cmd = "pve-xdelta3 -q -d -c -R -s '$fullbackup' '$archive' |tar x " . PVE::Tools::shellquote("--to-command=$tocmd");
+ } else {
+ $cmd = "zcat -f|tar xf " . PVE::Tools::shellquote($archive) . " " .
+ PVE::Tools::shellquote("--to-command=$tocmd");
+ }
my $tmpdir = "/var/tmp/vzdumptmp$$";
mkpath $tmpdir;
diff --git a/Storage.pm b/Storage.pm
index 4140a99..6b1a74d 100644
--- a/Storage.pm
+++ b/Storage.pm
@@ -494,7 +494,7 @@ sub path_to_volume_id {
} elsif ($path =~ m!^$privatedir/(\d+)$!) {
my $vmid = $1;
return ('rootdir', "$sid:rootdir/$vmid");
- } elsif ($path =~ m!^$backupdir/([^/]+\.(tar|tar\.gz|tar\.lzo|tgz|vma|vma\.gz|vma\.lzo))$!) {
+ } elsif ($path =~ m!^$backupdir/([^/]+\.(tar|tar\.gz|tar\.lzo|tgz|vma|vma\.gz|vma\.lzo|vcdiff|vcdiff\.gz|vcdiff\.lzo))$!) {
my $name = $1;
return ('iso', "$sid:backup/$name");
}
@@ -780,7 +780,7 @@ sub template_list {
$info = { volid => "$sid:vztmpl/$1", format => "t$2" };
} elsif ($tt eq 'backup') {
- next if $fn !~ m!/([^/]+\.(tar|tar\.gz|tar\.lzo|tgz|vma|vma\.gz|vma\.lzo))$!;
+ next if $fn !~ m!/([^/]+\.(tar|tar\.gz|tar\.lzo|tgz|vma|vma\.gz|vma\.lzo|vcdiff|vcdiff\.gz|vcdiff\.lzo))$!;
$info = { volid => "$sid:backup/$1", format => $2 };
}
@@ -1335,13 +1335,30 @@ sub foreach_volid {
}
}
+sub get_full_backup {
+ my ($archive) = @_;
+ if ($archive =~ m!([^/]*vzdump-([a-z]*)-(\d*)-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|((tar|vma)(\.(gz|lzo))?)))--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo))?$!) {
+ my $fullbackup = $archive;
+ $fullbackup =~ s!([^/]*vzdump-([a-z]+)-(\d+)-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|((tar|vma)(\.(gz|lzo))?)))--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo))?!$1!;
+ return $fullbackup;
+ }
+ return undef;
+}
+
sub extract_vzdump_config_tar {
my ($archive, $conf_re) = @_;
die "ERROR: file '$archive' does not exist\n" if ! -f $archive;
- my $pid = open(my $fh, '-|', 'tar', 'tf', $archive) ||
- die "unable to open file '$archive'\n";
+ my $pid;
+ my $fh;
+
+ if (my $fullbackup = get_full_backup($archive)) {
+ $pid = open($fh, '-|', 'bash', '-c' , "pve-xdelta3 -q -d -c -R -s '$fullbackup' '$archive' | tar tf -")
+ || die "unable to open file '$archive'\n";
+ } else {
+ $pid = open($fh, '-|', 'tar', 'tf', $archive) || die "unable to open file '$archive'\n";
+ }
my $file;
while (defined($file = <$fh>)) {
@@ -1364,7 +1381,15 @@ sub extract_vzdump_config_tar {
$raw .= "$output\n";
};
- PVE::Tools::run_command(['tar', '-xpOf', $archive, $file, '--occurrence'], outfunc => $out);
+ my $cmd = ['tar', '-xpOf', $archive, $file, '--occurrence'];
+ if (my $fullbackup = get_full_backup($archive)) {
+ $cmd = [
+ [ "bash", "-c", "pve-xdelta3 -q -d -c -R -s '$fullbackup' '$archive' || true" ],
+ [ 'tar', '-xpOf', '-', $file, '--occurrence' ]
+ ];
+ }
+
+ PVE::Tools::run_command($cmd, outfunc => $out);
return wantarray ? ($raw, $file) : $raw;
}
@@ -1374,6 +1399,7 @@ sub extract_vzdump_config_vma {
my $cmd;
my $raw = '';
+ my $fullbackup;
my $out = sub {
my $output = shift;
$raw .= "$output\n";
@@ -1389,7 +1415,12 @@ sub extract_vzdump_config_vma {
} else {
die "unknown compression method '$comp'\n";
}
- $cmd = [$uncomp, ["vma", "config", "-"]];
+ if ($fullbackup = get_full_backup($archive)) {
+ $cmd = [["pve-xdelta3", "-q", "-d", "-c", "-R", "-s", $fullbackup, $archive],
+ ["vma", "config", "-"]];
+ } else {
+ $cmd = [$uncomp, ["vma", "config", "-"]];
+ }
# in some cases, lzop/zcat exits with 1 when its stdout pipe is
# closed early by vma, detect this and ignore the exit code later
@@ -1397,7 +1428,7 @@ sub extract_vzdump_config_vma {
my $errstring;
my $err = sub {
my $output = shift;
- if ($output =~ m/lzop: Broken pipe: <stdout>/ || $output =~ m/gzip: stdout: Broken pipe/) {
+ if ($output =~ m/lzop: Broken pipe: <stdout>/ || $output =~ m/gzip: stdout: Broken pipe/ || $output =~ m/xdelta3: write failed: \/dev\/stdout: Broken pipe/) {
$broken_pipe = 1;
} elsif (!defined ($errstring) && $output !~ m/^\s*$/) {
$errstring = "Failed to extract config from VMA archive: $output\n";
@@ -1431,9 +1462,9 @@ sub extract_vzdump_config {
my $archive = abs_filesystem_path($cfg, $volid);
- if ($volid =~ /vzdump-(lxc|openvz)-\d+-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|(tar(\.(gz|lzo))?))$/) {
+ if ($volid =~ /vzdump-(lxc|openvz)-\d+-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|(tar(\.(gz|lzo))?))(--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo))?)?$/) {
return extract_vzdump_config_tar($archive, qr!^(\./etc/vzdump/(pct|vps)\.conf)$!);
- } elsif ($volid =~ /vzdump-qemu-\d+-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|((tar|vma)(\.(gz|lzo))?))$/) {
+ } elsif ($volid =~ /vzdump-qemu-\d+-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|((tar|vma)(\.(gz|lzo))?))(--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo))?)?$/) {
my $format;
my $comp;
if ($7 eq 'tgz') {
diff --git a/Storage/Plugin.pm b/Storage/Plugin.pm
index 163871d..da6ce2d 100644
--- a/Storage/Plugin.pm
+++ b/Storage/Plugin.pm
@@ -398,7 +398,7 @@ sub parse_volname {
return ('vztmpl', $1);
} elsif ($volname =~ m!^rootdir/(\d+)$!) {
return ('rootdir', $1, $1);
- } elsif ($volname =~ m!^backup/([^/]+(\.(tar|tar\.gz|tar\.lzo|tgz|vma|vma\.gz|vma\.lzo)))$!) {
+ } elsif ($volname =~ m!^backup/([^/]+(\.(tar|tar\.gz|tar\.lzo|tgz|vma|vma\.gz|vma\.lzo|vcdiff|vcdiff\.gz|vcdiff\.lzo)))$!) {
my $fn = $1;
if ($fn =~ m/^vzdump-(openvz|lxc|qemu)-(\d+)-.+/) {
return ('backup', $fn, $2);
diff --git a/VZDump.pm b/VZDump.pm
index 3d34f9f..b57d882 100644
--- a/VZDump.pm
+++ b/VZDump.pm
@@ -8,6 +8,7 @@ use IO::File;
use IO::Select;
use IPC::Open3;
use File::Path;
+use File::Basename;
use PVE::RPCEnvironment;
use PVE::Storage;
use PVE::Cluster qw(cfs_read_file);
@@ -171,6 +172,13 @@ my $confdesc = {
minimum => 1,
default => 1,
},
+ fullbackup => {
+ type => 'integer',
+ description => "Maximal days of validity for full backups to be used for creating differentials.",
+ optional => 1,
+ minimum => 0,
+ default => 0,
+ },
remove => {
type => 'boolean',
description => "Remove old backup files if there are more than 'maxfiles' backup files.",
@@ -736,6 +744,22 @@ sub get_backup_file_list {
return $bklist;
}
+
+sub get_differential_backup_file_list {
+ my ($dir, $bkname, $exclude_fn) = @_;
+
+ my $bklist = [];
+ foreach my $fn (<$dir/${bkname}-*>) {
+ next if $exclude_fn && $fn eq $exclude_fn;
+ if ($fn =~ m!/(${bkname}--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo))?)$!) {
+ $fn = "$dir/$1"; # untaint
+ my $t = timelocal ($7, $6, $5, $4, $3 - 1, $2 - 1900);
+ push @$bklist, [$fn, $t];
+ }
+ }
+
+ return $bklist;
+}
sub exec_backup_task {
my ($self, $task) = @_;
@@ -784,13 +808,43 @@ sub exec_backup_task {
if scalar(@$bklist) >= $maxfiles;
}
- my $logfile = $task->{logfile} = "$opts->{dumpdir}/$basename.log";
+ my $ext = $vmtype eq 'qemu' ? '.vma' : '.tar';
+ my ($comp, $comp_ext) = compressor_info($opts);
+ if ($comp && $comp_ext) {
+ $ext .= ".${comp_ext}";
+ }
- my $ext = $vmtype eq 'qemu' ? '.vma' : '.tar';
- my ($comp, $comp_ext) = compressor_info($opts);
- if ($comp && $comp_ext) {
- $ext .= ".${comp_ext}";
- }
+ my $fullbackup = undef;
+ if ($opts->{fullbackup} && !$opts->{stdout}) {
+ my $bklist = get_backup_file_list($opts->{dumpdir}, $bkname);
+ $bklist = [ sort { $b->[1] <=> $a->[1] } @$bklist ];
+ my $mintime = timelocal ($lt->sec, $lt->min, $lt->hour,
+ $lt->mday, $lt->mon, $lt->year) -
+ $opts->{fullbackup} * 24 * 60 * 60 -
+ 12 * 60 * 60; # - 12h just to make sure that on last day we create full backup
+
+ foreach my $d (@$bklist) {
+ next if $mintime > $d->[1];
+
+ $fullbackup = $d->[0];
+ $basename = basename($fullbackup);
+ $basename = sprintf "${basename}--differential-%04d_%02d_%02d-%02d_%02d_%02d",
+ $lt->year + 1900, $lt->mon + 1, $lt->mday,
+ $lt->hour, $lt->min, $lt->sec;
+ $ext = ".vcdiff";
+ if ($comp && $comp_ext) {
+ $ext .= ".${comp_ext}";
+ }
+
+ debugmsg ('info', "doing differential backup against '$fullbackup'");
+ last;
+ }
+
+ debugmsg ('info', "doing full backup, because no backup found in last $opts->{fullbackup} day(s)")
+ if !$fullbackup;
+ }
+
+ my $logfile = $task->{logfile} = "$opts->{dumpdir}/$basename.log";
if ($opts->{stdout}) {
$task->{tarfile} = '-';
@@ -964,7 +1018,7 @@ sub exec_backup_task {
}
debugmsg ('info', "creating archive '$task->{tarfile}'", $logfd);
- $plugin->archive($task, $vmid, $task->{tmptar}, $comp);
+ $plugin->archive($task, $vmid, $task->{tmptar}, $comp, $fullbackup);
rename ($task->{tmptar}, $task->{tarfile}) ||
die "unable to rename '$task->{tmptar}' to '$task->{tarfile}'\n";
@@ -976,7 +1030,7 @@ sub exec_backup_task {
# purge older backup
- if ($maxfiles && $opts->{remove}) {
+ if ($maxfiles && $opts->{remove} && !$fullbackup) {
my $bklist = get_backup_file_list($opts->{dumpdir}, $bkname, $task->{tarfile});
$bklist = [ sort { $b->[1] <=> $a->[1] } @$bklist ];
@@ -987,6 +1041,16 @@ sub exec_backup_task {
my $logfn = $d->[0];
$logfn =~ s/\.(tgz|((tar|vma)(\.(gz|lzo))?))$/\.log/;
unlink $logfn;
+
+ my $dbklist = get_differential_backup_file_list($opts->{dumpdir}, basename($d->[0]));
+
+ foreach my $df (@$dbklist) {
+ debugmsg ('info', "delete old differential backup '$df->[0]'", $logfd);
+ unlink $df->[0];
+ $logfn = $df->[0];
+ $logfn =~ s/\.(vcdiff(\.(gz|lzo))?)$/\.log/;
+ unlink $logfn;
+ }
}
}
diff --git a/VZDump/LXC.pm b/VZDump/LXC.pm
index ae793dc..06a88e7 100644
--- a/VZDump/LXC.pm
+++ b/VZDump/LXC.pm
@@ -296,7 +296,7 @@ sub assemble {
}
sub archive {
- my ($self, $task, $vmid, $filename, $comp) = @_;
+ my ($self, $task, $vmid, $filename, $comp, $basefile) = @_;
my $disks = $task->{disks};
my @sources;
@@ -356,6 +356,7 @@ sub archive {
my $bwl = $opts->{bwlimit}*1024; # bandwidth limit for cstream
push @$cmd, [ 'cstream', '-t', $bwl ] if $opts->{bwlimit};
+ push @$cmd, [ 'pve-xdelta3', '-q', '-e', '-c', '-s', $basefile ] if $basefile;
push @$cmd, [ split(/\s+/, $comp) ] if $comp;
if ($opts->{stdout}) {
diff --git a/VZDump/QemuServer.pm b/VZDump/QemuServer.pm
index 42680f8..1b0677c 100644
--- a/VZDump/QemuServer.pm
+++ b/VZDump/QemuServer.pm
@@ -237,7 +237,7 @@ sub assemble {
}
sub archive {
- my ($self, $task, $vmid, $filename, $comp) = @_;
+ my ($self, $task, $vmid, $filename, $comp, $basefile) = @_;
my $conffile = "$task->{tmpdir}/qemu-server.conf";
my $firewall = "$task->{tmpdir}/qemu-server.fw";
@@ -347,6 +347,15 @@ sub archive {
die "unable to open file '$filename' - $!\n";
}
+ if ($basefile) {
+ my $basecmd = "pve-xdelta3 -e -q -c -s '$basefile'";
+ if ($comp) {
+ $comp = "$basecmd|$comp";
+ } else {
+ $comp = $basecmd;
+ }
+ }
+
my $outfileno;
if ($comp) {
my @pipefd = POSIX::pipe();
EOF
}
function patch_revert() {
patch --reverse --quiet -p1 --batch --ignore-whitespace -d $*
}
function patch_apply() {
patch --forward -p1 --batch --ignore-whitespace -d $*
}
case $1 in
revert)
if pve_manager_patch | patch_revert /usr/share/pve-manager/ --dry-run
then
pve_manager_patch | patch_revert /usr/share/pve-manager/
echo "RESTORED: /usr/share/pve-manager/"
fi
if pve_perl_patch | patch_revert /usr/share/perl5/PVE/ --dry-run
then
pve_perl_patch | patch_revert /usr/share/perl5/PVE/
echo "RESTORED: /usr/share/perl5/PVE/"
fi
echo ""
service pveproxy restart
service pvedaemon restart
;;
apply)
if pve_manager_patch | patch_apply /usr/share/pve-manager/ --dry-run --batch
then
pve_manager_patch | patch_apply /usr/share/pve-manager/
echo "PATCHED: /usr/share/pve-manager/"
fi
if pve_perl_patch | patch_apply /usr/share/perl5/PVE/ --dry-run --batch
then
pve_perl_patch | patch_apply /usr/share/perl5/PVE/
echo "PATCHED: /usr/share/perl5/PVE/"
fi
echo ""
service pveproxy restart
service pvedaemon restart
;;
test)
pve_manager_patch | patch_apply /usr/share/pve-manager/ --dry-run --batch || true
pve_perl_patch | patch_apply /usr/share/perl5/PVE/ --dry-run --batch || true
;;
*)
echo "usage: $0 [apply|revert|test]"
exit 1
;;
esac