Bricklevel backup in folders

From Zarafa wiki

Revision as of 07:27, 4 November 2010 by DinX (Talk | contribs)
Jump to: navigation, search

The following Perl script makes it possible to store the bricklevel backups in different folders. This way you don't have thousands of backup files in 1 directory making it easier to restore.

#!/usr/bin/perl
open(OUT, "> /zarafa/scripts/temp.txt");
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
printf OUT "================================================================ \n";
printf OUT "%4d-%02d-%02d %02d:%02d:%02d : Starting Zarafa Backup\n",$year+1900,$mon+1,$mday,$hour,$min,$sec;
printf OUT "================================================================ \n";


@lines = `zarafa-admin -l | awk '{ print $1 }'`;
$i = 0;
foreach $line (@lines) {
        if ($i > 3) {
                @temp = split(" ", $line);
                $dir = "<your backup dir>" . $temp[0];
                if($temp[0]) {
                        if (-d $dir) {
                                ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
                                printf OUT "%4d-%02d-%02d %02d:%02d:%02d : Starting backup of $temp[0]\n",$year+1900,$mon+1,$mday,$hour,$min,$sec;
                                `zarafa-backup -u $temp[0] -o $dir`;
                                ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
                                printf OUT "%4d-%02d-%02d %02d:%02d:%02d : Finished backup of $temp[0]\n",$year+1900,$mon+1,$mday,$hour,$min,$sec;
                        }
                        else
                        {
                                mkdir $dir;
                                ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
                                printf OUT "%4d-%02d-%02d %02d:%02d:%02d : Starting backup of $temp[0]\n",$year+1900,$mon+1,$mday,$hour,$min,$sec;
                                `zarafa-backup -u $temp[0] -o $dir`;
                                ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
                                printf OUT "%4d-%02d-%02d %02d:%02d:%02d : Finished backup of $temp[0]\n",$year+1900,$mon+1,$mday,$hour,$min,$sec;
                        }
                }
        }
        $i++;
}
printf OUT "\n================================================================ \n";
system("mail -s \"Zarafa Backup\" yourmail\@domain.com < /zarafa/scripts/temp.txt");
system("rm -f /zarafa/scripts/temp.txt");
Personal tools