add simple backup-function for customers (testing state)

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2016-04-28 09:20:35 +02:00
parent a485d9f4f9
commit c8bbefb2bb
13 changed files with 554 additions and 88 deletions

View File

@@ -84,7 +84,7 @@ return array(
'value' => $result['registration_date'],
'size' => 10
),
'termination_date' => array(
'termination_date' => array(
'label' => $lng['domains']['termination_date'],
'desc' => $lng['panel']['dateformat'],
'type' => 'text',

View File

@@ -0,0 +1,70 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2016 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Formfields
*
*/
return array(
'backup' => array(
'title' => $lng['extras']['backup'],
'image' => 'icons/backup_big.png',
'sections' => array(
'section_a' => array(
'title' => $lng['extras']['backup'],
'image' => 'icons/backup_big.png',
'fields' => array(
'path' => array(
'label' => $lng['panel']['path'],
'desc' => (Settings::Get('panel.pathedit') != 'Dropdown' ? $lng['panel']['pathDescription'] : null).(isset($pathSelect['note']) ? '<br />'.$pathSelect['value'] : ''),
'type' => $pathSelect['type'],
'select_var' => $pathSelect['value'],
'value' => $pathSelect['value']
),
'backup_web' => array(
'label' => $lng['extras']['backup_web'],
'type' => 'checkbox',
'values' => array(
array(
'label' => $lng['panel']['yes'],
'value' => '1'
)
),
'value' => array('1')
),
'backup_mail' => array(
'label' => $lng['extras']['backup_mail'],
'type' => 'checkbox',
'values' => array(
array(
'label' => $lng['panel']['yes'],
'value' => '1'
)
),
'value' => array('1')
),
'backup_dbs' => array(
'label' => $lng['extras']['backup_dbs'],
'type' => 'checkbox',
'values' => array(
array(
'label' => $lng['panel']['yes'],
'value' => '1'
)
),
'value' => array('1')
)
)
)
)
)
);

View File

@@ -0,0 +1,116 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2016 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
*
*/
/**
* depending on the give choice, the customers web-data, email-data and databases are being backup'ed
*
* @param array $data
*
* @return void
*
*/
function createCustomerBackup($data = null, $customerdocroot = null, &$cronlog)
{
$cronlog->logAction(CRON_ACTION, LOG_INFO, 'Creating Backup for user "'.$data['loginname'].'"');
// create tmp folder
$tmpdir = makeCorrectDir($data['destdir'] . '/.tmp/');
$cronlog->logAction(CRON_ACTION, LOG_DEBUG, 'Creating tmp-folder "'.$tmpdir.'"');
$cronlog->logAction(CRON_ACTION, LOG_DEBUG, 'shell> mkdir -p ' . escapeshellarg($tmpdir));
safe_exec('mkdir -p ' . escapeshellarg($tmpdir));
$create_backup_tar = false;
// MySQL databases
if ($data['backup_dbs'] == 1) {
$cronlog->logAction(CRON_ACTION, LOG_DEBUG, 'Creating mysql-folder "'.makeCorrectDir($tmpdir . '/mysql').'"');
$cronlog->logAction(CRON_ACTION, LOG_DEBUG, 'shell> mkdir -p ' . escapeshellarg(makeCorrectDir($tmpdir . '/mysql')));
safe_exec('mkdir -p ' . escapeshellarg(makeCorrectDir($tmpdir . '/mysql')));
// get all customer database-names
$sel_stmt = Database::prepare("SELECT `databasename` FROM `" . TABLE_PANEL_DATABASES . "` WHERE `customerid` = :cid");
Database::pexecute($sel_stmt, array(
'cid' => $data['customerid']
));
Database::needRoot(true);
Database::needSqlData();
$sql_root = Database::getSqlData();
Database::needRoot(false);
while ($row = $sel_stmt->fetch()) {
$cronlog->logAction(CRON_ACTION, LOG_DEBUG, 'shell> mysqldump -u ' . escapeshellarg($sql_root['user']) . ' -pXXXXX ' . $row['databasename'] . ' > ' . makeCorrectFile($tmpdir . '/mysql/' . $row['databasename'] . '_' . date('YmdHi', time()) . '.sql'));
$bool_false = false;
safe_exec('mysqldump -u ' . escapeshellarg($sql_root['user']) . ' -p' . $sql_root['passwd'] . ' ' . $row['databasename'] . ' > ' . makeCorrectFile($tmpdir . '/mysql/' . $row['databasename'] . '_' . date('YmdHi', time()) . '.sql'), $bool_false, array('>'));
$create_backup_tar = true;
}
unset($sql_root);
}
// E-mail data
if ($data['backup_mail'] == 1) {
$cronlog->logAction(CRON_ACTION, LOG_DEBUG, 'Creating mail-folder "'.makeCorrectDir($tmpdir . '/mail').'"');
safe_exec('mkdir -p ' . escapeshellarg(makeCorrectDir($tmpdir . '/mail')));
// get all customer mail-accounts
$sel_stmt = Database::prepare("SELECT CONCAT(`homedir`, `maildir`) as acc_path FROM `" . TABLE_MAIL_USERS . "` WHERE `customerid` = :cid");
Database::pexecute($sel_stmt, array(
'cid' => $data['customerid']
));
$tar_file_list = "";
while ($row = $sel_stmt->fetch()) {
$tar_file_list .= $row['acc_path'] . " ";
}
if (! empty($tar_file_list)) {
$cronlog->logAction(CRON_ACTION, LOG_DEBUG, 'shell> tar cfvz ' . escapeshellarg(makeCorrectFile($tmpdir . '/mail/' . $data['loginname'] . '-mail.tar.gz')) . ' ' . escapeshellarg(trim($tar_file_list)));
safe_exec('tar cfz ' . escapeshellarg(makeCorrectFile($tmpdir . '/mail/' . $data['loginname'] . '-mail.tar.gz')) . ' ' . escapeshellarg(trim($tar_file_list)));
$create_backup_tar = true;
}
}
// Web data
if ($data['backup_web'] == 1) {
$cronlog->logAction(CRON_ACTION, LOG_DEBUG, 'Creating web-folder "'.makeCorrectDir($tmpdir . '/web').'"');
safe_exec('mkdir -p ' . escapeshellarg(makeCorrectDir($tmpdir . '/web')));
$cronlog->logAction(CRON_ACTION, LOG_DEBUG, 'shell> tar cfvz ' . escapeshellarg(makeCorrectFile($tmpdir . '/web/' . $data['loginname'] . '-web.tar.gz')) . ' --exclude ' . escapeshellarg($tmpdir) .' ' . escapeshellarg($customerdocroot));
safe_exec('tar cfz ' . escapeshellarg(makeCorrectFile($tmpdir . '/web/' . $data['loginname'] . '-web.tar.gz')) . ' --exclude ' . escapeshellarg($tmpdir) .' ' . escapeshellarg($customerdocroot));
$create_backup_tar = true;
}
if ($create_backup_tar)
{
$backup_file = makeCorrectFile($tmpdir . '/' . $data['loginname'] . '-backup_' . date('YmdHi', time()) . '.tar.gz');
$cronlog->logAction(CRON_ACTION, LOG_INFO, 'Creating backup-file "'.$backup_file.'"');
// pack all archives in tmp-dir to one
$cronlog->logAction(CRON_ACTION, LOG_DEBUG, 'shell> tar cfvz ' . escapeshellarg($backup_file) . ' ' . escapeshellarg($tmpdir));
safe_exec('tar cfz ' . escapeshellarg($backup_file) . ' ' . escapeshellarg($tmpdir));
// move to destination directory
$cronlog->logAction(CRON_ACTION, LOG_DEBUG, 'shell> mv ' . escapeshellarg($backup_file) . ' ' . escapeshellarg($data['destdir']));
safe_exec('mv ' . escapeshellarg($backup_file) . ' ' . escapeshellarg($data['destdir']));
// remove tmp-files
$cronlog->logAction(CRON_ACTION, LOG_DEBUG, 'shell> rm -rf '.escapeshellarg($tmpdir));
safe_exec('rm -rf '.escapeshellarg($tmpdir));
// set owner to customer
$cronlog->logAction(CRON_ACTION, LOG_DEBUG, 'shell> chown -R ' . (int)$data['uid'] . ':' . (int)$data['gid'] . ' ' . escapeshellarg($data['destdir']));
safe_exec('chown -R ' . (int)$data['uid'] . ':' . (int)$data['gid'] . ' ' . escapeshellarg($data['destdir']));
}
}

View File

@@ -101,5 +101,10 @@ function inserttask($type, $param1 = '', $param2 = '', $param3 = '', $param4 = '
$data = serialize($data);
Database::pexecute($ins_stmt, array('type' => '8', 'data' => $data));
} elseif ($type == '20'
&& is_array($param1)
) {
$data = serialize($param1);
Database::pexecute($ins_stmt, array('type' => '20', 'data' => $data));
}
}

View File

@@ -124,11 +124,15 @@ return array (
'url' => 'customer_extras.php?page=htaccess',
'label' => $lng['menue']['extras']['pathoptions'],
),
array (
'url' => 'customer_logger.php?page=log',
'label' => $lng['menue']['logger']['logger'],
'show_element' => ( Settings::Get('logger.enabled') == true )
),
array (
'url' => 'customer_logger.php?page=log',
'label' => $lng['menue']['logger']['logger'],
'show_element' => ( Settings::Get('logger.enabled') == true )
),
array (
'url' => 'customer_extras.php?page=backup',
'label' => $lng['menue']['extras']['backup'],
),
),
),
'traffic' => array (