Perl implements a blog backup script code _perl

Source: Internet
Author: User
Always do not pay attention to their own blog, the last lost just love dearly, now pay attention to it, decided to regularly back up the SQL. Write a small script as follows:
Copy Code code as follows:

#!/usr/bin/perl
Use warnings;
Use strict;
Use Mysql::backup;
Use Mail::sender;
Open My $tmp _sql, ' > ', ' Backup.sql ';
My $mb = new Mysql::backup (' dbname ', ' localhost ', ' dbuser ', ' dbpasswd ', {' Use_replace ' => 1, ' Show_table_names ' => 1 });
Print $tmp _sql $mb->create_structure ();
Print $tmp _sql $mb->data_backup ();
Close $tmp _sql;
My $sender = new Mail::sender {smtp => ' smtp.163.com ',
From => ' mailuser@163.com ',
# debug => ' Backup_debug.log ',
Auth => ' LOGIN ',
Authid => ' Mailuser ',
Authpwd => ' mailpasswd ',
};
$sender->mailfile ({to => ' mailuser@gmail.com '),
Subject => ' Backup Blog sql_ '. Time (),
msg => ' 3Q ',
File => ' Backup.sql ',});

Instead of using mysqldump directly, we looked for the Mysql::backup module and tried to see the exported SQL, and Mysqldump's results were somewhat different. The SQL generic structure that mysqldump exports is this way:
Copy Code code as follows:

DROP TABLE IF EXISTS ' tablename ';
CREATE TABLE ' tablename ' (ID INT not NULL ...);
LOCK TABLES ' tablename ' warite;
INSERT into ' tablename ' VALUES (...), (...), (...);
UNLOCK TABLES;

The SQL structure exported by Mysql::backup is this:
Copy Code code as follows:

CREATE TABLE ' tablename ' (ID INT not NULL ...);
REPLACE into ' tablename ' (ID,...) VALUES (1,...);
REPLACE into ' tablename ' (ID,...) VALUES (2,...);

In fact, I'm not quite sure that REPLACE the insert is good, but the pod on the example used use_replace=> ' 1 ', copied, if the custom insert, in the new build object, do not use this param on the line. In addition this Mail::sender module, is in micro-blog on a comment, found a lot of friends in use, I will give up a net::smtp_auth, with a try, feel good ~ ~
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.