#!/usr/bin/perl # This runs out of a cron job on the p4d host, taking a checkpoint # and tarring up the file archive, then mailing to the backup storage # host, which ftps to grab the backup files. # use Carp; use strict; $| = 1; my $Myname; ($Myname = $0) =~ s%^.*/%%; my $P4port = shift; my $P4root = shift; my $P4config = shift; my $Depots = shift; my $Ftp_dir = shift; my $Ftp_prefix = shift; my $Notify_email = shift; $Ftp_prefix = "$Ftp_dir/$Ftp_prefix"; chdir $P4root || die "chdir ($P4root): $!"; my ($sts, $output) = &s("/bin/rm -f $Ftp_prefix.*"); if ($sts) { die $output; } $ENV{"P4CONFIG"} = $P4config; my ($sts, $output) = &s("/usr/local/bin/p4 -p $P4port admin checkpoint -z $Ftp_prefix"); if ($sts) { die $output; } my ($sts, $output) = &s("/usr/local/bin/p4 -p $P4port counter journal"); if ($sts) { die $output; } my $c = $output; chomp $c; my ($sts, $output) = &s("/usr/bin/tar czf $Ftp_prefix.$c.tar.gz $Depots"); if ($sts) { die $output; } my ($sts, $output) = &s("/usr/bin/touch $Ftp_prefix.$c"); if ($sts) { die $output; } open (M, "| /usr/sbin/sendmail $Notify_email") || die "open | /usr/sbin/sendmail $Notify_email: $!"; print M < $cmd\n"); if (! open(CMD, "$cmd 2>&1 |")) { die "can't open \"$cmd 2>&1 |\": $!"; } while () { print(": $_"); $output .= $_; } close CMD; if ($sts = $?) { my $sig = $sts & 0x0f; $sts = $sts >> 8; die "\"$cmd\" exited with signal $sig status $sts"; } return ($sts, $output); }