My QQ mailbox has a capacity of 16G. It is said that the capacity is unlimited and will automatically increase. If it is used to back up websites on vps, it does not take up space and is convenient, wouldn’t it be great! There is a way. After packaging, use sendmail to send to QQ mailbox, it is simple and fast.
I am relatively familiar with PHP and use PHPMailer-Lite to call sendmail to send backup files. If you cannot use sendmail, you can use smtp to send, but it is slower.
If the attachments of a large website are stored on a daily basis, you can also use this method to package and back up attachments on a daily basis. Anyway, QQ mail has unlimited capacity, so there is no need to use it in vain.
Need to download http://nchc.dl.sourceforge.net/PRoject/phpmailer/phpmailer%20for%20php5_6/PHPMailer-Lite%20v5.1/PHPMailer-Lite_v5.1.zip
The following is the quoted content:
<?php
/**
* Blog backup and send to email
* Very convenient and suitable for small site backup
*
* usage:
* /usr/local/php/bin/php /path/to/mailbackup.php
*
* @author Pan Chunmeng<cmpan(at)qq.com>
* @link <a href=" http://yulans.cn/php/mail-backup">yulans.cn</a >
* @license NEWBSD
*/
//require_once('class.phpmailer-lite.php');
require_once('PHPMailerLite.php');
// set up
$mailTo = '[email protected]' ; // Which email address to send to
$mailFrom = '[email protected]' ; // Email address for sending attachments
$dataDir = '/data/MySQL/3306/data/yulans/'; // MySQL database path of the website
$attDir = '/web/yulans.cn/www/wp-content/uploads/'; // Attachment path
$dataBakFile = 'uploads.yulans.cn.gz';
$attBakFile = 'data.yulans.cn.gz';
date_default_timezone_set('Asia/Shanghai'); // PHP 5 >= 5.2.0
$gzPre = date('Ymd-His-');
print "Backup Message:n";
print "backup start:".date('Ymd H:i:s')."n";
//Package attachments
$attGz = "/tmp/{$gzPre}{$attBakFile}"; // Compressed attachment package to be sent
system("tar zcf $attGz $attDir");
print "$attGz finish!n";
//Copy the database file and package it
$dbGz = "/tmp/{$gzPre}{$dataBakFile}"; // Attachment database compression package to be sent
$dbTmp = "/tmp/{$gzPre}db_bak_tmp";
system("cp -R $dataDir $dbTmp");
system("tar zcf $dbGz $dbTmp");
print "$dbGz finish!n";
$mail = new PHPMailerLite(true);
$mail->IsSendmail();
try {
$msg = '';
$mail->SetFrom($mailFrom, 'Bak');
$mail->AddAddress($mailTo, 'cm pan');
$mail->Subject = 'Yulans.cn backup';
$mail->AltBody = date('Ymd H:i:s').'!';
$mail->MsgHTML(date('Ymd H:i:s').'! OK');
//Add attachment
if(file_exists($attGz)) {
$mail->AddAttachment($attGz);
$msg .= "AddAttachment $attGz finish!<br />n";
} else {
$msg .= "Attachment $attGz not exists!<br />n";
}
if(file_exists($dbGz)) {
$mail->AddAttachment($dbGz);
$msg .= "AddAttachment $dbGz finish!<br />n";
} else {
$msg .= "Attachment $dbGz not exists!<br />n";
}
print $msg;
$mail->MsgHTML($msg);
$mail->Send();
} catch (phpmailerException $e) {
echo $e->errorMessage();
} catch (Exception $e) {
echo $e->getMessage();
}
// Delete temporary files
system("rm -f $attGz");
system("rm -f $dbGz");
system("rm -rf $dbTmp");
print "Backup Finishn";
After all the above file contents are uploaded to the server, create a new file in /etc/cron.daily/ to let the system run the backup script on a daily basis. The content is:
#!/bin/sh
/webserver/php/bin/php /path/to/worker.php #The path of the above php script