Differential backup script using exdupe

mythicalbox

New Member
Aug 30, 2012
16
0
1
Hello, Could someone help convert this script I found and marked up with pseduo code to use exdupe to functional perl code?

www.exdupe.com

Code:
#!/usr/bin/perl -w# hook script for vzdump (--script option)
# quax@ 26.04.2011, mythicalbox@ 06.09.2012
# thanks to http://www.dim13.org/2011/05/Backup-Proxmox-Containers-to-FTP
use strict;
print "HOOK: " . join (' ', @ARGV) . "\n";


# config
my $host = "host";
my $user = "user";
my $pass = "secret";
my $dir = "/";
my $backupdir = "/mnt/pve/backupsOnNode3";
my $nodeb_backupdir = "/var/lib/vz/backups/dump";


my $phase = shift;
my $mode = shift; # stop/suspend/snapshot
my $vmid = shift;
my $vmtype = $ENV{VMTYPE}; # openvz/qemu
my $dumpdir = $ENV{DUMPDIR};
my $hostname = $ENV{HOSTNAME};
my $tarfile = $ENV{TARFILE};
my $logfile = $ENV{LOGFILE}; 


my %dispatch = (
        "job-start"     => \&nop,
        "job-end"       => \&nop,
        "job-abort"     => \&nop,
        "backup-start"  => \&nop,
        "backup-end"    => \&backup_end,
        "backup-abort"  => \&nop,
        "log-end"       => \&log_end,
        "pre-stop"      => \&nop,
        "pre-restart"   => \&nop,
);


sub upload {
        my $file = shift;


        # left over from old script
        #system("echo $pass | ftp-upload -h $host -u $user -s -d $dir $file") == 0 ||
        #system("echo $pass | ftp-upload -h $host -u $user -s -d $dir $file") == 0 ||
        #die "upload to backup-host failed";


    my ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) = localtime(time);
    my $datetimestamp = "$year-$month-$mday $hour:$min:$sec";


    #if FULL file does not exist
        #exdupe should run on the node where the files are to prevent extra network/nfs IO traffic


        my $createFull = "exdupe -g2 -t12 $nodeb_backupdir/$file $vmid.full";
        system("touch $backupdir/$vmid.full-$datetimestamp"); # so we know when the .full was made


        #delete original file


        system("ssh 192.168.5.200 \"echo $createFull");
    #else
        #CREATE DELTA FILE
        #move delta file
        my $createDiff = "exdupe -t12 -D $nodeb_backupdir/$file $nodeb_backupdir/$vmid.full $nodeb_backupdir/$vmid-$datetimestamp.diff";
                system("ssh 192.168.5.200 \"echo $createDiff");


        #delete original file
        #delete old backups > maxbackup count
    #endelse




    #move to final storage path


        print "TEMP DISABLED\n"; #HOOK: upload " . $file . " to ftp://" . $host . $dir . " done\n";
}


sub nop {
        # nothing
}


sub backup_end {
        upload($tarfile);
}


sub log_end {
        # Not storing Log upload($logfile);
}


exists $dispatch{$phase} ? $dispatch{$phase}() : die "got unknown phase '$phase'";


exit (0);

You'll notice in the script that for efficiency purposes I was trying to write it to run the exdupe operations on the node that is storing the back ups.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!