Falko Timme
2013-11-21 0564653685f7fb1aebc1556361ad26e74076f750
- Added options to use a mounted backup directory. This allows for remote backups, e.g. vis sshfs to a backup server. The backup script checks if the backup directory is mounted, and if not, tries to mount it.
7 files modified
70 ■■■■■ changed files
install/tpl/server.ini.master 2 ●●●●● patch | view | raw | blame | history
interface/web/admin/form/server_config.tform.php 14 ●●●●● patch | view | raw | blame | history
interface/web/admin/lib/lang/de_server_config.lng 2 ●●●●● patch | view | raw | blame | history
interface/web/admin/lib/lang/en_server_config.lng 2 ●●●●● patch | view | raw | blame | history
interface/web/admin/templates/server_config_server_edit.htm 10 ●●●●● patch | view | raw | blame | history
server/cron_daily.php 23 ●●●●● patch | view | raw | blame | history
server/plugins-available/backup_plugin.inc.php 17 ●●●●● patch | view | raw | blame | history
install/tpl/server.ini.master
@@ -15,6 +15,8 @@
loglevel=2
admin_notify_events=1
backup_dir=/var/backup
backup_dir_is_mount=n
backup_dir_mount_cmd=
backup_mode=rootgz
monit_url=
monit_user=
interface/web/admin/form/server_config.tform.php
@@ -171,6 +171,20 @@
            'width' => '40',
            'maxlength' => '255'
        ),
        'backup_dir_is_mount' => array(
            'datatype' => 'VARCHAR',
            'formtype' => 'CHECKBOX',
            'default' => 'n',
            'value' => array(0 => 'n', 1 => 'y')
        ),
        'backup_dir_mount_cmd' => array(
            'datatype' => 'VARCHAR',
            'formtype' => 'TEXT',
            'default' => '',
            'value' => '',
            'width' => '40',
            'maxlength' => '255'
        ),
        'backup_mode' => array(
            'datatype' => 'VARCHAR',
            'formtype' => 'SELECT',
interface/web/admin/lib/lang/de_server_config.lng
@@ -188,4 +188,6 @@
$wb['munin_password_txt'] = 'Munin-Passwort';
$wb['munin_url_error_regex'] = 'Ungültige Munin-URL';
$wb['munin_url_note_txt'] = 'Platzhalter:';
$wb['backup_dir_is_mount_txt'] = 'Backupverzeichnis ist ein eigener Mount?';
$wb['backup_dir_mount_cmd_txt'] = 'Mount-Befehl, falls Backupverzeichnis nicht gemountet';
?>
interface/web/admin/lib/lang/en_server_config.lng
@@ -188,4 +188,6 @@
$wb['munin_password_txt'] = 'Munin Password';
$wb['munin_url_error_regex'] = 'Invalid Munin URL';
$wb['munin_url_note_txt'] = 'Placeholder:';
$wb['backup_dir_is_mount_txt'] = 'Backup directory is a mount?';
$wb['backup_dir_mount_cmd_txt'] = 'Mount command, if backup directory not mounted';
?>
interface/web/admin/templates/server_config_server_edit.htm
@@ -59,6 +59,16 @@
                <label for="backup_dir">{tmpl_var name='backup_dir_txt'}</label>
                <input name="backup_dir" id="backup_dir" value="{tmpl_var name='backup_dir'}" size="40" maxlength="255" type="text" class="textInput" />
            </div>
            <div class="ctrlHolder">
                <p class="label">{tmpl_var name='backup_dir_is_mount_txt'}</p>
                <div class="multiField">
                    {tmpl_var name='backup_dir_is_mount'}
                </div>
            </div>
            <div class="ctrlHolder">
                <label for="backup_dir_mount_cmd">{tmpl_var name='backup_dir_mount_cmd_txt'}</label>
                <input name="backup_dir_mount_cmd" id="backup_dir_mount_cmd" value="{tmpl_var name='backup_dir_mount_cmd'}" size="40" maxlength="255" type="text" class="textInput" />
            </div>
            <div class="ctrlHolder">
                <label for="backup_mode">{tmpl_var name='backup_mode_txt'}</label>
                <select name="backup_mode" id="backup_mode" class="selectInput">
server/cron_daily.php
@@ -562,7 +562,6 @@
$sql = "SELECT domain_id, domain, document_root, system_user FROM web_domain WHERE server_id = ".$conf['server_id'];
$records = $app->db->queryAllRecords($sql);
$app->uses('system');
if(is_array($records)) {
    foreach($records as $rec){
        $tmp_path = realpath(escapeshellcmd($rec['document_root'].'/tmp'));
@@ -1105,6 +1104,18 @@
        chmod(escapeshellcmd($backup_dir), $backup_dir_permissions);
    }
    //* mount backup directory, if necessary
    $run_backups = true;
    $server_config['backup_dir_mount_cmd'] = trim($server_config['backup_dir_mount_cmd']);
    if($server_config['backup_dir_is_mount'] == 'y' && $server_config['backup_dir_mount_cmd'] != ''){
        if(!$app->system->is_mounted($backup_dir)){
            exec(escapeshellcmd($server_config['backup_dir_mount_cmd']));
            sleep(1);
            if(!$app->system->is_mounted($backup_dir)) $run_backups = false;
        }
    }
    if($run_backups){
    $sql = "SELECT * FROM web_domain WHERE server_id = ".$conf['server_id']." AND (type = 'vhost' OR type = 'vhostsubdomain')";
    $records = $app->db->queryAllRecords($sql);
    if(is_array($records)) {
@@ -1197,7 +1208,6 @@
                unset($dir_handle);
                //* Remove backupdir symlink and create as directory instead
                $app->uses('system');
                $app->system->web_folder_protection($web_path, false);
                if(is_link($web_path.'/backup')) {
@@ -1325,6 +1335,15 @@
            }
        }
    }
    } else {
        //* send email to admin that backup directory could not be mounted
        $global_config = $app->getconf->get_global_config('mail');
        if($global_config['admin_mail'] != ''){
            $subject = 'Backup directory '.$backup_dir.' could not be mounted';
            $message = "Backup directory ".$backup_dir." could not be mounted.\n\nThe command\n\n".$server_config['backup_dir_mount_cmd']."\n\nfailed.";
            mail($global_config['admin_mail'], $subject, $message);
        }
    }
}
server/plugins-available/backup_plugin.inc.php
@@ -65,12 +65,24 @@
        if(is_array($backup)) {
            $app->uses('ini_parser,file,getconf');
            $app->uses('ini_parser,file,getconf,system');
            $web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$backup['parent_domain_id']);
            $server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
            $backup_dir = $server_config['backup_dir'].'/web'.$web['domain_id'];
            //* mount backup directory, if necessary
            $backup_dir_is_ready = true;
            $server_config['backup_dir_mount_cmd'] = trim($server_config['backup_dir_mount_cmd']);
            if($server_config['backup_dir_is_mount'] == 'y' && $server_config['backup_dir_mount_cmd'] != ''){
                if(!$app->system->is_mounted($backup_dir)){
                    exec(escapeshellcmd($server_config['backup_dir_mount_cmd']));
                    sleep(1);
                    if(!$app->system->is_mounted($backup_dir)) $backup_dir_is_ready = false;
                }
            }
            if($backup_dir_is_ready){
            //* Make backup available for download
            if($action_name == 'backup_download') {
                //* Copy the backup file to the backup folder of the website
@@ -123,6 +135,9 @@
                    }
                }
            }
            } else {
                $app->log('Backup directory not ready.', LOGLEVEL_DEBUG);
            }
        } else {
            $app->log('No backup with ID '.$backup_id.' found.', LOGLEVEL_DEBUG);