Skip to content

Commit 8bc6a8c

Browse files
rvalitovTill Brehm
authored andcommitted
New code for backups with lots of new features
1 parent 2fa5ed2 commit 8bc6a8c

File tree

75 files changed

+3340
-417
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+3340
-417
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
-- add new proxy_protocol column
22
ALTER TABLE `web_domain`
33
ADD COLUMN `proxy_protocol` ENUM('n','y') NOT NULL DEFAULT 'n' AFTER `log_retention`;
4+
5+
-- backup format
6+
ALTER TABLE `web_domain` ADD `backup_format_web` VARCHAR( 255 ) NOT NULL default 'default' AFTER `backup_copies`;
7+
ALTER TABLE `web_domain` ADD `backup_format_db` VARCHAR( 255 ) NOT NULL default 'gzip' AFTER `backup_format_web`;
8+
-- end of backup format
9+
10+
-- backup encryption
11+
ALTER TABLE `web_domain` ADD `backup_encrypt` enum('n','y') NOT NULL DEFAULT 'n' AFTER `backup_format_db`;
12+
ALTER TABLE `web_domain` ADD `backup_password` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `backup_encrypt`;
13+
ALTER TABLE `web_backup` ADD `backup_format` VARCHAR( 64 ) NOT NULL DEFAULT '' AFTER `backup_mode`;
14+
ALTER TABLE `web_backup` ADD `backup_password` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `filesize`;
15+
-- end of backup encryption

install/sql/ispconfig3.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,9 +1922,11 @@ CREATE TABLE `web_backup` (
19221922
`parent_domain_id` int(10) unsigned NOT NULL DEFAULT '0',
19231923
`backup_type` enum('web','mysql','mongodb') NOT NULL DEFAULT 'web',
19241924
`backup_mode` varchar(64) NOT NULL DEFAULT '',
1925+
`backup_format` varchar(64) NOT NULL DEFAULT '',
19251926
`tstamp` int(10) unsigned NOT NULL DEFAULT '0',
19261927
`filename` varchar(255) NOT NULL DEFAULT '',
19271928
`filesize` VARCHAR(20) NOT NULL DEFAULT '',
1929+
`backup_password` VARCHAR(255) NOT NULL DEFAULT '',
19281930
PRIMARY KEY (`backup_id`)
19291931
) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
19301932

