El siguiente Script nos ayuda a respaldar una base de datos Mysql(tipo ISAM) de tamaño moderado(Max 10Mb), dicho respaldo sera depositado en la bandeja de correo que el Sysadmin crea conveniente.
Nota: Si este respaldo se realiza de manera frecuente, recomiendo que se anexe como una tarea semanal en el cron
#!/usr/bin/perl use Archive::Zip; use MIME::Lite; use Net::SMTP; #### Llenar por usuario ###### my $from_address = 'edwinplauchu@micronesia.com'; my $to_address = 'edson.estrella@microsiga.com'; my $mail_host = 'pop3.microsiga.com.br'; my $subject = 'Microsiga Wiki Backup...'; my $message_body = "Anexo a este correo el respaldo semanal de nuestro amado wiki"; ############################## ### Aqui inicia el codigo perl ofuscado#### #BEGIN ####################### #01.- Mysqldump ZIP system("/usr/bin/mysqldump -u root -ph1st3r14 mediawiki > mediawiki.sql"); $obj = Archive::Zip->new(); # new instance @files = ('mediawiki.sql'); # files to store foreach $file (@files){ $obj->addFile($file); } if ($obj->writeToFileNamed('my_file.zip') != AZ_OK) { # write to disk print "Error in archive creation!";} else { print "Archive created successfully!"; } ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); $year += 1900; $mon += 1; my $my_file_zip = 'my_file.zip'; my $your_file_zip = "mediawiki-mysql-" . $mon . "-" . $mday . "-" . $year . ".sql.zip"; #02.- Send Mail with ZIP ### Create the multipart container $msg = MIME::Lite->new ( From => $from_address, To => $to_address, Subject => $subject, Type =>'multipart/mixed' ) or die "Error no puede crearce el respaldo del wiki: $!n"; ### Add the text message part $msg->attach ( Type => 'TEXT', Data => $message_body ) or die "Error adding the text message part: $!n"; ### Add the ZIP file $msg->attach ( Type => 'application/zip', Path => $my_file_zip, Filename => $your_file_zip, Disposition => 'attachment' ) or die "Error adding $file_zip: $!n"; MIME::Lite->send('smtp', $mail_host, Timeout=>60); $msg->send; #END #########################
