#!/usr/bin/perl -w # Backups Blow by Brandon Low# # Copyright 2007 Brandon Low # Released under the terms of the GPL v2 # # http://lostlogicx.com/backupsblow/ package BackupsBlow::Transport::Local; use strict; use Exporter; our (@EXPORT_OK, %EXPORT_TAGS, @ISA); @ISA = qw(Exporter); @EXPORT_OK = qw(&performBackup &removeBackups &listBackups &fixBackupPath); %EXPORT_TAGS = ("all" => [@EXPORT_OK]); use BackupsBlow::Util qw(:transport); use BackupsBlow::Programs qw(:all); use Log::Log4perl; my $logger=Log::Log4perl->get_logger(); sub fixBackupPath ($) { my ($backupPath)=@_; $backupPath=~s/\/*$/\//; return $backupPath; } sub performBackup ($$$$) { my ($backupDir,$backupFile,$incFile,$errFile)=@_; my @command; push @command,buildTarCommand($incFile, $errFile); push @command,"$backupDir$backupFile"; my $command=join(">",@command); system($command); if ($? == 0) { chmod(0600,"$backupDir$backupFile"); } else { unlink "$backupDir$backupFile"; die("Failed to perform backup: $command: $?"); } } sub removeBackups ($$) { my ($backupDir,$fileNames)=@_; unshift @$fileNames,"rm"; my $rmCommand=join(" $backupDir",@$fileNames); system($rmCommand); die("Failed to remove old backups: $rmCommand: $?") unless ($? == 0); } # Takes a directory to list # returns an array of files in that directory sub listBackups ($) { # Create a command to list the backups already on the server my @lsCommand; push @lsCommand,needProgram("ls"); push @lsCommand,"-1"; push @lsCommand,$_[0]; my $command=join(" ",@lsCommand); chomp(my @retval=`$command 2> /dev/null`); die("Unable to list backups") unless ($? == 0); return @retval; } 1;
"Remember, brick walls let us show our dedication. They are there to separate us from the people who don't really want to achieve their dreams. Don't bail. The best of the gold's at the bottom of barrels of crap." --Randy Pausch