No probs, see code snippet attached.
Many thanks
#!/usr/bin/perl
use strict;
use MIME::Lite;
use DBI;
open(STDOUT, ">/dev/null");
open(STDERR, ">/dev/null");
## Set your e-mail address
my $email = '';
## Set the message of the backup e-mail
my $subject = 'Database Backup';
## Set your cpanel username
my $user = '';
## Set your cpanel password
my $pass = '';
my @databases;
my $dbh = DBI->connect('DBI:mysql::localhost', $user, $pass);
my $sth = $dbh->prepare("show databases");
$sth->execute;
while (my($db) = $sth->fetchrow_array) {
push(@databases, $db);
}
$sth->finish;
$dbh->disconnect();
if (!-d "/home/" . $user . "/sqldumps") {
system("mkdir","-p","/home/" . $user . "/sqldumps");
}
foreach my $database (@databases) {
system("/usr/bin/mysqldump -u " . $user . " -p" . $pass . " " . $database . " >/home/" . $user . "/sqldumps/" . $database . ".sql");
}
my $mime_msg = MIME::Lite->new(
To => $email,
Subject => $subject,
Type =>'multipart/mixed'
);
foreach my $database (@databases) {
$mime_msg->attach (
Path => "/home/" . $user . "/sqldumps/" . $database . ".sql",
Disposition => 'attachment'
);
}
MIME::Lite->send('sendmail', "/usr/sbin/sendmail -t -oi");
$mime_msg->send();
foreach my $database (@databases) {
unlink("/home/" . $user . "/sqldumps/" . $database . ".sql");
}
close(STDERR);
close(STDOUT);
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61:





by: bounsyPosted on 2009-07-23 at 11:07:42ID: 24928197
Can you cut and paste the code? EE is not letting me view the attachment.