MN2LP config backup automation
This perl script shows how to automate the backup of the config for a NAS I bought (Sans Digital MN2LP).
#!/usr/bin/perl -w
# by Michael Mayer-Oakes
# 6/14/2009
use strict;
use CGI qw/-no_xhtml :form :cgi :escapeHTML/;
use WWW::Mechanize;
use diagnostics;
# change these
use constant BASEFOLDER => '/save/to/folder'; # where to save the config.ccyymmddhhmmss.tar file
my ($username, $password) = ('username', 'password'); # login to MN2LP
my $mn2lp = "mn2lp.yourdomain.com"; # could be an IP address as well
my $cgi = new CGI;
my $mech = WWW::Mechanize->new(onwarn => undef);
$mech->credentials($username, $password);
my $url = 'http://'.$mn2lp.'/cgi/saveConfig/saveConfigHandler.cgi';
$mech->get($url); # force config.tar to be rebuilt
$url = 'http://'.$mn2lp.'/config.tar';
$mech->get($url); # get config.tar
# debug
#print $mech->status()."\n";
#print $mech->content_type()."\n";
# generate name of file, config.(datetime).tar
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year += 1900; # adjust to actual year not just offset from 1900
$mon += 1; # change range to 1..12
$mon = sprintf("%02d", $mon);
$mday = sprintf("%02d", $mday);
$hour = sprintf("%02d", $hour);
$min = sprintf("%02d", $min);
$sec = sprintf("%02d", $sec);
my $filename = BASEFOLDER.'/config.'.$year.$mon.$mday.$hour.$min.$sec.'.tar';
# debug
#print $filename."\n";
# create file
open(FH, ">", $filename) || die "$0 Can't create $filename: $!\n";
# use write contents
print FH $mech->content();
# cleanup
close(FH);
# end of script
This along with a cron entry, something like so
30 0 * * * /path/to/script/backup.pl
And you are ready to go with your automated backup of the MN2LP's config