Hello
I have an environment with 6 PVE hosts and have recently setup a PBS server to backup these hosts.
What I want to achieve is to in the backup job call for a perl script that copies the backup files to our S3 storage and then delete the local file.
I run into errors though and since I'm a newbie on some of this I need help.
In the jobs.cfg I call on the script in the root folder as below.
The hook script I use is from Andrew Palardy and looks like this.
The job fails and the log show this.
Local backups works perfectly and my S3 setup works also for manual copying and such.
How do I fix this?
Thank you in advance
I have an environment with 6 PVE hosts and have recently setup a PBS server to backup these hosts.
What I want to achieve is to in the backup job call for a perl script that copies the backup files to our S3 storage and then delete the local file.
I run into errors though and since I'm a newbie on some of this I need help.
In the jobs.cfg I call on the script in the root folder as below.
Code:
vzdump: backup-67a4674f-3b31
comment
schedule 21:00
enabled 1
mailnotification always
mailto xxx
mode snapshot
notes-template {{guestname}}
script /root/vzdump.pl
storage <storage>
vmid 212080
The hook script I use is from Andrew Palardy and looks like this.
Perl:
#!/usr/bin/perl -w
# Hook script for vzdump to backup to an S3 bucket
# 2022 Andrew Palardy
# Based on example hook script from Proxmox
use strict;
# Define the name of your bucket here
my $bucket = "S3backup";
# The S3 endpoint comes from the s3cmd --configure setup, it is not set here
# Define the number of days to retain backups in the bucket
# Only accepts days, doesn't check hours/minutes
my $retain = 7;
#Uncomment this to see the hook script with arguments (not required)
print "HOOK: " . join (' ', @ARGV) . "\n";
#Get the phase from the first argument
my $phase = shift;
#For job-based phases
#Note that job-init was added in PVE 7.2 or 7.3 AFAIK
if ( $phase eq 'job-init' ||
$phase eq 'job-start' ||
$phase eq 'job-end' ||
$phase eq 'job-abort') {
#Env variables available for job based arguments
my $dumpdir = $ENV{DUMPDIR};
my $storeid = $ENV{STOREID};
#Uncomment this to print the environment variables for debugging
print "HOOK-ENV: dumpdir=$dumpdir;storeid=$storeid\n";
#Call s3cleanup at job end
if ($phase eq 'job-end') {
system ("/root/s3cleanup.sh $bucket \"$retain days\"");
}
#For backup-based phases
} elsif ($phase eq 'backup-start' ||
$phase eq 'backup-end' ||
$phase eq 'backup-abort' ||
$phase eq 'log-end' ||
$phase eq 'pre-stop' ||
$phase eq 'pre-restart' ||
$phase eq 'post-restart') {
#Data available to backup-based phases
my $mode = shift; # stop/suspend/snapshot
my $vmid = shift;
my $vmtype = $ENV{VMTYPE}; # lxc/qemu
my $dumpdir = $ENV{DUMPDIR};
my $storeid = $ENV{STOREID};
my $hostname = $ENV{HOSTNAME};
my $tarfile = $ENV{TARGET};
my $logfile = $ENV{LOGFILE};
#Uncomment this to print environment variables
print "HOOK-ENV: vmtype=$vmtype;dumpdir=$dumpdir;storeid=$storeid;hostname=$hostname;tarfile=$tarfile;logfile=$logfile\n";
# During backup-end, copy the target file to S3 and delete the original on the system
if ($phase eq 'backup-end') {
#S3 put
my $result = system ("s3cmd put $tarfile s3://$bucket/");
#rm original
system ("rm $tarfile");
#Die of error returned
if($result != 0) {
die "upload backup failed";
}
}
# During log-end, copy the log file to S3 and delete the original on the system (same as target file)
if ($phase eq 'log-end') {
my $result = system ("s3cmd put $logfile s3://$bucket/");
system ("rm $logfile");
if($result != 0) {
die "upload logfile failed";
}
}
#Otherwise, phase is unknown
} else {
die "got unknown phase '$phase'";
}
exit (0);
The job fails and the log show this.
Code:
Logs
vzdump 212080 --mailto log@example.com --notes-template '{{guestname}}' --storage <PBS Storage> --mailnotification always --quiet 1 --script /root/vzdump.pl --mode snapshot
2024-04-22 21:00:04 INFO: HOOK: job-init
2024-04-22 21:00:04 INFO: HOOK-ENV: dumpdir=;storeid=<PBS Storage>
2024-04-22 21:00:04 INFO: Use of uninitialized value $dumpdir in concatenation (.) or string at /root/vzdump.pl line 36.
2024-04-22 21:00:04 INFO: HOOK: job-start
2024-04-22 21:00:04 INFO: HOOK-ENV: dumpdir=;storeid=<PBS Storage>
2024-04-22 21:00:04 INFO: Use of uninitialized value $dumpdir in concatenation (.) or string at /root/vzdump.pl line 36.
212080: 2024-04-22 21:00:04 INFO: Starting Backup of VM 212080 (qemu)
212080: 2024-04-22 21:00:04 INFO: status = running
212080: 2024-04-22 21:00:04 INFO: VM Name: <VM name>
212080: 2024-04-22 21:00:04 INFO: include disk 'scsi0' 'local-lvm:vm-212080-disk-0' 53452M
212080: 2024-04-22 21:00:04 INFO: include disk 'scsi1' 'storage-lvm:vm-212080-disk-0' 650G
212080: 2024-04-22 21:00:05 INFO: backup mode: snapshot
212080: 2024-04-22 21:00:05 INFO: ionice priority: 7
212080: 2024-04-22 21:00:05 INFO: Use of uninitialized value $dumpdir in concatenation (.) or string at /root/vzdump.pl line 69.
212080: 2024-04-22 21:00:05 INFO: Use of uninitialized value $logfile in concatenation (.) or string at /root/vzdump.pl line 69.
212080: 2024-04-22 21:00:05 INFO: HOOK: backup-start snapshot 212080
212080: 2024-04-22 21:00:05 INFO: HOOK-ENV: vmtype=qemu;dumpdir=;storeid=<PBS Storage>;hostname=<VM name>;tarfile=vm/212080/2024-04-22T19:00:04Z;logfile=
212080: 2024-04-22 21:00:05 INFO: Use of uninitialized value $dumpdir in concatenation (.) or string at /root/vzdump.pl line 69.
212080: 2024-04-22 21:00:05 INFO: Use of uninitialized value $logfile in concatenation (.) or string at /root/vzdump.pl line 69.
212080: 2024-04-22 21:00:05 INFO: HOOK: pre-stop snapshot 212080
212080: 2024-04-22 21:00:05 INFO: HOOK-ENV: vmtype=qemu;dumpdir=;storeid=<PBS Storage>;hostname=<VM name>;tarfile=vm/212080/2024-04-22T19:00:04Z;logfile=
212080: 2024-04-22 21:00:05 INFO: Use of uninitialized value $dumpdir in concatenation (.) or string at /root/vzdump.pl line 69.
212080: 2024-04-22 21:00:05 INFO: Use of uninitialized value $logfile in concatenation (.) or string at /root/vzdump.pl line 69.
212080: 2024-04-22 21:00:05 INFO: HOOK: pre-restart snapshot 212080
212080: 2024-04-22 21:00:05 INFO: HOOK-ENV: vmtype=qemu;dumpdir=;storeid=<PBS Storage>;hostname=<VM name>;tarfile=vm/212080/2024-04-22T19:00:04Z;logfile=
212080: 2024-04-22 21:00:05 INFO: Use of uninitialized value $dumpdir in concatenation (.) or string at /root/vzdump.pl line 69.
212080: 2024-04-22 21:00:05 INFO: Use of uninitialized value $logfile in concatenation (.) or string at /root/vzdump.pl line 69.
212080: 2024-04-22 21:00:05 INFO: HOOK: post-restart snapshot 212080
212080: 2024-04-22 21:00:05 INFO: HOOK-ENV: vmtype=qemu;dumpdir=;storeid=<PBS Storage>;hostname=<VM name>;tarfile=vm/212080/2024-04-22T19:00:04Z;logfile=
212080: 2024-04-22 21:00:05 INFO: creating Proxmox Backup Server archive 'vm/212080/2024-04-22T19:00:04Z'
212080: 2024-04-22 21:00:05 INFO: issuing guest-agent 'fs-freeze' command
212080: 2024-04-22 21:00:05 INFO: issuing guest-agent 'fs-thaw' command
212080: 2024-04-22 21:00:06 INFO: started backup task 'f82c64a5-89ae-4868-b25e-6b3916abeeb0'
212080: 2024-04-22 21:00:06 INFO: resuming VM again
212080: 2024-04-22 21:00:06 INFO: scsi0: dirty-bitmap status: OK (148.0 MiB of 52.2 GiB dirty)
212080: 2024-04-22 21:00:06 INFO: scsi1: dirty-bitmap status: OK (32.0 MiB of 650.0 GiB dirty)
212080: 2024-04-22 21:00:06 INFO: using fast incremental mode (dirty-bitmap), 180.0 MiB dirty of 702.2 GiB total
212080: 2024-04-22 21:00:09 INFO: 100% (180.0 MiB of 180.0 MiB) in 3s, read: 60.0 MiB/s, write: 58.7 MiB/s
212080: 2024-04-22 21:00:09 INFO: backup was done incrementally, reused 702.03 GiB (99%)
212080: 2024-04-22 21:00:09 INFO: transferred 180.00 MiB in 3 seconds (60.0 MiB/s)
212080: 2024-04-22 21:00:09 INFO: adding notes to backup
212080: 2024-04-22 21:00:09 INFO: Use of uninitialized value $dumpdir in concatenation (.) or string at /root/vzdump.pl line 69.
212080: 2024-04-22 21:00:09 INFO: Use of uninitialized value $logfile in concatenation (.) or string at /root/vzdump.pl line 69.
212080: 2024-04-22 21:00:09 INFO: HOOK: backup-end snapshot 212080
212080: 2024-04-22 21:00:09 INFO: HOOK-ENV: vmtype=qemu;dumpdir=;storeid=<PBS Storage>;hostname=<VM name>;tarfile=vm/212080/2024-04-22T19:00:04Z;logfile=
212080: 2024-04-22 21:00:09 INFO: ERROR: Parameter problem: Nothing to upload.
212080: 2024-04-22 21:00:09 INFO: rm: cannot remove 'vm/212080/2024-04-22T19:00:04Z': No such file or directory
212080: 2024-04-22 21:00:09 INFO: upload backup failed at /root/vzdump.pl line 79.
212080: 2024-04-22 21:00:09 ERROR: Backup of VM 212080 failed - command '/root/vzdump.pl backup-end snapshot 212080' failed: exit code 1
212080: 2024-04-22 21:00:09 INFO: HOOK: backup-abort snapshot 212080
212080: 2024-04-22 21:00:09 INFO: HOOK-ENV: vmtype=qemu;dumpdir=;storeid=<PBS Storage>;hostname=<VM name>;tarfile=vm/212080/2024-04-22T19:00:04Z;logfile=
212080: 2024-04-22 21:00:09 INFO: Use of uninitialized value $dumpdir in concatenation (.) or string at /root/vzdump.pl line 69.
212080: 2024-04-22 21:00:09 INFO: Use of uninitialized value $logfile in concatenation (.) or string at /root/vzdump.pl line 69.
2024-04-22 21:00:09 INFO: HOOK: job-end
2024-04-22 21:00:09 INFO: HOOK-ENV: dumpdir=;storeid=<PBS Storage>
2024-04-22 21:00:09 INFO: Use of uninitialized value $dumpdir in concatenation (.) or string at /root/vzdump.pl line 36.
Local backups works perfectly and my S3 setup works also for manual copying and such.
How do I fix this?
Thank you in advance