Perl Net::FTP:
http://aplawrence.com/Unixart/perlnetftp.html
Remotebackup.pl:
http://www.goldb.org/remotebackup.html
Crontab: a simple text file that holds a list of commands that are to be run at specified times
http://ubuntuforums.org/showthread.php?t=102625
My simple script for backup
===============================
#!/usr/bin/perl -w
#This is the backup script from Chenyang, version 0.1
#Questions please contact Chenyang: higooday@gmail.com
#use strict;
#use warnings;
#definitions and environments
my $email = 'xx@xx';
my $t_list= "xxxxx"; #list of directories to backup. txt file with each dir in one line
my $backup_dir ="xx/xx/xx"; #dir where the backup files are stored
my $backup_name = "xxx".datetime().".tar.gz";
my $log_name = "xxxx".datetime().".log";
my $startime=localtime();
print "Performing backup:$backup_name ...\nstarting at $startime\n";
system ("tar czvf $backup_dir/$backup_name -T $t_list >$backup_dir/$log_name");
my $finishtime=localtime();
print "\ndone! Finish time $finishtime\n";
print "Email backup conformation to $email ...";
email_notice($email,$backup_dir,$backup_name);
print "done!\n";
#############
sub datetime {
my ($sec, $min, $hour, $day, $month, $year) = (localtime)[0, 1, 2, 3, 4, 5];
my $datetime = sprintf "%02d-%02d-%02d-%02d.%02d.%02d",
$year + 1900, ($month + 1), $day, $hour, $min, $sec;
return $datetime;
}
sub email_notice {
my ($email, $backup_dir,$backup_name) = @_;
my $subject="Confirmation of backup";
my $time=localtime();
my $body="
A backup has finished at $time. The backup directory is: $backup_dir. The backup file is $backup_name. Please copy the backup file ASAP.
Chenyang
";
open(MAIL, "|/usr/lib/sendmail -t");
print MAIL "To: $email\n";
print MAIL "From: $email\n";
print MAIL "Subject: $subject\n";
print MAIL "$body\n";
close (MAIL);
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment