我找到了这个 PHP 代码。它从您的网站备份文件和数据库到保管箱。
<?php
// Set the timezone so filenames are correct
date_default_timezone_set('Europe/London');
// Dropbox username/password
$dropbox_email='dropbox@dropbox.com';
$dropbox_pass='password';
// MySQL username/password/db name
$mysql_database='mysql_database';
$mysql_username='mysql_username';
$mysql_password='password';
// Filenames for backup files
$backup_dbname = "database_" . date("Y.m.d-H.i.s_l") . '.sql.gz';
$backup_files = "files_" . date("Y.m.d-h.i.s_l") . '.tgz';
// File to backup
$siteroot = "/site/home/public_html/";
// Backup database, obviously you can tweak the mysqldump switches
// Backup is GZipped.
system("mysqldump -h localhost -u $mysql_username --password=$mysql_password $mysql_database --complete-insert | gzip > $backup_dbname");
// Backup all files in public_html apart from the gz
system("tar -czvf $backup_files $siteroot");
include("DropboxUploader.php");
$uploader = new DropboxUploader($dropbox_email, $dropbox_pass);
$uploader->upload($backup_files,'Backup/Files/');
$uploader->upload($backup_dbname,'Backup/Database/');
system("rm $backup_files");
system("rm $backup_dbname");
?>
我想备份文件 $backup_files = "files_" 。日期(“Ymd-his_l”)。'.tgz'; 压缩不是 tgz。当我用 'zip' 替换 'tgz' 时,zip 文件没有打开。我还尝试添加'$createZip = new createZip;' 但它根本没有创建 zip 文件。
对于我的情况,我更喜欢 zip 而不是 tgz。