From OrganicDesign
#!/usr/bin/perl
# - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
# - Author: http://www.organicdesign.co.nz/nad
use POSIX qw(strftime setsid);
use HTTP::Request;
use LWP::UserAgent;
$dir = '/home/nad';
$date = strftime('%Y-%m-%d',localtime);
$ua = LWP::UserAgent->new(cookie_jar => {},agent => 'Mozilla/5.0',timeout => 10,max_size => 1024);
# Return size of passed file in MB
sub size { return (int([stat shift]->[7]/104857.6+0.5)/10).'MB'; }
# Post a comment to the wiki's server-log article
sub comment {
$comment = shift;
%data = (title => 'Server log',content => "*$comment",summary => $comment,caction => 'append');
$post = $ua->post('http://www.organicdesign.co.nz/wiki/index.php',\%data);
}
# Backup and compress databases
$s7z = "all-$date.sql.7z";
$sql = "$dir/all.sql";
qx( mysqldump -u root --password='**********' -A >$sql );
qx( 7za a $dir/$s7z $sql );
qx( chmod 644 $dir/$s7z );
comment "DB backup: $s7z (".size($sql)."/".size("$dir/$s7z").")";
# Backup and compress file structure (weekly)
if ($date =~ /[0-9]+-[0-9]+-(01|09|16|24)/) {
$t7z = "www-$date.t7z";
$tar = "$dir/www.tar";
qx( tar -cf $tar /var/www );
qx( 7za a $dir/$t7z $tar );
qx( chmod 644 $dir/$s7z );
comment "FS backup: $t7z (".size($tar)."/".size("$dir/$t7z").")";
}