|
|
|
|
@@ -39,7 +39,7 @@ class ExportCron extends FroxlorCron
|
|
|
|
|
|
|
|
|
|
public static function run()
|
|
|
|
|
{
|
|
|
|
|
FroxlorLogger::getInstanceOf()->logAction(FroxlorLogger::CRON_ACTION, LOG_INFO, 'BackupCron: started - creating customer backup');
|
|
|
|
|
FroxlorLogger::getInstanceOf()->logAction(FroxlorLogger::CRON_ACTION, LOG_INFO, 'ExportCron: started - creating customer data export');
|
|
|
|
|
|
|
|
|
|
$result_tasks_stmt = Database::query("
|
|
|
|
|
SELECT * FROM `" . TABLE_PANEL_TASKS . "` WHERE `type` = '20' ORDER BY `id` ASC
|
|
|
|
|
@@ -65,11 +65,11 @@ class ExportCron extends FroxlorCron
|
|
|
|
|
|
|
|
|
|
// create folder if not exists
|
|
|
|
|
if (!file_exists($row['data']['destdir']) && $row['data']['destdir'] != '/' && $row['data']['destdir'] != Settings::Get('system.documentroot_prefix') && $row['data']['destdir'] != $customerdocroot) {
|
|
|
|
|
FroxlorLogger::getInstanceOf()->logAction(FroxlorLogger::CRON_ACTION, LOG_NOTICE, 'Creating backup-destination path for customer: ' . escapeshellarg($row['data']['destdir']));
|
|
|
|
|
FroxlorLogger::getInstanceOf()->logAction(FroxlorLogger::CRON_ACTION, LOG_DEBUG, 'Creating data export destination path for customer: ' . escapeshellarg($row['data']['destdir']));
|
|
|
|
|
FileDir::safe_exec('mkdir -p ' . escapeshellarg($row['data']['destdir']));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self::createCustomerBackup($row['data'], $customerdocroot, $cronlog);
|
|
|
|
|
self::createCustomerExport($row['data'], $customerdocroot, $cronlog);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -80,7 +80,7 @@ class ExportCron extends FroxlorCron
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* depending on the give choice, the customers web-data, email-data and databases are being backup'ed
|
|
|
|
|
* depending on the give choice, the customers web-data, email-data and databases are being exported
|
|
|
|
|
*
|
|
|
|
|
* @param array $data
|
|
|
|
|
*
|
|
|
|
|
@@ -88,19 +88,19 @@ class ExportCron extends FroxlorCron
|
|
|
|
|
*
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
private static function createCustomerBackup($data = null, $customerdocroot = null, &$cronlog = null)
|
|
|
|
|
private static function createCustomerExport($data = null, $customerdocroot = null, &$cronlog = null)
|
|
|
|
|
{
|
|
|
|
|
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_INFO, 'Creating Backup for user "' . $data['loginname'] . '"');
|
|
|
|
|
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_NOTICE, 'Creating data export for user "' . $data['loginname'] . '"');
|
|
|
|
|
|
|
|
|
|
// create tmp folder
|
|
|
|
|
$tmpdir = FileDir::makeCorrectDir($data['destdir'] . '/.tmp/');
|
|
|
|
|
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_DEBUG, 'Creating tmp-folder "' . $tmpdir . '"');
|
|
|
|
|
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_DEBUG, 'shell> mkdir -p ' . escapeshellarg($tmpdir));
|
|
|
|
|
FileDir::safe_exec('mkdir -p ' . escapeshellarg($tmpdir));
|
|
|
|
|
$create_backup_tar_data = "";
|
|
|
|
|
$create_export_tar_data = "";
|
|
|
|
|
|
|
|
|
|
// MySQL databases
|
|
|
|
|
if ($data['backup_dbs'] == 1) {
|
|
|
|
|
if ($data['dump_dbs'] == 1) {
|
|
|
|
|
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_DEBUG, 'Creating mysql-folder "' . FileDir::makeCorrectDir($tmpdir . '/mysql') . '"');
|
|
|
|
|
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_DEBUG, 'shell> mkdir -p ' . escapeshellarg(FileDir::makeCorrectDir($tmpdir . '/mysql')));
|
|
|
|
|
FileDir::safe_exec('mkdir -p ' . escapeshellarg(FileDir::makeCorrectDir($tmpdir . '/mysql')));
|
|
|
|
|
@@ -140,7 +140,7 @@ class ExportCron extends FroxlorCron
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($has_dbs) {
|
|
|
|
|
$create_backup_tar_data .= './mysql ';
|
|
|
|
|
$create_export_tar_data .= './mysql ';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (file_exists($mysqlcnf_file)) {
|
|
|
|
|
@@ -151,7 +151,7 @@ class ExportCron extends FroxlorCron
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// E-mail data
|
|
|
|
|
if ($data['backup_mail'] == 1) {
|
|
|
|
|
if ($data['dump_mail'] == 1) {
|
|
|
|
|
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_DEBUG, 'Creating mail-folder "' . FileDir::makeCorrectDir($tmpdir . '/mail') . '"');
|
|
|
|
|
FileDir::safe_exec('mkdir -p ' . escapeshellarg(FileDir::makeCorrectDir($tmpdir . '/mail')));
|
|
|
|
|
|
|
|
|
|
@@ -171,41 +171,41 @@ class ExportCron extends FroxlorCron
|
|
|
|
|
if (!empty($tar_file_list)) {
|
|
|
|
|
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_DEBUG, 'shell> tar cfvz ' . escapeshellarg(FileDir::makeCorrectFile($tmpdir . '/mail/' . $data['loginname'] . '-mail.tar.gz')) . ' -C ' . escapeshellarg($mail_homedir) . ' ' . trim($tar_file_list));
|
|
|
|
|
FileDir::safe_exec('tar cfz ' . escapeshellarg(FileDir::makeCorrectFile($tmpdir . '/mail/' . $data['loginname'] . '-mail.tar.gz')) . ' -C ' . escapeshellarg($mail_homedir) . ' ' . trim($tar_file_list));
|
|
|
|
|
$create_backup_tar_data .= './mail ';
|
|
|
|
|
$create_export_tar_data .= './mail ';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Web data
|
|
|
|
|
if ($data['backup_web'] == 1) {
|
|
|
|
|
if ($data['dump_web'] == 1) {
|
|
|
|
|
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_DEBUG, 'Creating web-folder "' . FileDir::makeCorrectDir($tmpdir . '/web') . '"');
|
|
|
|
|
FileDir::safe_exec('mkdir -p ' . escapeshellarg(FileDir::makeCorrectDir($tmpdir . '/web')));
|
|
|
|
|
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_DEBUG, 'shell> tar cfz ' . escapeshellarg(FileDir::makeCorrectFile($tmpdir . '/web/' . $data['loginname'] . '-web.tar.gz')) . ' --exclude=' . escapeshellarg(str_replace($customerdocroot, "./", FileDir::makeCorrectFile($tmpdir . '/*'))) . ' --exclude=' . escapeshellarg(str_replace($customerdocroot, "./", substr(FileDir::makeCorrectDir($tmpdir), 0, -1))) . ' -C ' . escapeshellarg($customerdocroot) . ' .');
|
|
|
|
|
FileDir::safe_exec('tar cfz ' . escapeshellarg(FileDir::makeCorrectFile($tmpdir . '/web/' . $data['loginname'] . '-web.tar.gz')) . ' --exclude=' . escapeshellarg(str_replace($customerdocroot, "./", FileDir::makeCorrectFile($tmpdir . '/*'))) . ' --exclude=' . escapeshellarg(str_replace($customerdocroot, "./", substr(FileDir::makeCorrectFile($tmpdir), 0, -1))) . ' -C ' . escapeshellarg($customerdocroot) . ' .');
|
|
|
|
|
$create_backup_tar_data .= './web ';
|
|
|
|
|
$create_export_tar_data .= './web ';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!empty($create_backup_tar_data)) {
|
|
|
|
|
if (!empty($create_export_tar_data)) {
|
|
|
|
|
// set owner to customer
|
|
|
|
|
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_DEBUG, 'shell> chown -R ' . (int)$data['uid'] . ':' . (int)$data['gid'] . ' ' . escapeshellarg($tmpdir));
|
|
|
|
|
FileDir::safe_exec('chown -R ' . (int)$data['uid'] . ':' . (int)$data['gid'] . ' ' . escapeshellarg($tmpdir));
|
|
|
|
|
// create tar-file
|
|
|
|
|
$backup_file = FileDir::makeCorrectFile($tmpdir . '/' . $data['loginname'] . '-backup_' . date('YmdHi', time()) . '.tar.gz' . (!empty($data['pgp_public_key']) ? '.gpg' : ''));
|
|
|
|
|
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_INFO, 'Creating backup-file "' . $backup_file . '"');
|
|
|
|
|
$export_file = FileDir::makeCorrectFile($tmpdir . '/' . $data['loginname'] . '-export_' . date('YmdHi', time()) . '.tar.gz' . (!empty($data['pgp_public_key']) ? '.gpg' : ''));
|
|
|
|
|
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_INFO, 'Creating export-file "' . $export_file . '"');
|
|
|
|
|
if (!empty($data['pgp_public_key'])) {
|
|
|
|
|
// pack all archives in tmp-dir to one archive and encrypt it with gpg
|
|
|
|
|
$recipient_file = FileDir::makeCorrectFile($tmpdir . '/' . $data['loginname'] . '-recipients.gpg');
|
|
|
|
|
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_INFO, 'Creating recipient-file "' . $recipient_file . '"');
|
|
|
|
|
file_put_contents($recipient_file, $data['pgp_public_key']);
|
|
|
|
|
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_DEBUG, 'shell> tar cfz - -C ' . escapeshellarg($tmpdir) . ' ' . trim($create_backup_tar_data) . ' | gpg --encrypt --recipient-file ' . escapeshellarg($recipient_file) . ' --output ' . escapeshellarg($backup_file) . ' --trust-model always --batch --yes');
|
|
|
|
|
FileDir::safe_exec('tar cfz - -C ' . escapeshellarg($tmpdir) . ' ' . trim($create_backup_tar_data) . ' | gpg --encrypt --recipient-file ' . escapeshellarg($recipient_file) . ' --output ' . escapeshellarg($backup_file) . ' --trust-model always --batch --yes', $return_value, ['|']);
|
|
|
|
|
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_DEBUG, 'shell> tar cfz - -C ' . escapeshellarg($tmpdir) . ' ' . trim($create_export_tar_data) . ' | gpg --encrypt --recipient-file ' . escapeshellarg($recipient_file) . ' --output ' . escapeshellarg($export_file) . ' --trust-model always --batch --yes');
|
|
|
|
|
FileDir::safe_exec('tar cfz - -C ' . escapeshellarg($tmpdir) . ' ' . trim($create_export_tar_data) . ' | gpg --encrypt --recipient-file ' . escapeshellarg($recipient_file) . ' --output ' . escapeshellarg($export_file) . ' --trust-model always --batch --yes', $return_value, ['|']);
|
|
|
|
|
} else {
|
|
|
|
|
// pack all archives in tmp-dir to one archive
|
|
|
|
|
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_DEBUG, 'shell> tar cfz ' . escapeshellarg($backup_file) . ' -C ' . escapeshellarg($tmpdir) . ' ' . trim($create_backup_tar_data));
|
|
|
|
|
FileDir::safe_exec('tar cfz ' . escapeshellarg($backup_file) . ' -C ' . escapeshellarg($tmpdir) . ' ' . trim($create_backup_tar_data));
|
|
|
|
|
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_DEBUG, 'shell> tar cfz ' . escapeshellarg($export_file) . ' -C ' . escapeshellarg($tmpdir) . ' ' . trim($create_export_tar_data));
|
|
|
|
|
FileDir::safe_exec('tar cfz ' . escapeshellarg($export_file) . ' -C ' . escapeshellarg($tmpdir) . ' ' . trim($create_export_tar_data));
|
|
|
|
|
}
|
|
|
|
|
// move to destination directory
|
|
|
|
|
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_DEBUG, 'shell> mv ' . escapeshellarg($backup_file) . ' ' . escapeshellarg($data['destdir']));
|
|
|
|
|
FileDir::safe_exec('mv ' . escapeshellarg($backup_file) . ' ' . escapeshellarg($data['destdir']));
|
|
|
|
|
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_DEBUG, 'shell> mv ' . escapeshellarg($export_file) . ' ' . escapeshellarg($data['destdir']));
|
|
|
|
|
FileDir::safe_exec('mv ' . escapeshellarg($export_file) . ' ' . escapeshellarg($data['destdir']));
|
|
|
|
|
// remove tmp-files
|
|
|
|
|
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_DEBUG, 'shell> rm -rf ' . escapeshellarg($tmpdir));
|
|
|
|
|
FileDir::safe_exec('rm -rf ' . escapeshellarg($tmpdir));
|
|
|
|
|
|