Commit fe5f5359 authored by Falko Timme's avatar Falko Timme

- It is now possible to exclude directories - on a per-vHost base - from website backups.

parent d04604ab
ALTER TABLE `web_domain` ADD `backup_excludes` MEDIUMTEXT NULL AFTER `backup_copies` ;
\ No newline at end of file
...@@ -1796,6 +1796,7 @@ CREATE TABLE `web_domain` ( ...@@ -1796,6 +1796,7 @@ CREATE TABLE `web_domain` (
`custom_php_ini` mediumtext, `custom_php_ini` mediumtext,
`backup_interval` VARCHAR( 255 ) NOT NULL DEFAULT 'none', `backup_interval` VARCHAR( 255 ) NOT NULL DEFAULT 'none',
`backup_copies` INT NOT NULL DEFAULT '1', `backup_copies` INT NOT NULL DEFAULT '1',
`backup_excludes` mediumtext,
`active` enum('n','y') NOT NULL default 'y', `active` enum('n','y') NOT NULL default 'y',
`traffic_quota_lock` enum('n','y') NOT NULL default 'n', `traffic_quota_lock` enum('n','y') NOT NULL default 'n',
`fastcgi_php_version` varchar(255) DEFAULT NULL, `fastcgi_php_version` varchar(255) DEFAULT NULL,
......
...@@ -520,6 +520,18 @@ $form["tabs"]['backup'] = array ( ...@@ -520,6 +520,18 @@ $form["tabs"]['backup'] = array (
'default' => '', 'default' => '',
'value' => array('1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', '10' => '10') 'value' => array('1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', '10' => '10')
), ),
'backup_excludes' => array (
'datatype' => 'VARCHAR',
'validators' => array ( 0 => array ( 'type' => 'REGEX',
'regex' => '@^(?!.*\.\.)[-a-zA-Z0-9_/.~,]*$@',
'errmsg'=> 'backup_excludes_error_regex'),
),
'formtype' => 'TEXT',
'default' => '',
'value' => '',
'width' => '30',
'maxlength' => '255'
),
//################################# //#################################
// ENDE Datatable fields // ENDE Datatable fields
//################################# //#################################
......
...@@ -510,6 +510,18 @@ $form["tabs"]['backup'] = array ( ...@@ -510,6 +510,18 @@ $form["tabs"]['backup'] = array (
'default' => '', 'default' => '',
'value' => array('1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', '10' => '10') 'value' => array('1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', '10' => '10')
), ),
'backup_excludes' => array (
'datatype' => 'VARCHAR',
'validators' => array ( 0 => array ( 'type' => 'REGEX',
'regex' => '@^(?!.*\.\.)[-a-zA-Z0-9_/.~,]*$@',
'errmsg'=> 'backup_excludes_error_regex'),
),
'formtype' => 'TEXT',
'default' => '',
'value' => '',
'width' => '30',
'maxlength' => '255'
),
//################################# //#################################
// ENDE Datatable fields // ENDE Datatable fields
//################################# //#################################
......
...@@ -121,4 +121,9 @@ $wb['invalid_rewrite_rules_txt'] = 'Unzulässige Rewrite Rules'; ...@@ -121,4 +121,9 @@ $wb['invalid_rewrite_rules_txt'] = 'Unzulässige Rewrite Rules';
$wb['allowed_rewrite_rule_directives_txt'] = 'Erlaubte Direktiven:'; $wb['allowed_rewrite_rule_directives_txt'] = 'Erlaubte Direktiven:';
$wb['configuration_error_txt'] = 'KONFIGURATIONSFEHLER'; $wb['configuration_error_txt'] = 'KONFIGURATIONSFEHLER';
$wb['variables_txt'] = 'Variablen'; $wb['variables_txt'] = 'Variablen';
$wb['added_by_txt'] = 'Hinzugefügt von';
$wb['added_date_txt'] = 'Hinzugefügt am';
$wb['backup_excludes_txt'] = 'Auszuschließende Verzeichnisse';
$wb['backup_excludes_note_txt'] = '(Mehrere Verzeichnisse mit Kommas trennen)';
$wb['backup_excludes_error_regex'] = 'Die auszuschließenden Verzeichnisse enthalten ungültige Zeichen.';
?> ?>
\ No newline at end of file
...@@ -119,4 +119,8 @@ $wb['rewrite_rules_txt'] = 'Rewrite Rules'; ...@@ -119,4 +119,8 @@ $wb['rewrite_rules_txt'] = 'Rewrite Rules';
$wb['invalid_rewrite_rules_txt'] = 'Unzulässige Rewrite Rules'; $wb['invalid_rewrite_rules_txt'] = 'Unzulässige Rewrite Rules';
$wb['allowed_rewrite_rule_directives_txt'] = 'Erlaubte Direktiven:'; $wb['allowed_rewrite_rule_directives_txt'] = 'Erlaubte Direktiven:';
$wb['configuration_error_txt'] = 'KONFIGURATIONSFEHLER'; $wb['configuration_error_txt'] = 'KONFIGURATIONSFEHLER';
$wb['variables_txt'] = 'Variablen';
$wb['backup_excludes_txt'] = 'Auszuschließende Verzeichnisse';
$wb['backup_excludes_note_txt'] = '(Mehrere Verzeichnisse mit Kommas trennen)';
$wb['backup_excludes_error_regex'] = 'Die auszuschließenden Verzeichnisse enthalten ungültige Zeichen.';
?> ?>
\ No newline at end of file
...@@ -123,4 +123,7 @@ $wb['configuration_error_txt'] = "CONFIGURATION ERROR"; ...@@ -123,4 +123,7 @@ $wb['configuration_error_txt'] = "CONFIGURATION ERROR";
$wb['variables_txt'] = 'Variables'; $wb['variables_txt'] = 'Variables';
$wb['added_by_txt'] = 'Added by'; $wb['added_by_txt'] = 'Added by';
$wb['added_date_txt'] = 'Added date'; $wb['added_date_txt'] = 'Added date';
$wb['backup_excludes_txt'] = 'Excluded Directories';
$wb['backup_excludes_note_txt'] = '(Separate multiple directories with commas)';
$wb['backup_excludes_error_regex'] = 'The excluded directories contain invalid characters.';
?> ?>
\ No newline at end of file
...@@ -120,4 +120,8 @@ $wb['rewrite_rules_txt'] = 'Rewrite Rules'; ...@@ -120,4 +120,8 @@ $wb['rewrite_rules_txt'] = 'Rewrite Rules';
$wb['invalid_rewrite_rules_txt'] = 'Invalid Rewrite Rules'; $wb['invalid_rewrite_rules_txt'] = 'Invalid Rewrite Rules';
$wb['allowed_rewrite_rule_directives_txt'] = 'Allowed Directives:'; $wb['allowed_rewrite_rule_directives_txt'] = 'Allowed Directives:';
$wb['configuration_error_txt'] = "CONFIGURATION ERROR"; $wb['configuration_error_txt'] = "CONFIGURATION ERROR";
$wb['variables_txt'] = 'Variables';
$wb['backup_excludes_txt'] = 'Auszuschließende Verzeichnisse';
$wb['backup_excludes_note_txt'] = '(Mehrere Verzeichnisse mit Kommas trennen)';
$wb['backup_excludes_error_regex'] = 'Die auszuschließenden Verzeichnisse enthalten ungültige Zeichen.';
?> ?>
\ No newline at end of file
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
<select name="backup_copies" id="backup_copies" class="selectInput"> <select name="backup_copies" id="backup_copies" class="selectInput">
{tmpl_var name='backup_copies'} {tmpl_var name='backup_copies'}
</select> </select>
</div>
<div class="ctrlHolder">
<label for="backup_excludes">{tmpl_var name='backup_excludes_txt'}</label>
<input name="backup_excludes" id="backup_excludes" value="{tmpl_var name='backup_excludes'}" size="30" type="text" class="textInput" />&nbsp;{tmpl_var name='backup_excludes_note_txt'}
</div> </div>
</fieldset> </fieldset>
......
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
</div> </div>
<div class="ctrlHolder nginx"> <div class="ctrlHolder nginx">
<label for="nginx_directives">{tmpl_var name='nginx_directives_txt'}</label> <label for="nginx_directives">{tmpl_var name='nginx_directives_txt'}</label>
<textarea name="nginx_directives" id="nginx_directives" rows='10' cols='50' style="width:400px;">{tmpl_var name='nginx_directives'}</textarea>&nbsp;<b>{tmpl_var name="available_nginx_directive_snippets_txt"}</b><br><br>&nbsp;{tmpl_var name="nginx_directive_snippets_txt"} <textarea name="nginx_directives" id="nginx_directives" rows='10' cols='50' style="width:400px;">{tmpl_var name='nginx_directives'}</textarea>&nbsp;<b>{tmpl_var name="available_nginx_directive_snippets_txt"}</b><br><br>&nbsp;{tmpl_var name="nginx_directive_snippets_txt"}<br>----<br><b>&nbsp;{tmpl_var name='variables_txt'}:</b> <a href="javascript:void(0);" class="addPlaceholder">{DOCROOT}</a>, <a href="javascript:void(0);" class="addPlaceholder">{FASTCGIPASS}</a>
</div> </div>
<div class="ctrlHolder proxy"> <div class="ctrlHolder proxy">
<label for="proxy_directives">{tmpl_var name='proxy_directives_txt'}</label> <label for="proxy_directives">{tmpl_var name='proxy_directives_txt'}</label>
......
...@@ -16,6 +16,10 @@ ...@@ -16,6 +16,10 @@
<select name="backup_copies" id="backup_copies" class="selectInput"> <select name="backup_copies" id="backup_copies" class="selectInput">
{tmpl_var name='backup_copies'} {tmpl_var name='backup_copies'}
</select> </select>
</div>
<div class="ctrlHolder">
<label for="backup_excludes">{tmpl_var name='backup_excludes_txt'}</label>
<input name="backup_excludes" id="backup_excludes" value="{tmpl_var name='backup_excludes'}" size="30" type="text" class="textInput" />&nbsp;{tmpl_var name='backup_excludes_note_txt'}
</div> </div>
</fieldset> </fieldset>
......
...@@ -1127,15 +1127,27 @@ if($backup_dir != '') { ...@@ -1127,15 +1127,27 @@ if($backup_dir != '') {
chown($web_backup_dir, 'root'); chown($web_backup_dir, 'root');
chgrp($web_backup_dir, 'root'); chgrp($web_backup_dir, 'root');
}*/ }*/
$backup_excludes = '';
$b_excludes = explode(',', trim($rec['backup_excludes']));
if(is_array($b_excludes) && !empty($b_excludes)){
foreach($b_excludes as $b_exclude){
$b_exclude = trim($b_exclude);
if($b_exclude != ''){
$backup_excludes .= ' --exclude='.escapeshellarg($b_exclude);
}
}
}
if($backup_mode == 'userzip') { if($backup_mode == 'userzip') {
//* Create a .zip backup as web user and include also files owned by apache / nginx user //* Create a .zip backup as web user and include also files owned by apache / nginx user
$web_backup_file = 'web'.$web_id.'_'.date('Y-m-d_H-i').'.zip'; $web_backup_file = 'web'.$web_id.'_'.date('Y-m-d_H-i').'.zip';
exec('cd '.escapeshellarg($web_path).' && sudo -u '.escapeshellarg($web_user).' find . -group '.escapeshellarg($web_group).' -print 2> /dev/null | zip -b /tmp --exclude=backup\* --symlinks '.escapeshellarg($web_backup_dir.'/'.$web_backup_file).' -@', $tmp_output, $retval); exec('cd '.escapeshellarg($web_path).' && sudo -u '.escapeshellarg($web_user).' find . -group '.escapeshellarg($web_group).' -print 2> /dev/null | zip -b /tmp --exclude=backup\* --symlinks '.escapeshellarg($web_backup_dir.'/'.$web_backup_file).' -@', $tmp_output, $retval);
if($retval == 0) exec('cd '.escapeshellarg($web_path).' && sudo -u '.escapeshellarg($web_user).' find . -user '.escapeshellarg($http_server_user).' -print 2> /dev/null | zip -b /tmp --exclude=backup\* --update --symlinks '.escapeshellarg($web_backup_dir.'/'.$web_backup_file).' -@', $tmp_output, $retval); if($retval == 0) exec('cd '.escapeshellarg($web_path).' && sudo -u '.escapeshellarg($web_user).' find . -user '.escapeshellarg($http_server_user).' -print 2> /dev/null | zip -b /tmp --exclude=backup\*'.$backup_excludes.' --update --symlinks '.escapeshellarg($web_backup_dir.'/'.$web_backup_file).' -@', $tmp_output, $retval);
} else { } else {
//* Create a tar.gz backup as root user //* Create a tar.gz backup as root user
$web_backup_file = 'web'.$web_id.'_'.date('Y-m-d_H-i').'.tar.gz'; $web_backup_file = 'web'.$web_id.'_'.date('Y-m-d_H-i').'.tar.gz';
exec('tar pczf '.escapeshellarg($web_backup_dir.'/'.$web_backup_file).' --exclude=backup\* --directory '.escapeshellarg($web_path).' .', $tmp_output, $retval); exec('tar pczf '.escapeshellarg($web_backup_dir.'/'.$web_backup_file).' --exclude=backup\*'.$backup_excludes.' --directory '.escapeshellarg($web_path).' .', $tmp_output, $retval);
} }
if($retval == 0 || $backup_mode != 'userzip'){ // tar can return 1 (due to harmless warings) and still create valid backups if($retval == 0 || $backup_mode != 'userzip'){ // tar can return 1 (due to harmless warings) and still create valid backups
if(is_file($web_backup_dir.'/'.$web_backup_file)){ if(is_file($web_backup_dir.'/'.$web_backup_file)){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment