mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-02-19 04:13:18 +08:00
Backup plugin use tar stream
This commit is contained in:
parent
d1bab197c1
commit
f1c6ff3f2a
2 changed files with 26 additions and 21 deletions
plugins/backup
|
@ -30,31 +30,36 @@ class BackupPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
return $this->jsonResponse(__FUNCTION__, false);
|
||||
}
|
||||
|
||||
$sZipHash = \MailSo\Base\Utils::Sha1Rand();
|
||||
$sZipFileName = APP_PRIVATE_DATA . $sZipHash . '.zip';
|
||||
|
||||
\file_put_contents(APP_PRIVATE_DATA.'cache/CACHEDIR.TAG', 'Signature: 8a477f597d28d172789f06886806bc55');
|
||||
|
||||
if (\class_exists('ZipArchive')) {
|
||||
// $oZip = new \ZipArchive();
|
||||
// $oZip->open($sZipFileName, \ZIPARCHIVE::CREATE | \ZIPARCHIVE::OVERWRITE);
|
||||
// $oZip->setArchiveComment('SnappyMail/'.APP_VERSION);
|
||||
$sFileName = APP_PRIVATE_DATA . \MailSo\Base\Utils::Sha1Rand();
|
||||
|
||||
if (false) {
|
||||
$sFileName .= '.zip';
|
||||
if (\class_exists('ZipArchive')) {
|
||||
// $oArchive = new \ZipArchive();
|
||||
// $oArchive->open($sFileName, \ZIPARCHIVE::CREATE | \ZIPARCHIVE::OVERWRITE);
|
||||
// $oArchive->setArchiveComment('SnappyMail/'.APP_VERSION);
|
||||
}
|
||||
$oArchive = new \SnappyMail\Stream\ZIP($sFileName);
|
||||
} else {
|
||||
$sFileName .= '.tgz';
|
||||
$oArchive = new \SnappyMail\Stream\TAR($sFileName);
|
||||
}
|
||||
|
||||
$oZip = new \SnappyMail\Stream\ZIP($sZipFileName);
|
||||
// $oZip->addRecursive(APP_PRIVATE_DATA, '#/(cache.*)#');
|
||||
$oZip->addRecursive(APP_PRIVATE_DATA.'configs', 'configs');
|
||||
$oZip->addRecursive(APP_PRIVATE_DATA.'domains', 'domains');
|
||||
$oZip->addRecursive(APP_PRIVATE_DATA.'plugins', 'plugins');
|
||||
$oZip->addRecursive(APP_PRIVATE_DATA.'storage', 'storage');
|
||||
// $oArchive->addRecursive(APP_PRIVATE_DATA, '#/(cache.*)#');
|
||||
$oArchive->addRecursive(APP_PRIVATE_DATA.'configs', 'configs');
|
||||
$oArchive->addRecursive(APP_PRIVATE_DATA.'domains', 'domains');
|
||||
$oArchive->addRecursive(APP_PRIVATE_DATA.'plugins', 'plugins');
|
||||
$oArchive->addRecursive(APP_PRIVATE_DATA.'storage', 'storage');
|
||||
if (\is_readable(APP_PRIVATE_DATA.'AddressBook.sqlite')) {
|
||||
$oZip->addFile(APP_PRIVATE_DATA.'AddressBook.sqlite');
|
||||
$oArchive->addFile(APP_PRIVATE_DATA.'AddressBook.sqlite');
|
||||
}
|
||||
// $oZip->addFile(APP_DATA_FOLDER_PATH.'SALT.php');
|
||||
$oZip->close();
|
||||
// $oArchive->addFile(APP_DATA_FOLDER_PATH.'SALT.php');
|
||||
$oArchive->close();
|
||||
|
||||
$data = \base64_encode(\file_get_contents($sZipFileName));
|
||||
\unlink($sZipFileName);
|
||||
$data = \base64_encode(\file_get_contents($sFileName));
|
||||
\unlink($sFileName);
|
||||
|
||||
return $this->jsonResponse(__FUNCTION__, array(
|
||||
'zip' => $data
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
});
|
||||
} else {
|
||||
var link = document.createElement("a");
|
||||
link.download = 'backup-' + Date.now() + '.zip';
|
||||
link.href = 'data:application/zip;base64,' + oData.Result.zip;
|
||||
link.textContent = 'backup.zip';
|
||||
link.download = oData.Result.name;
|
||||
link.href = oData.Result.data;
|
||||
link.textContent = oData.Result.name;
|
||||
this.viewModelDom.append(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
|
|
Loading…
Reference in a new issue