[mrtg] Re: Archive script

Dave Jones DJones at TheFund.com
Wed Oct 18 23:34:55 MEST 2000


Thank you.  I'll give that a try.  Doesn't look like a "newbie" script
though :)

Dave

-----Original Message-----
From: Starkweather, Mike (CNS)
[mailto:mike.starkweather at anheuser-busch.com]
Sent: Wednesday, October 18, 2000 5:20 PM
To: 'Dave Jones'; mrtg at list.ee.ethz.ch
Subject: RE: [mrtg] Archive script


Well, I copy the log files each night.  It creates a directory using the
current
date (20001018) then recreates the MRTG directory structure underneath it
with
the log files where they occur.  It could be extended to do more.  Here's my
code, for what it's worth.  I was a Perl newbie at the time.  Not much
better
now.

Schedule this line to run daily, I do it at 11:57 pm.

perl c:\whatever\bkuplog.pl

Here is the code for bkuplog.pl (running on Windows NT or 95).  If I recall
correctly, this is based on a contribution from around MRTG 2.5.3.  It's
probably still there and a lot better than this, but at the time it did not
support Windows.

#!perl -w
#
# Backup MRTG log files
#
# Create datestamped directory under backup root
# Traverse source directory tree from root
# Copy selected files from source to backup tree
#
# Assumes $bakroot directory exists

# set initial values
$srcroot = "c:/webdata/wwwroot/mrtg/";	# source directory root
$bakroot = "c:/backup/";			# backup directory root

$filcnt = 0;
$dircnt = 0;

# create daily backup directory
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$mon++;				# make relative to 1
$year += 1900;
$bkupymd = sprintf("%04d%02d%02d/",$year,$mon,$mday);
$bakroot .= $bkupymd;

# initialize directory list with source directory root
push (@dirs,$srcroot);		# set starting directory

# process the directory list
while ( defined ($x = shift @dirs) ) {

# create the backup directory if it does not exist
  $bakdir = $x;
  $bakdir =~ s/$srcroot/$bakroot/i;
  mkdir ($bakdir,666) unless ( -d $bakdir );

# change to the source directory
  chdir $x || die "Cannot change to $x ($!)";

# process all items in directory
  while ( defined($nextname = <*.*>) ) {

# got a directory
    if ( -d $nextname ) {
      push (@dirs,"$x$nextname/");
      $dircnt++;

# process desired files here
    } elsif ( -f $nextname && $nextname =~ /\.log$/i ) {	# <- set
pattern
      push (@files,"$x$nextname");
      $filcnt++;
    }
  }
}

# print results and copy files
print "\n";
print "backup log files for $bkupymd\n";
print "\n";
print "$dircnt directories\n";
print "$filcnt files\n";
print "\n";
foreach $x ( @files ) {
  $y = $x;
  $y =~ s/$srcroot/$bakroot/i;
  $x =~ s/\//\\/g;		# fix the slashes
  $y =~ s/\//\\/g;		# fix the slashes
  `copy $x $y` || die "unable to copy $x to $y\n";	# <- change copy
command
}


FWIW...Mike Starkweather

-----Original Message-----
From: Dave Jones [mailto:DJones at TheFund.com]
Sent: Wednesday, October 18, 2000 3:30 PM
To: mrtg at list.ee.ethz.ch
Subject: [mrtg] Archive script



Anybody written a .bat or .cmd file to run in NT to archive the output from
MRTG (.gif files, etc) into a different directory each time?  Like based on
the date or anything?

David Jones



--
Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Archive     http://www.ee.ethz.ch/~slist/mrtg
FAQ         http://faq.mrtg.org    Homepage     http://www.mrtg.org
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi

--
Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Archive     http://www.ee.ethz.ch/~slist/mrtg
FAQ         http://faq.mrtg.org    Homepage     http://www.mrtg.org
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the mrtg mailing list