@@ -2055,6 +2057,10 @@ CREATE TABLE `web_domain` (
20552057
`custom_php_ini` mediumtext,
20562058
`backup_interval` VARCHAR( 255 ) NOT NULL DEFAULT 'none',
20572059
`backup_copies` INT NOT NULL DEFAULT '1',
2060+
`backup_format_web` VARCHAR( 255 ) NOT NULL default 'default',
2061+
`backup_format_db` VARCHAR( 255 ) NOT NULL default 'gzip',
2062+
`backup_encrypt` enum('n','y') NOT NULL DEFAULT 'n',
2063+
`backup_password` VARCHAR( 255 ) NOT NULL DEFAULT '',
20582064
`backup_excludes` mediumtext,
20592065
`active` enum('n','y') NOT NULL default 'y',
20602066
`traffic_quota_lock` enum('n','y') NOT NULL default 'n',

interface/lib/classes/aps_guicontroller.inc.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ public function createDatabaseForPackageInstance(&$settings, $websrv) {
340340
"remote_access" => $mysql_db_remote_access,
341341
"remote_ips" => $mysql_db_remote_ips,
342342
"backup_copies" => $websrv['backup_copies'],
343+
"backup_format_web" => $websrv['backup_format_web'],
344+
"backup_format_db" => $websrv['backup_format_db'],
343345
"active" => 'y',
344346
"backup_interval" => $websrv['backup_interval']
345347
);

interface/lib/classes/plugin_backuplist.inc.php

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,34 @@ class plugin_backuplist extends plugin_base {
3737
var $formdef;
3838
var $options;
3939

40+
/**
41+
* Process request to make a backup. This request is triggered manually by the user in the ISPConfig interface.
42+
* @param string $message
43+
* @param string $error
44+
* @param string[] $wb language text
45+
* @author Ramil Valitov <ramilvalitov@gmail.com>
46+
* @uses backup_plugin::make_backup_callback() this method is called later in the plugin to run the backup
47+
*/
48+
protected function makeBackup(&$message, &$error, $wb)
49+
{
50+
global $app;
51+
52+
$mode = $_GET['make_backup'];
53+
$action_type = ($mode == 'web') ? 'backup_web_files' : 'backup_database';
54+
$domain_id = intval($this->form->id);
55+
56+
$sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = ? AND action_param = ?";
57+
$tmp = $app->db->queryOneRecord($sql, $action_type, $domain_id);
58+
if ($tmp['number'] == 0) {
59+
$server_id = $this->form->dataRecord['server_id'];
60+
$message .= $wb['backup_info_txt'];
61+
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) VALUES (?, UNIX_TIMESTAMP(), ?, ?, 'pending', '')";
62+
$app->db->query($sql, $server_id, $action_type, $domain_id);
63+
} else {
64+
$error .= $wb['backup_pending_txt'];
65+
}
66+
}
67+
4068
function onShow() {
4169

4270
global $app;
@@ -52,6 +80,10 @@ function onShow() {
5280
$message = '';
5381
$error = '';
5482

83+
if (isset($_GET['make_backup'])) {
84+
$this->makeBackup($message, $error, $wb);
85+
}
86+
5587
if(isset($_GET['backup_action'])) {
5688
$backup_id = $app->functions->intval($_GET['backup_id']);
5789

@@ -137,7 +169,30 @@ function onShow() {
137169
$rec["bgcolor"] = $bgcolor;
138170

139171
$rec['date'] = date($app->lng('conf_format_datetime'), $rec['tstamp']);
140-
$rec['backup_type'] = $wb[('backup_type_'.$rec['backup_type'])];
172+
$backup_format = $rec['backup_format'];
173+
if (empty($backup_format)) {
174+
//We have a backup from old version of ISPConfig
175+
switch ($rec['backup_type']) {
176+
case 'mysql':
177+
$backup_format = 'gzip';
178+
break;
179+
case 'web':
180+
$backup_format = ($rec['backup_mode'] == 'userzip') ? 'zip' : 'tar_gzip';
181+
break;
182+
default:
183+
$app->log('Unsupported backup type "' . $rec['backup_type'] . '" for backup id ' . $rec['backup_id'], LOGLEVEL_ERROR);
184+
break;
185+
}
186+
}
187+
$rec['backup_type'] = $wb[('backup_type_' . $rec['backup_type'])];
188+
$backup_format = (!empty($backup_format)) ? $wb[('backup_format_' . $backup_format . '_txt')] : $wb["backup_format_unknown_txt"];
189+
if (empty($backup_format))
190+
$backup_format = $wb["backup_format_unknown_txt"];
191+
192+
$rec['backup_format'] = $backup_format;
193+
$rec['backup_encrypted'] = empty($rec['backup_password']) ? $wb["no_txt"] : $wb["yes_txt"];
194+
$backup_manual_prefix = 'manual-';
195+
$rec['backup_job'] = (substr($rec['filename'], 0, strlen($backup_manual_prefix)) == $backup_manual_prefix) ? $wb["backup_job_manual_txt"] : $wb["backup_job_auto_txt"];
141196

142197
$rec['download_available'] = true;
143198
if($rec['server_id'] != $web['server_id']) $rec['download_available'] = false;

interface/lib/classes/remote.d/sites.inc.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,12 @@ public function sites_database_add($session_id, $client_id, $params)
132132
$app->sites_database_plugin->processDatabaseInsert($this);
133133

134134
// set correct values for backup_interval and backup_copies
135-
if(isset($params['backup_interval']) || isset($params['backup_copies'])){
135+
if(isset($params['backup_interval']) || isset($params['backup_copies']) || isset($params['backup_format_web']) || isset($params['backup_format_db'])){
136136
$sql_set = array();
137137
if(isset($params['backup_interval'])) $sql_set[] = "backup_interval = '".$app->db->quote($params['backup_interval'])."'";
138138
if(isset($params['backup_copies'])) $sql_set[] = "backup_copies = ".$app->functions->intval($params['backup_copies']);
139+
if(isset($params['backup_format_web'])) $sql_set[] = "backup_format_web = ".$app->functions->intval($params['backup_format_web']);
140+
if(isset($params['backup_format_db'])) $sql_set[] = "backup_format_db = ".$app->functions->intval($params['backup_format_db']);
139141
$this->updateQueryExecute("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$retval, $retval, $params);
140142
}
141143

@@ -165,10 +167,12 @@ public function sites_database_update($session_id, $client_id, $primary_id, $par
165167
$retval = $this->updateQueryExecute($sql, $primary_id, $params);
166168

167169
// set correct values for backup_interval and backup_copies
168-
if(isset($params['backup_interval']) || isset($params['backup_copies'])){
170+
if(isset($params['backup_interval']) || isset($params['backup_copies']) || isset($params['backup_format_web']) || isset($params['backup_format_db'])){
169171
$sql_set = array();
170172
if(isset($params['backup_interval'])) $sql_set[] = "backup_interval = '".$app->db->quote($params['backup_interval'])."'";
171173
if(isset($params['backup_copies'])) $sql_set[] = "backup_copies = ".$app->functions->intval($params['backup_copies']);
174+
if(isset($params['backup_format_web'])) $sql_set[] = "backup_format_web = ".$app->functions->intval($params['backup_format_web']);
175+
if(isset($params['backup_format_db'])) $sql_set[] = "backup_format_db = ".$app->functions->intval($params['backup_format_db']);
172176
$this->updateQueryExecute("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$primary_id, $primary_id, $params);
173177
}
174178

interface/lib/classes/sites_database_plugin.inc.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ public function processDatabaseUpdate($form_page) {
4545
//* The Database user shall be owned by the same group then the website
4646
$sys_groupid = $app->functions->intval($web['sys_groupid']);
4747
$backup_interval = $web['backup_interval'];
48+
$backup_format_web = $web['backup_format_web'];
49+
$backup_format_db = $web['backup_format_db'];
4850
$backup_copies = $app->functions->intval($web['backup_copies']);
4951

50-
$sql = "UPDATE web_database SET sys_groupid = ?, backup_interval = ?, backup_copies = ? WHERE database_id = ?";
51-
$app->db->query($sql, $sys_groupid, $backup_interval, $backup_copies, $form_page->id);
52+
$sql = "UPDATE web_database SET sys_groupid = ?, backup_interval = ?, backup_copies = ?, backup_format_web = ?, backup_format_db = ? WHERE database_id = ?";
53+
$app->db->query($sql, $sys_groupid, $backup_interval, $backup_copies, $backup_format_web, $backup_format_db, $form_page->id);
5254
}
5355
}
5456

interface/lib/classes/system.inc.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,17 @@ public function system_safe($cmd) {
9797
call_user_func_array(array($this, 'exec_safe'), func_get_args());
9898
return implode("\n", $this->_last_exec_out);
9999
}
100+
101+
//* Check if a application is installed
102+
public function is_installed($appname) {
103+
$this->exec_safe('which ? 2> /dev/null', $appname);
104+
$out = $this->last_exec_out();
105+
$returncode = $this->last_exec_retcode();
106+
if(isset($out[0]) && stristr($out[0], $appname) && $returncode == 0) {
107+
return true;
108+
} else {
109+
return false;
110+
}
111+
}
100112

101113
} //* End Class

interface/lib/plugins/sites_web_vhost_domain_plugin.inc.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,18 +249,22 @@ function sites_web_vhost_domain_edit($event_name, $page_form) {
249249
}
250250

251251
//* Change database backup options when web backup options have been changed
252-
if(isset($page_form->dataRecord['backup_interval']) && ($page_form->dataRecord['backup_interval'] != $page_form->oldDataRecord['backup_interval'] || $page_form->dataRecord['backup_copies'] != $page_form->oldDataRecord['backup_copies'])) {
252+
if(isset($page_form->dataRecord['backup_interval']) && ($page_form->dataRecord['backup_interval'] != $page_form->oldDataRecord['backup_interval'] || $page_form->dataRecord['backup_copies'] != $page_form->oldDataRecord['backup_copies'] || $page_form->dataRecord['backup_format_web'] != $page_form->oldDataRecord['backup_format_web'] || $page_form->dataRecord['backup_format_db'] != $page_form->oldDataRecord['backup_format_db'])) {
253253
//* Update all databases
254254
$backup_interval = $page_form->dataRecord['backup_interval'];
255255
$backup_copies = $app->functions->intval($page_form->dataRecord['backup_copies']);
256+
$backup_format_web = $page_form->dataRecord['backup_format_web'];
257+
$backup_format_db = $page_form->dataRecord['backup_format_db'];
256258
$records = $app->db->queryAllRecords("SELECT database_id FROM web_database WHERE parent_domain_id = ".$page_form->id);
257259
foreach($records as $rec) {
258-
$app->db->datalogUpdate('web_database', array("backup_interval" => $backup_interval, "backup_copies" => $backup_copies), 'database_id', $rec['database_id']);
260+
$app->db->datalogUpdate('web_database', array("backup_interval" => $backup_interval, "backup_copies" => $backup_copies, "backup_format_web" => $backup_format_web, "backup_format_db" => $backup_format_db), 'database_id', $rec['database_id']);
259261
}
260262
unset($records);
261263
unset($rec);
262264
unset($backup_copies);
263265
unset($backup_interval);
266+
unset($backup_format_web);
267+
unset($backup_format_db);
264268
}
265269

266270
//* Change vhost subdomain and alias ip/ipv6 if domain ip/ipv6 has changed

interface/web/sites/form/web_vhost_domain.tform.php

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
if($client['limit_backup'] != 'y') $backup_available = false;
9797
}
9898

99-
$app->uses('getconf');
99+
$app->uses('getconf,system');
100100
$web_config = $app->getconf->get_global_config('sites');
101101

102102
$form["tabs"]['domain'] = array (
@@ -649,6 +649,28 @@
649649

650650
//* Backup
651651
if ($backup_available) {
652+
$missing_utils = array();
653+
$compressors_list = array(
654+
'gzip',
655+
'gunzip',
656+
'zip',
657+
'unzip',
658+
'pigz',
659+
'tar',
660+
'bzip2',
661+
'bunzip2',
662+
'xz',
663+
'unxz',
664+
'7z',
665+
'rar',
666+
);
667+
foreach ($compressors_list as $compressor) {
668+
if (!$app->system->is_installed($compressor)) {
669+
array_push($missing_utils, $compressor);
670+
}
671+
}
672+
$app->tpl->setVar("missing_utils", implode(", ",$missing_utils), true);
673+
652674
$form["tabs"]['backup'] = array (
653675
'title' => "Backup",
654676
'width' => 100,
@@ -682,6 +704,58 @@
682704
'width' => '30',
683705
'maxlength' => '255'
684706
),
707+
'backup_format_web' => array (
708+
'datatype' => 'VARCHAR',
709+
'formtype' => 'SELECT',
710+
'default' => '',
711+
'value' => array(
712+
'default' => 'backup_format_default_txt',
713+
'zip' => 'backup_format_zip_txt',
714+
'zip_bzip2' => 'backup_format_zip_bzip2_txt',
715+
'tar_gzip' => 'backup_format_tar_gzip_txt',
716+
'tar_bzip2' => 'backup_format_tar_bzip2_txt',
717+
'tar_xz' => 'backup_format_tar_xz_txt',
718+
'tar_7z_lzma2' => 'backup_format_tar_7z_lzma2_txt',
719+
'tar_7z_lzma' => 'backup_format_tar_7z_lzma_txt',
720+
'tar_7z_ppmd' => 'backup_format_tar_7z_ppmd_txt',
721+
'tar_7z_bzip2' => 'backup_format_tar_7z_bzip2_txt',
722+
'rar' => 'backup_format_rar_txt',
723+
)
724+
),
725+
'backup_format_db' => array (
726+
'datatype' => 'VARCHAR',
727+
'formtype' => 'SELECT',
728+
'default' => '',
729+
'value' => array(
730+
'zip' => 'backup_format_zip_txt',
731+
'zip_bzip2' => 'backup_format_zip_bzip2_txt',
732+
'gzip' => 'backup_format_gzip_txt',
733+
'bzip2' => 'backup_format_bzip2_txt',
734+
'xz' => 'backup_format_xz_txt',
735+
'7z_lzma2' => 'backup_format_7z_lzma2_txt',
736+
'7z_lzma' => 'backup_format_7z_lzma_txt',
737+
'7z_ppmd' => 'backup_format_7z_ppmd_txt',
738+
'7z_bzip2' => 'backup_format_7z_bzip2_txt',
739+
'rar' => 'backup_format_rar_txt',
740+
)
741+
),
742+
'backup_encrypt' => array (
743+
'datatype' => 'VARCHAR',
744+
'formtype' => 'CHECKBOX',
745+
'default' => 'n',
746+
'value' => array (
747+
0 => 'n',
748+
1 => 'y'
749+
)
750+
),
751+
'backup_password' => array (
752+
'datatype' => 'VARCHAR',
753+
'formtype' => 'TEXT',
754+
'default' => '',
755+
'value' => '',
756+
'width' => '30',
757+
'maxlength' => '255'
758+
),
685759
//#################################
686760
// END Datatable fields
687761
//#################################

interface/web/sites/lib/lang/ar_web_backup_list.lng

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,36 @@ $wb['backup_type_mysql'] = 'MySQL Database';
1818
$wb['backup_type_web'] = 'Website files';
1919
$wb['filesize_txt'] = 'Filesize';
2020
$wb['backup_type_mongodb'] = 'MongoDB Database';
21+
$wb['backup_pending_txt'] = 'There is already a pending backup job.';
22+
$wb['error_txt'] = 'Error';
23+
$wb['backup_info_txt'] = 'A backup process started. This action can take several minutes to complete.';
24+
$wb["backup_format_txt"] = 'Backup format';
25+
$wb["backup_format_unknown_txt"] = 'Unknown';
26+
$wb["backup_job_txt"] = 'Scheduler';
27+
$wb["backup_job_manual_txt"] = 'Manual';
28+
$wb["backup_job_auto_txt"] = 'Auto';
29+
$wb["manual_backup_title_txt"] = 'Manual backup';
30+
$wb["make_backup_web_txt"] = 'Make backup of web files';
31+
$wb["make_backup_database_txt"] = 'Make backup of databases';
32+
$wb["make_backup_confirm_txt"] = 'You are about to start a manual backup process. Manual backups count towards the total number of allowed backup copies: therefore if the limit will be exceeded, then oldest backups may be deleted automatically. Proceed?';
33+
$wb["yes_txt"] = 'Yes';
34+
$wb["no_txt"] = 'No';
35+
$wb["backup_is_encrypted_txt"] = "Encrypted";
36+
$wb["backup_format_zip_txt"] = 'zip (deflate)';
37+
$wb["backup_format_gzip_txt"] = 'gzip';
38+
$wb["backup_format_bzip2_txt"] = 'bzip2';
39+
$wb["backup_format_xz_txt"] = 'xz';
40+
$wb["backup_format_tar_gzip_txt"] = 'tar (gzip)';
41+
$wb["backup_format_tar_bzip2_txt"] = 'tar (bzip2)';
42+
$wb["backup_format_tar_xz_txt"] = 'tar (xz)';
43+
$wb["backup_format_zip_bzip2_txt"] = 'zip (bzip2)';
44+
$wb["backup_format_7z_lzma_txt"] = '7z (LZMA)';
45+
$wb["backup_format_7z_lzma2_txt"] = '7z (LZMA2)';
46+
$wb["backup_format_7z_ppmd_txt"] = '7z (PPMd)';
47+
$wb["backup_format_7z_bzip2_txt"] = '7z (BZip2)';
48+
$wb["backup_format_tar_7z_lzma_txt"] = 'tar + 7z (LZMA)';
49+
$wb["backup_format_tar_7z_lzma2_txt"] = 'tar + 7z (LZMA2)';
50+
$wb["backup_format_tar_7z_ppmd_txt"] = 'tar + 7z (PPMd)';
51+
$wb["backup_format_tar_7z_bzip2_txt"] = 'tar + 7z (BZip2)';
52+
$wb["backup_format_rar_txt"] = 'RAR';
2153
?>

0 commit comments

Comments
 (0)