#! /usr/bin/env perl use warnings; use strict; # Part of backupServer package. This module creates a copy of the current directory # using zfs snapshot # allows multiple copies of a directory tree to exist without using a lot of disk space # third parameter is the root path of the backups (ie, /srv) # third and fourth parameters are the client name and server name # last parameter is the configuration directory (again, not used) # Example call: # version_zfs /srv DailyData strax.dailydata.net /usr/local/etc/rsbackup # First verifies all required parameters entered, and the source directory exists # then determines the zfs dataset name (from the path), and concatenates the date/time my $rootDir = shift; # root of all backups my $client = shift; # client name (subdirectory of $rootdir) my $server = shift; # server name (subdirectory of rootdir/client and a zfs dataset) sub dateTimeStamp { use POSIX qw(strftime); my $format = shift; return strftime $format, localtime(); } # following command accepts path, and returns tab separated list, the first # value being the zfs name mounted there my $GETZFSFROMPATH = 'zfs list -H '; my @error; push @error, '$rootDir unset' unless $rootDir; push @error, '$client unset' unless $client; push @error, '$server unset' unless $server; die "Invalid Call: " . join( "\n\t", @error ) . "\n" if @error; my $sourceDir = "$rootDir/$client/$server"; die "Source directory $sourceDir does not exist" unless -d $sourceDir; my ($zfsName) = split( "\t", `$GETZFSFROMPATH $sourceDir` ); $zfsName .= '@' . &dateTimeStamp( '%Y%m%d_%H%M%S' ); chomp $zfsName; print "Creating Linked Backup of source tree at " . &dateTimeStamp( '%F %T') . "\n"; print qx/zfs snapshot -r $zfsName/; #print "zfs snapshot -r $zfsName\n"; print " Complete at " . &dateTimeStamp( '%F %T') . "\n"; 1;