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-6.2-4-diff-backup-addon
executable file
·661 lines (577 loc) · 21.3 KB
/
pve-6.2-4-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
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
#!/bin/bash
set -eo pipefail
VERSION=6.2-4
echo "Proxmox VE $VERSION - differential backup support, v3"
echo "Kamil Trzcinski, http://ayufan.eu/, [email protected]"
echo ""
patch_diff() {
grep -A 10000 "^__PATCH__$" "$0"
}
patch_revert() {
patch_diff | patch --reverse --quiet -p1 --batch --ignore-whitespace -d "$@"
}
patch_apply() {
patch_diff | patch --forward -p1 --batch --ignore-whitespace -d "$@"
}
print_and_run() {
echo "$ $@"
"$@"
}
patch_test() {
local TYPE="$1"
local VMID="$2"
local EXT="$3"
local TARGET_VMID="$4"
local TARGET_EXT="$EXT"
TARGET_EXT=${TARGET_EXT/tar/}
TARGET_EXT=${TARGET_EXT/vma/}
shift 4
echo "Testing type=$TYPE vmid=$VMID:$TARGET_VMID ext=$ext flags=$@..."
case $TYPE in
qemu)
print_and_run qm status "$VMID"
print_and_run vzdump --fullbackup=0 "$@" $VMID
print_and_run vzdump --fullbackup=5 "$@" $VMID
print_and_run qmrestore --force=true /var/lib/vz/dump/vzdump-qemu-$VMID-*.$EXT $TARGET_VMID
print_and_run qmrestore --force=true /var/lib/vz/dump/vzdump-qemu-$VMID-*.$EXT-*.vcdiff${TARGET_EXT} $TARGET_VMID
;;
lxc)
print_and_run pct status "$VMID"
print_and_run vzdump --fullbackup=0 "$@" $VMID
print_and_run vzdump --fullbackup=5 "$@" $VMID
print_and_run pct restore $TARGET_VMID /var/lib/vz/dump/vzdump-lxc-$VMID-*.$EXT --force=true
print_and_run pct restore $TARGET_VMID /var/lib/vz/dump/vzdump-lxc-$VMID-*.$EXT-*.vcdiff${TARGET_EXT} --force=true
;;
esac
}
case $1 in
revert)
if patch_revert / --dry-run
then
patch_revert /
echo "RESTORED"
else
echo "FAILED to restore!"
exit 1
fi
echo ""
print_and_run service pveproxy restart
print_and_run service pvedaemon restart
;;
apply)
if ! dpkg -s pve-xdelta3 2>/dev/null | grep -q zstd; then
echo "Missing pve-xdelta3"
echo
echo "wget https://github.com/ayufan/pve-xdelta3/releases/download/3.0.11.zstd/pve-xdelta3_3.0.11-dfsg-1ubuntu1.zstd.ayufan2_amd64.deb"
echo "dpkg -i pve-xdelta3_3.0.11-dfsg-1ubuntu1.zstd.ayufan2_amd64.deb"
exit 1
fi
if patch_apply / --dry-run
then
print_and_run patch_apply /
echo "APPLIED"
else
echo "FAILED to apply!"
exit 1
fi
echo ""
print_and_run service pveproxy restart
print_and_run service pvedaemon restart
;;
reinstall)
PATHS=$(patch_diff | grep "^+++ b/" | sed 's/^\+\+\+ b//g')
echo "Affected file paths:"
echo "$PATHS"
echo ""
PACKAGES=$(dpkg --search $PATHS | cut -d: -f1 | tr -d , | sort -u)
echo "Affected packages:"
echo "$PACKAGES"
echo ""
echo "Press Enter to continue, or Ctrl-C to cancel."
read PROMPT
apt-get --reinstall install $PACKAGES
;;
test)
print_and_run patch_apply / --dry-run --batch
;;
patch)
patch_diff
;;
selftest-qemu)
echo "This is destructive command that requires:"
echo ""
echo "- the VM500 present"
echo "- and VM510 empty"
echo ""
if ! qm status 500 &> /dev/null; then
echo "The VM500 has to be present!"
exit 1
fi
echo "Press enter to continue, Ctrl-C to abort"
read LINE
print_and_run rm -rf /var/lib/vz/dump/vzdump-qemu-500-*
patch_test qemu 500 vma.zst 510 --compress=zstd
patch_test qemu 500 vma.lzo 510 --compress=lzo
patch_test qemu 500 vma 510
patch_test qemu 500 vma.gz 510 --compress=gzip
;;
selftest-lxc)
echo "This is destructive command that requires:"
echo ""
echo "- the CT501 present"
echo "- and CT511 empty"
echo ""
if ! pct status 501 &> /dev/null; then
echo "The CT501 has to be present!"
exit 1
fi
echo "Press enter to continue, Ctrl-C to abort"
read LINE
print_and_run rm -rf /var/lib/vz/dump/vzdump-lxc-501-*
patch_test lxc 501 tar.zst 511 --compress=zstd
patch_test lxc 501 tar.lzo 511 --compress=lzo
patch_test lxc 501 tar 511
patch_test lxc 501 tar.gz 511 --compress=gzip
;;
new-version)
set -e
if [[ "$#" -ne 3 ]]; then
echo "usage: $0 new-version <pve-commit-id> <pve-manager-id>"
exit 1
fi
VERSION=$(dpkg -s pve-manager | grep Version | awk '{print $2}')
echo "Detected pve-manager $VERSION..."
echo
echo "Checking perl5/PVE patch $2..."
git -C /usr/share/perl5/PVE show "$2" | patch -p1 --dry-run -d /usr/share/perl5/PVE -R
echo
echo "Checking pve-manager patch $3..."
git -C /usr/share/pve-manager show "$3" | patch -p1 --dry-run -d /usr/share/pve-manager -R
echo
OUT="pve-$VERSION-diff-backup-addon"
if [[ -e "$OUT" ]]; then
echo "The $OUT already exist. Are you sure?"
fi
echo "Press enter to continue, Ctrl-C to abort"
read LINE
(
grep -B 10000 "^__PATCH__$" "$0" | sed "s/^VERSION=.*$/VERSION=$VERSION/"
git -C /usr/share/perl5/PVE show "$2" | sed \
-e "s|^\([-+][-+][-+] [ab]\)/|\1/usr/share/perl5/PVE/|g"
git -C /usr/share/pve-manager show "$3" | sed \
-e "s|^\([-+][-+][-+] [ab]\)/|\1/usr/share/pve-manager/|g"
) > "$OUT"
chmod +x "$OUT"
echo "Wrote $OUT."
;;
*)
echo "usage: $0 [apply|revert|test|patch]"
exit 1
;;
esac
exit 0
__PATCH__
commit 96b13aa6b4b5719b9f1d2c5fae9fa741ee288239
Author: Kamil Trzciński <[email protected]>
Date: Fri Mar 20 12:12:36 2020 +0100
PVE diff backup
diff --git a/LXC/Create.pm b/LXC/Create.pm
index 39902a2..9c43385 100644
--- a/usr/share/perl5/PVE/LXC/Create.pm
+++ b/usr/share/perl5/PVE/LXC/Create.pm
@@ -116,7 +116,10 @@ sub restore_tar_archive {
my $archive_fh;
my $tar_input = '<&STDIN';
my @compression_opt;
- if ($archive ne '-') {
+
+ if (PVE::Storage::get_full_backup($archive)) {
+ # ignore
+ } elsif ($archive ne '-') {
# GNU tar refuses to autodetect this... *sigh*
my %compression_map = (
'.gz' => '-z',
@@ -152,8 +155,19 @@ sub restore_tar_archive {
push @$cmd, '--anchored';
push @$cmd, '--exclude' , './dev/*';
+ $cmd = [ $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', @PVE::Storage::Plugin::COMMON_TAR_FLAGS, '-C', $rootdir, '--skip-old-files', '--anchored', '--exclude' , './dev/*']
+ ];
+ }
+
if (defined($bwlimit)) {
- $cmd = [ ['cstream', '-t', $bwlimit*1024], $cmd ];
+ splice @$cmd, 1, 0, ['cstream', '-t', $bwlimit*1024];
}
if ($archive eq '-') {
diff --git a/QemuServer.pm b/QemuServer.pm
index dcf05df..9c3fed6 100644
--- a/usr/share/perl5/PVE/QemuServer.pm
+++ b/usr/share/perl5/PVE/QemuServer.pm
@@ -5621,8 +5621,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(\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?)))--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?$!) {
+ my $fullbackup = $archive;
+ $fullbackup =~ s!([^/]*vzdump-([a-z]+)-(\d+)-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|(tar(\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?)))--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?!$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;
@@ -6255,7 +6265,13 @@ sub restore_vma_archive {
}
}
- if ($comp) {
+ if ($archive =~ m!([^/]*vzdump-([a-z]*)-(\d*)-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(vma(\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?))--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo|zst))?$!) {
+ my $fullbackup = $archive;
+ $fullbackup =~ s!([^/]*vzdump-([a-z]+)-(\d+)-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(vma(\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?))--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo|zst))?!$1!;
+ print "extracting from differential archive, using full backup '$fullbackup'\n";
+ my $uncomp = ['pve-xdelta3', '-q', '-d', '-c', '-R', '-s', $fullbackup, $readfrom];
+ $add_pipe->($uncomp);
+ } elsif ($comp) {
my $info = PVE::Storage::decompressor_info('vma', $comp);
my $cmd = $info->{decompressor};
push @$cmd, $readfrom;
@@ -6459,8 +6475,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(\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?)))--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?$!) {
+ my $fullbackup = $archive;
+ $fullbackup =~ s!([^/]*vzdump-([a-z]+)-(\d+)-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|(tar(\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?)))--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?!$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 f1e3b19..f385c2b 100644
--- a/usr/share/perl5/PVE/Storage.pm
+++ b/usr/share/perl5/PVE/Storage.pm
@@ -535,7 +535,7 @@ sub path_to_volume_id {
} elsif ($path =~ m!^$privatedir/(\d+)$!) {
my $vmid = $1;
return ('rootdir', "$sid:rootdir/$vmid");
- } elsif ($path =~ m!^$backupdir/([^/]+\.(?:tgz|(?:(?:tar|vma)(?:\.(?:${\PVE::Storage::Plugin::COMPRESSOR_RE}))?)))$!) {
+ } elsif ($path =~ m!^$backupdir/([^/]+\.(?:tgz|(?:(?:tar|vma|vcdiff)(?:\.(?:${\PVE::Storage::Plugin::COMPRESSOR_RE}))?)))$!) {
my $name = $1;
return ('backup', "$sid:backup/$name");
} elsif ($path =~ m!^$snippetsdir/([^/]+)$!) {
@@ -1397,6 +1397,9 @@ sub archive_info {
if ($volid =~ /vzdump-(lxc|openvz|qemu)-\d+-.+\.(tgz$|tar|vma)(?:\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?$/) {
$info = decompressor_info($2, $3);
$info->{type} = $1;
+ } elsif ($volid =~ /vzdump-(lxc|openvz|qemu)-\d+-.+\.(tgz$|tar|vma)(?:\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?--differential-.+\.vcdiff(\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?$/) {
+ $info = decompressor_info($2, $3);
+ $info->{type} = $1;
} else {
die "ERROR: couldn't determine archive info from '$archive'\n";
}
@@ -1404,13 +1407,30 @@ sub archive_info {
return $info;
}
+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(\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?)))--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?$!) {
+ my $fullbackup = $archive;
+ $fullbackup =~ s!([^/]*vzdump-([a-z]+)-(\d+)-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|(tar(\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?)))--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?!$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>)) {
@@ -1433,7 +1453,15 @@ sub extract_vzdump_config_tar {
$raw .= "$output\n";
};
- 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' ]
+ ];
+ }
+
+ run_command($cmd, outfunc => $out);
return wantarray ? ($raw, $file) : $raw;
}
diff --git a/Storage/Plugin.pm b/Storage/Plugin.pm
index cec136e..9964be5 100644
--- a/usr/share/perl5/PVE/Storage/Plugin.pm
+++ b/usr/share/perl5/PVE/Storage/Plugin.pm
@@ -437,7 +437,7 @@ sub parse_volname {
return ('vztmpl', $1);
} elsif ($volname =~ m!^rootdir/(\d+)$!) {
return ('rootdir', $1, $1);
- } elsif ($volname =~ m!^backup/([^/]+(?:\.(?:tgz|(?:(?:tar|vma)(?:\.(?:${\COMPRESSOR_RE}))?))))$!) {
+ } elsif ($volname =~ m!^backup/([^/]+(?:\.(?:tgz|(?:(?:tar|vma|vcdiff)(?:\.(?:${\COMPRESSOR_RE}))?))))$!) {
my $fn = $1;
if ($fn =~ m/^vzdump-(openvz|lxc|qemu)-(\d+)-.+/) {
return ('backup', $fn, $2);
@@ -941,7 +941,7 @@ my $get_subdir_files = sub {
} elsif ($tt eq 'backup') {
next if defined($vmid) && $fn !~ m/\S+-$vmid-\S+/;
- next if $fn !~ m!/([^/]+\.(tgz|(?:(?:tar|vma)(?:\.(${\COMPRESSOR_RE}))?)))$!;
+ next if $fn !~ m!/([^/]+\.(tgz|(?:(?:tar|vma|vcdiff)(?:\.(${\COMPRESSOR_RE}))?)))$!;
my $format = $2;
$fn = $1;
diff --git a/VZDump.pm b/VZDump.pm
index 623c6f8..9cfae1d 100644
--- a/usr/share/perl5/PVE/VZDump.pm
+++ b/usr/share/perl5/PVE/VZDump.pm
@@ -7,6 +7,7 @@ use Fcntl ':flock';
use File::Path;
use IO::File;
use IO::Select;
+use File::Basename;
use IPC::Open3;
use POSIX qw(strftime);
use Time::Local;
@@ -639,6 +640,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(\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?)$!) {
+ $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) = @_;
@@ -712,17 +729,47 @@ sub exec_backup_task {
if $count >= $maxfiles;
}
- if (!$self->{opts}->{pbs}) {
- $task->{logfile} = "$opts->{dumpdir}/$basename.log";
+ my $ext = $vmtype eq 'qemu' ? '.vma' : '.tar';
+
+ my $fullbackup = undef;
+ if (!$opts->{opts}->{pbs}) {
+ if ($opts->{fullbackup} && !$opts->{stdout}) {
+ my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
+ my $bklist = get_backup_file_list($opts->{dumpdir}, $bkname);
+ $bklist = [ sort { $b->[1] <=> $a->[1] } @$bklist ];
+ my $mintime = timelocal($sec, $min, $hour, $mday, $mon, $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",
+ $year + 1900, $mon + 1, $mday,
+ $hour, $min, $sec;
+ $ext = ".vcdiff";
+
+ 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 $ext = $vmtype eq 'qemu' ? '.vma' : '.tar';
my ($comp, $comp_ext) = compressor_info($opts);
if ($comp && $comp_ext) {
$ext .= ".${comp_ext}";
}
- if ($self->{opts}->{pbs}) {
+ if (!$opts->{opts}->{type}) {
+ $task->{logfile} = "$opts->{dumpdir}/$basename.log";
+ }
+
+ if ($opts->{opts}->{type}) {
die "unable to pipe backup to stdout\n" if $opts->{stdout};
} else {
if ($opts->{stdout}) {
@@ -905,7 +952,7 @@ sub exec_backup_task {
} else {
debugmsg ('info', "creating archive '$task->{tarfile}'", $logfd);
}
- $plugin->archive($task, $vmid, $task->{tmptar}, $comp);
+ $plugin->archive($task, $vmid, $task->{tmptar}, $comp, $fullbackup);
if ($self->{opts}->{pbs}) {
# fixme: log size ?
@@ -921,7 +968,7 @@ sub exec_backup_task {
}
# purge older backup
- if ($maxfiles && $opts->{remove}) {
+ if ($maxfiles && $opts->{remove} && !$fullbackup) {
if ($self->{opts}->{pbs}) {
my $args = [$pbs_group_name, '--keep-last', $maxfiles];
@@ -939,6 +986,16 @@ sub exec_backup_task {
my $logfn = $d->[0];
$logfn =~ s/\.(tgz|((tar|vma)(\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?))$/\.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(\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?)$/\.log/;
+ unlink $logfn;
+ }
}
}
}
diff --git a/VZDump/Common.pm b/VZDump/Common.pm
index 909e3af..1c3abe2 100644
--- a/usr/share/perl5/PVE/VZDump/Common.pm
+++ b/usr/share/perl5/PVE/VZDump/Common.pm
@@ -210,6 +210,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.",
diff --git a/VZDump/LXC.pm b/VZDump/LXC.pm
index 0dc60c4..35d0493 100644
--- a/usr/share/perl5/PVE/VZDump/LXC.pm
+++ b/usr/share/perl5/PVE/VZDump/LXC.pm
@@ -317,7 +317,7 @@ sub assemble {
}
sub archive {
- my ($self, $task, $vmid, $filename, $comp) = @_;
+ my ($self, $task, $vmid, $filename, $comp, $basefile) = @_;
my $disks = $task->{disks};
my @sources;
@@ -412,6 +412,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 1a0d437..0d10369 100644
--- a/usr/share/perl5/PVE/VZDump/QemuServer.pm
+++ b/usr/share/perl5/PVE/VZDump/QemuServer.pm
@@ -243,7 +243,7 @@ sub assemble {
}
sub archive {
- my ($self, $task, $vmid, $filename, $comp) = @_;
+ my ($self, $task, $vmid, $filename, $comp, $basefile) = @_;
my $opts = $self->{vzdump}->{opts};
my $scfg = $opts->{scfg};
@@ -251,7 +251,7 @@ sub archive {
if ($self->{vzdump}->{opts}->{pbs}) {
$self->archive_pbs($task, $vmid);
} else {
- $self->archive_vma($task, $vmid, $filename, $comp);
+ $self->archive_vma($task, $vmid, $filename, $comp, $basefile);
}
}
@@ -472,7 +472,7 @@ my $fork_compressor_pipe = sub {
};
sub archive_vma {
- 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";
@@ -547,6 +547,15 @@ sub archive_vma {
}
my $outfileno = fileno($outfh);
+ if ($basefile) {
+ my $basecmd = "pve-xdelta3 -e -q -c -s '$basefile'";
+ if ($comp) {
+ $comp = "$basecmd|$comp";
+ } else {
+ $comp = $basecmd;
+ }
+ }
+
if ($comp) {
($cpid, $outfileno) = $fork_compressor_pipe->($self, $comp, $outfileno);
}
commit 53d1df30e8425c6d230bb5c6d0a61a8e55b42598
Author: Kamil Trzciński <[email protected]>
Date: Fri Mar 20 12:10:00 2020 +0100
PVE diff backup
diff --git a/js/pvemanagerlib.js b/js/pvemanagerlib.js
index 36c9e71..dad4b29 100644
--- a/usr/share/pve-manager/js/pvemanagerlib.js
+++ b/usr/share/pve-manager/js/pvemanagerlib.js
@@ -41663,6 +41663,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',