#! /usr/local/env perl use warnings; use strict; # Part of backupServer package. This module creates a copy of the current directory # using cp -al (linked lists) in a dated copy # allows multiple copies of a directory tree to exist without using a lot of disk space # First two parameters are directories RELATIVE TO THE INSTALL DIRECTORY which we are working with # Example call: # version backup version /home/backups DailyData mal.dailydata.net # First verifies the followind directories exist: # /home/backups/DailyData/mal.dailydata.net/ # /home/backups/DailyData/mal.dailydata.net/backup # /home/backups/DailyData/mal.dailydata.net/version (creates if it does not exist) # Then determines the current date. It then executes the command # cp -al /home/backups/DailyData/mal.dailydata.net/backup /home/backups/DailyData/mal.dailydata.net/version/date # which, on 1 Jan 2010 would copy /home/backups/DailyData/mal.dailydata.net/backup to # /home/backups/DailyData/mal.dailydata.net/version/20100101, creating hard links # between all files in the tree. # # NOTE: target and source MUST be on the same partition. Hard Links to not work across partitions my $sourceDir = shift; # the directory which we copy from my $targetDir = shift; # the directory under which we create the backup copy my $rootDir = shift; my $client = shift; my $server = shift; my $confDir = shift; $sourceDir = "$rootDir/$client/$server/$sourceDir"; $targetDir = "$rootDir/$client/$server/$targetDir"; die "Invalid Call, exiting" unless ( $rootDir && $client && $server && $confDir ); die "Invalid Path for version $sourceDir, exiting" unless -d "$sourceDir"; die "Source directory $sourceDir does not exist" unless -d $sourceDir; print `mkdir -p $targetDir` unless -d $targetDir; $targetDir .= '/' . `date +"%Y-%m-%d"`; chomp $targetDir; if ( -e $targetDir ) { print "Not creating [$targetDir], it already exists\n"; } else { print "Creating Linked Backup of source tree at " . `date`; print qx/cp -al $sourceDir $targetDir/; print " Complete at " . `date`; } 1;