- 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.
| | |
| | | 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= |
| | |
| | | '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', |
| | |
| | | $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'; |
| | | ?> |
| | |
| | | $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'; |
| | | ?> |
| | |
| | | <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"> |
| | |
| | | |
| | | $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')); |
| | |
| | | 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)) { |
| | |
| | | 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')) { |
| | |
| | | } |
| | | } |
| | | } |
| | | } 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); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | 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 |
| | |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | $app->log('Backup directory not ready.', LOGLEVEL_DEBUG); |
| | | } |
| | | |
| | | } else { |
| | | $app->log('No backup with ID '.$backup_id.' found.', LOGLEVEL_DEBUG); |