#!/usr/local/bin/perl use warnings; use strict; $|++; use vars qw( $LOGDIR $TESTING $TAPEPATH $DISKPATH %DRIVES $DUMP $REMOTE $FSSNAP $TAR ); do '/etc/tardump.config' or die "No/bad /etc/tardump.config\n"; $FSSNAP ||= "/usr/sbin/fssnap"; $TAR ||= "/usr/local/bin/gtar"; # Should have something in here for '-F', the auto-change-tape option die "Not root" unless $< == 0; use vars qw( $DEFAULT ); my $mntpoint = "/mnt/gtar_backup"; until (-d $mntpoint) { print "mkdir -p $mntpoint\n"; system("mkdir -p $mntpoint"); sleep 1; } foreach my $drive (sort keys %DRIVES) { my $info = ref $DRIVES{$drive} ? $DRIVES{$drive} : $DEFAULT; my $raw = ref $DRIVES{$drive} ? $$info{'physical'} : $DRIVES{$drive}; print scalar localtime, " - $drive ($raw)\n"; # System drive; we have to stop and restart ntp stop_ntp() if ($raw eq '/'); my $snapstring = "$FSSNAP -F ufs -o raw,bs=$DISKPATH,unlink $raw"; print "$snapstring\n"; my $fssnap = `$snapstring`; chomp $fssnap; my $mount = $fssnap; $mount =~ s/rfs/fs/; my $mntstring = "mount -F ufs -o ro $mount $mntpoint"; print "$mntstring\n"; system $mntstring unless $TESTING; my $string = ""; if ($REMOTE) { $string = "$TAR -C $mntpoint -Mvcf - . $REMOTE"; } elsif ($TAPEPATH) { $string = "$TAR -C $mntpoint -Mvcf $TAPEPATH ."; } else { die "No tape to write to\n"; } print "$string\n"; system($string) unless $TESTING; my $umntstring = "umount -f $mntpoint"; print "$umntstring\n"; system $umntstring unless $TESTING; my $unsnap = "$FSSNAP -F ufs -d $raw"; print "$unsnap\n"; system $unsnap; start_ntp() if ($raw eq '/'); } sub stop_ntp { system("/etc/init.d/xntpd stop > /dev/null 2>&1"); } sub start_ntp { system("/etc/init.d/xntpd start > /dev/null 2>&1"); }