|
@@ -41,9 +41,9 @@ discard block |
|
|
block discarded – undo |
|
41
|
41
|
if ($_POST['download']) |
|
42
|
42
|
{ |
|
43
|
43
|
list($file) = each($_POST['download']); |
|
44
|
|
- $file = $db_backup->backup_dir.'/'.basename($file); // basename to now allow to change the dir |
|
|
44
|
+ $file = $db_backup->backup_dir.'/'.basename($file); // basename to now allow to change the dir |
|
45
|
45
|
while (@ob_end_clean()) {} // end all active output buffering |
|
46
|
|
- ini_set('zlib.output_compression',0); // switch off zlib.output_compression, as this would limit downloads in size to memory_limit |
|
|
46
|
+ ini_set('zlib.output_compression', 0); // switch off zlib.output_compression, as this would limit downloads in size to memory_limit |
|
47
|
47
|
Api\Header\Content::type(basename($file)); |
|
48
|
48
|
readfile($file); |
|
49
|
49
|
exit; |
|
@@ -61,23 +61,23 @@ discard block |
|
|
block discarded – undo |
|
61
|
61
|
{ |
|
62
|
62
|
Api\Csrf::validate($_POST['csrf_token'], __FILE__); |
|
63
|
63
|
} |
|
64
|
|
-$setup_tpl->set_block('T_db_backup','schedule_row','schedule_rows'); |
|
65
|
|
-$setup_tpl->set_block('T_db_backup','set_row','set_rows'); |
|
|
64
|
+$setup_tpl->set_block('T_db_backup', 'schedule_row', 'schedule_rows'); |
|
|
65
|
+$setup_tpl->set_block('T_db_backup', 'set_row', 'set_rows'); |
|
66
|
66
|
|
|
67
|
|
-$setup_tpl->set_var('stage_title',$stage_title = lang('DB backup and restore')); |
|
68
|
|
-$setup_tpl->set_var('stage_desc',lang('This program lets you backup your database, schedule a backup or restore it.')); |
|
69
|
|
-$setup_tpl->set_var('error_msg',''); |
|
|
67
|
+$setup_tpl->set_var('stage_title', $stage_title = lang('DB backup and restore')); |
|
|
68
|
+$setup_tpl->set_var('stage_desc', lang('This program lets you backup your database, schedule a backup or restore it.')); |
|
|
69
|
+$setup_tpl->set_var('error_msg', ''); |
|
70
|
70
|
|
|
71
|
|
-$bgcolor = array('#DDDDDD','#EEEEEE'); |
|
|
71
|
+$bgcolor = array('#DDDDDD', '#EEEEEE'); |
|
72
|
72
|
|
|
73
|
73
|
if (is_object($GLOBALS['egw_setup']->html)) |
|
74
|
74
|
{ |
|
75
|
|
- $GLOBALS['egw_setup']->html->show_header($stage_title,False,'config',$GLOBALS['egw_setup']->ConfigDomain . '(' . $GLOBALS['egw_domain'][$GLOBALS['egw_setup']->ConfigDomain]['db_type'] . ')'); |
|
|
75
|
+ $GLOBALS['egw_setup']->html->show_header($stage_title, False, 'config', $GLOBALS['egw_setup']->ConfigDomain.'('.$GLOBALS['egw_domain'][$GLOBALS['egw_setup']->ConfigDomain]['db_type'].')'); |
|
76
|
76
|
} |
|
77
|
77
|
else |
|
78
|
78
|
{ |
|
79
|
|
- $setup_tpl->set_block('T_db_backup','setup_header'); |
|
80
|
|
- $setup_tpl->set_var('setup_header',''); |
|
|
79
|
+ $setup_tpl->set_block('T_db_backup', 'setup_header'); |
|
|
80
|
+ $setup_tpl->set_var('setup_header', ''); |
|
81
|
81
|
$GLOBALS['egw_info']['flags']['app_header'] = $stage_title; |
|
82
|
82
|
echo $GLOBALS['egw']->framework->header(); |
|
83
|
83
|
echo $GLOBALS['egw']->framework->navbar(); |
|
@@ -93,9 +93,9 @@ discard block |
|
|
block discarded – undo |
|
93
|
93
|
if (empty($minCount)) |
|
94
|
94
|
{ |
|
95
|
95
|
$minCount = 0; |
|
96
|
|
- $setup_tpl->set_var('error_msg',htmlspecialchars(lang("'%1' must be integer", lang("backup min count")))); |
|
|
96
|
+ $setup_tpl->set_var('error_msg', htmlspecialchars(lang("'%1' must be integer", lang("backup min count")))); |
|
97
|
97
|
} |
|
98
|
|
- $db_backup->saveConfig($minCount,$is_setup ? (boolean)$filesBackup : null); |
|
|
98
|
+ $db_backup->saveConfig($minCount, $is_setup ? (boolean)$filesBackup : null); |
|
99
|
99
|
|
|
100
|
100
|
if (is_int($minCount) && $minCount > 0) |
|
101
|
101
|
{ |
|
@@ -112,23 +112,22 @@ discard block |
|
|
block discarded – undo |
|
112
|
112
|
{ |
|
113
|
113
|
Vfs::$is_root = true; |
|
114
|
114
|
echo '<div align="center">'. |
|
115
|
|
- (Vfs::mount('filesystem://default'.$db_backup->backup_dir.'?group=Admins&mode=070','/backup',false) ? |
|
116
|
|
- lang('Backup directory %1 mounted as %2',$db_backup->backup_dir,'/backup') : |
|
117
|
|
- lang('Failed to mount Backup directory!')). |
|
|
115
|
+ (Vfs::mount('filesystem://default'.$db_backup->backup_dir.'?group=Admins&mode=070', '/backup', false) ? |
|
|
116
|
+ lang('Backup directory %1 mounted as %2', $db_backup->backup_dir, '/backup') : lang('Failed to mount Backup directory!')). |
|
118
|
117
|
"</div>\n"; |
|
119
|
118
|
Vfs::$is_root = false; |
|
120
|
119
|
} |
|
121
|
120
|
// create a backup now |
|
122
|
|
-if($_POST['backup']) |
|
|
121
|
+if ($_POST['backup']) |
|
123
|
122
|
{ |
|
124
|
123
|
if (is_resource($f = $db_backup->fopen_backup())) |
|
125
|
124
|
{ |
|
126
|
125
|
echo '<p align="center">'.lang('backup started, this might take a few minutes ...')."</p>\n"; |
|
127
|
126
|
$starttime = microtime(true); |
|
128
|
127
|
$db_backup->backup($f); |
|
129
|
|
- if(is_resource($f)) |
|
|
128
|
+ if (is_resource($f)) |
|
130
|
129
|
fclose($f); |
|
131
|
|
- $setup_tpl->set_var('error_msg', lang('backup finished').': '. number_format(microtime(true)-$starttime, 1).'s'); |
|
|
130
|
+ $setup_tpl->set_var('error_msg', lang('backup finished').': '.number_format(microtime(true) - $starttime, 1).'s'); |
|
132
|
131
|
|
|
133
|
132
|
/* Remove old backups. */ |
|
134
|
133
|
$cleaned_files = array(); |
|
@@ -140,38 +139,38 @@ discard block |
|
|
block discarded – undo |
|
140
|
139
|
} |
|
141
|
140
|
else |
|
142
|
141
|
{ |
|
143
|
|
- $setup_tpl->set_var('error_msg',$f); |
|
|
142
|
+ $setup_tpl->set_var('error_msg', $f); |
|
144
|
143
|
} |
|
145
|
144
|
} |
|
146
|
|
-$setup_tpl->set_var('backup_now_button','<input type="submit" name="backup" title="'.htmlspecialchars(lang("back's up your DB now, this might take a few minutes")).'" value="'.htmlspecialchars(lang('backup now')).'" />'); |
|
147
|
|
-$setup_tpl->set_var('upload','<input type="file" name="uploaded" /> '. |
|
|
145
|
+$setup_tpl->set_var('backup_now_button', '<input type="submit" name="backup" title="'.htmlspecialchars(lang("back's up your DB now, this might take a few minutes")).'" value="'.htmlspecialchars(lang('backup now')).'" />'); |
|
|
146
|
+$setup_tpl->set_var('upload', '<input type="file" name="uploaded" /> '. |
|
148
|
147
|
'<input type="submit" name="upload" value="'.htmlspecialchars(lang('upload backup')).'" title="'.htmlspecialchars(lang("uploads a backup to the backup-dir, from where you can restore it")).'" />'); |
|
149
|
|
-$setup_tpl->set_var('backup_mincount','<input type="text" name="backup_mincount" value="'.$db_backup->backup_mincount.'" size="3" maxlength="3"/>'); |
|
150
|
|
-$setup_tpl->set_var('backup_files','<input type="checkbox" name="backup_files" value="backup_files"'. |
|
151
|
|
- ($db_backup->backup_files ? ' checked="true"':''). |
|
|
148
|
+$setup_tpl->set_var('backup_mincount', '<input type="text" name="backup_mincount" value="'.$db_backup->backup_mincount.'" size="3" maxlength="3"/>'); |
|
|
149
|
+$setup_tpl->set_var('backup_files', '<input type="checkbox" name="backup_files" value="backup_files"'. |
|
|
150
|
+ ($db_backup->backup_files ? ' checked="true"' : ''). |
|
152
|
151
|
// do NOT allow to change "backup files" outside of setup |
|
153
|
152
|
($is_setup ? '' : ' disabled="true" title="'.htmlspecialchars(lang('Can only be change via Setup!')).'"').'/>'); |
|
154
|
|
-$setup_tpl->set_var('backup_save_settings','<input type="submit" name="save_backup_settings" value="'.htmlspecialchars(lang('save')).'" />'); |
|
155
|
|
-$setup_tpl->set_var('backup_mount','<input type="submit" name="mount" value="'.htmlspecialchars(lang('Mount backup directory to %1','/backup')).'" />'); |
|
|
153
|
+$setup_tpl->set_var('backup_save_settings', '<input type="submit" name="save_backup_settings" value="'.htmlspecialchars(lang('save')).'" />'); |
|
|
154
|
+$setup_tpl->set_var('backup_mount', '<input type="submit" name="mount" value="'.htmlspecialchars(lang('Mount backup directory to %1', '/backup')).'" />'); |
|
156
|
155
|
|
|
157
|
156
|
if ($_POST['upload'] && is_array($_FILES['uploaded']) && !$_FILES['uploaded']['error'] && |
|
158
|
157
|
is_uploaded_file($_FILES['uploaded']['tmp_name'])) |
|
159
|
158
|
{ |
|
160
|
|
- move_uploaded_file($_FILES['uploaded']['tmp_name'],$db_backup->backup_dir.'/'.$_FILES['uploaded']['name']); |
|
|
159
|
+ move_uploaded_file($_FILES['uploaded']['tmp_name'], $db_backup->backup_dir.'/'.$_FILES['uploaded']['name']); |
|
161
|
160
|
|
|
162
|
161
|
$md5 = ', md5='.md5_file($db_backup->backup_dir.'/'.$_FILES['uploaded']['name']); |
|
163
|
162
|
$md5 .= ', sha1='.sha1_file($db_backup->backup_dir.'/'.$_FILES['uploaded']['name']); |
|
164
|
163
|
|
|
165
|
|
- $setup_tpl->set_var('error_msg',lang("succesfully uploaded file %1",$_FILES['uploaded']['name'].', '. |
|
166
|
|
- sprintf('%3.1lf MB (%d)',$_FILES['uploaded']['size']/(1024*1024),$_FILES['uploaded']['size']).$md5)); |
|
|
164
|
+ $setup_tpl->set_var('error_msg', lang("succesfully uploaded file %1", $_FILES['uploaded']['name'].', '. |
|
|
165
|
+ sprintf('%3.1lf MB (%d)', $_FILES['uploaded']['size'] / (1024 * 1024), $_FILES['uploaded']['size']).$md5)); |
|
167
|
166
|
} |
|
168
|
167
|
// delete a backup |
|
169
|
168
|
if ($_POST['delete']) |
|
170
|
169
|
{ |
|
171
|
170
|
list($file) = each($_POST['delete']); |
|
172
|
|
- $file = $db_backup->backup_dir.'/'.basename($file); // basename to not allow to change the dir |
|
|
171
|
+ $file = $db_backup->backup_dir.'/'.basename($file); // basename to not allow to change the dir |
|
173
|
172
|
|
|
174
|
|
- if (unlink($file)) $setup_tpl->set_var('error_msg',lang("backup '%1' deleted",$file)); |
|
|
173
|
+ if (unlink($file)) $setup_tpl->set_var('error_msg', lang("backup '%1' deleted", $file)); |
|
175
|
174
|
} |
|
176
|
175
|
// rename a backup |
|
177
|
176
|
if ($_POST['rename']) |
|
@@ -182,44 +181,44 @@ discard block |
|
|
block discarded – undo |
|
182
|
181
|
{ |
|
183
|
182
|
list($ending) = array_reverse(explode('.', $file)); |
|
184
|
183
|
list($new_ending, $has_ending) = array_reverse(explode('.', $new_name)); |
|
185
|
|
- if(!$has_ending || $new_ending != $ending) $new_name .= '.'.$ending; |
|
186
|
|
- $file = $db_backup->backup_dir.'/'.basename($file); // basename to not allow to change the dir |
|
187
|
|
- $ext = preg_match('/(\.gz|\.bz2)+$/i',$file,$matches) ? $matches[1] : ''; |
|
188
|
|
- $new_file = $db_backup->backup_dir.'/'.preg_replace('/(\.gz|\.bz2)+$/i','',basename($new_name)).$ext; |
|
189
|
|
- if (rename($file,$new_file)) $setup_tpl->set_var('error_msg',lang("backup '%1' renamed to '%2'",basename($file),basename($new_file))); |
|
|
184
|
+ if (!$has_ending || $new_ending != $ending) $new_name .= '.'.$ending; |
|
|
185
|
+ $file = $db_backup->backup_dir.'/'.basename($file); // basename to not allow to change the dir |
|
|
186
|
+ $ext = preg_match('/(\.gz|\.bz2)+$/i', $file, $matches) ? $matches[1] : ''; |
|
|
187
|
+ $new_file = $db_backup->backup_dir.'/'.preg_replace('/(\.gz|\.bz2)+$/i', '', basename($new_name)).$ext; |
|
|
188
|
+ if (rename($file, $new_file)) $setup_tpl->set_var('error_msg', lang("backup '%1' renamed to '%2'", basename($file), basename($new_file))); |
|
190
|
189
|
} |
|
191
|
190
|
} |
|
192
|
191
|
// restore a backup |
|
193
|
192
|
if ($_POST['restore']) |
|
194
|
193
|
{ |
|
195
|
194
|
list($file) = each($_POST['restore']); |
|
196
|
|
- $file = $db_backup->backup_dir.'/'.basename($file); // basename to not allow to change the dir |
|
|
195
|
+ $file = $db_backup->backup_dir.'/'.basename($file); // basename to not allow to change the dir |
|
197
|
196
|
|
|
198
|
|
- if (is_resource($f = $db_backup->fopen_backup($file,true))) |
|
|
197
|
+ if (is_resource($f = $db_backup->fopen_backup($file, true))) |
|
199
|
198
|
{ |
|
200
|
|
- echo '<p align="center">'.lang('restore started, this might take a few minutes ...')."</p>\n".str_repeat(' ',4096); |
|
|
199
|
+ echo '<p align="center">'.lang('restore started, this might take a few minutes ...')."</p>\n".str_repeat(' ', 4096); |
|
201
|
200
|
$start = time(); |
|
202
|
|
- $db_backup->restore($f, true, $file); // allways convert to current system charset on restore |
|
203
|
|
- $setup_tpl->set_var('error_msg',lang("backup '%1' restored",$file).' ('.(time()-$start).' s)'); |
|
|
201
|
+ $db_backup->restore($f, true, $file); // allways convert to current system charset on restore |
|
|
202
|
+ $setup_tpl->set_var('error_msg', lang("backup '%1' restored", $file).' ('.(time() - $start).' s)'); |
|
204
|
203
|
if ($run_in_egw) |
|
205
|
204
|
{ |
|
206
|
205
|
// updating the backup |
|
207
|
206
|
$cmd = new setup_cmd_update($GLOBALS['egw']->session->account_domain, |
|
208
|
|
- $GLOBALS['egw_info']['server']['header_admin_user']='admin', |
|
209
|
|
- $GLOBALS['egw_info']['server']['header_admin_password']=uniqid('pw',true),false,true); |
|
|
207
|
+ $GLOBALS['egw_info']['server']['header_admin_user'] = 'admin', |
|
|
208
|
+ $GLOBALS['egw_info']['server']['header_admin_password'] = uniqid('pw', true), false, true); |
|
210
|
209
|
echo $cmd->run()."\n"; |
|
211
|
|
- echo '<h3>'.lang('You should %1log out%2 and in again, to update your current session!','<a href="'.Egw::link('/logout.php').'" target="_parent">','</a>')."</h3>\n"; |
|
|
210
|
+ echo '<h3>'.lang('You should %1log out%2 and in again, to update your current session!', '<a href="'.Egw::link('/logout.php').'" target="_parent">', '</a>')."</h3>\n"; |
|
212
|
211
|
} |
|
213
|
212
|
} |
|
214
|
213
|
else |
|
215
|
214
|
{ |
|
216
|
|
- $setup_tpl->set_var('error_msg',$f); |
|
|
215
|
+ $setup_tpl->set_var('error_msg', $f); |
|
217
|
216
|
} |
|
218
|
217
|
} |
|
219
|
218
|
// create a new scheduled backup |
|
220
|
219
|
if ($_POST['schedule']) |
|
221
|
220
|
{ |
|
222
|
|
- $asyncservice->set_timer($_POST['times'],'db_backup-'.implode(':',$_POST['times']),'admin.admin_db_backup.do_backup',''); |
|
|
221
|
+ $asyncservice->set_timer($_POST['times'], 'db_backup-'.implode(':', $_POST['times']), 'admin.admin_db_backup.do_backup', ''); |
|
223
|
222
|
} |
|
224
|
223
|
// cancel a scheduled backup |
|
225
|
224
|
if (is_array($_POST['cancel'])) |
|
@@ -230,29 +229,29 @@ discard block |
|
|
block discarded – undo |
|
230
|
229
|
// list scheduled backups |
|
231
|
230
|
if (($jobs = $asyncservice->read('db_backup-%'))) |
|
232
|
231
|
{ |
|
233
|
|
- foreach($jobs as $job) |
|
|
232
|
+ foreach ($jobs as $job) |
|
234
|
233
|
{ |
|
235
|
234
|
$setup_tpl->set_var($job['times']); |
|
236
|
|
- $setup_tpl->set_var('next_run',date('Y-m-d H:i',$job['next'])); |
|
237
|
|
- $setup_tpl->set_var('actions','<input type="submit" name="cancel['.$job['id'].']" value="'.htmlspecialchars(lang('delete')).'" />'); |
|
238
|
|
- $setup_tpl->parse('schedule_rows','schedule_row',true); |
|
|
235
|
+ $setup_tpl->set_var('next_run', date('Y-m-d H:i', $job['next'])); |
|
|
236
|
+ $setup_tpl->set_var('actions', '<input type="submit" name="cancel['.$job['id'].']" value="'.htmlspecialchars(lang('delete')).'" />'); |
|
|
237
|
+ $setup_tpl->parse('schedule_rows', 'schedule_row', true); |
|
239
|
238
|
} |
|
240
|
239
|
} |
|
241
|
240
|
// input-fields to create a new scheduled backup |
|
242
|
|
-foreach($times=array('year'=>'*','month'=>'*','day'=>'*','dow'=>'2-6','hour'=>3,'min'=>0) as $name => $default) |
|
|
241
|
+foreach ($times = array('year'=>'*', 'month'=>'*', 'day'=>'*', 'dow'=>'2-6', 'hour'=>3, 'min'=>0) as $name => $default) |
|
243
|
242
|
{ |
|
244
|
|
- $setup_tpl->set_var($name,'<input name="times['.$name.']" size="5" value="'.$default.'" />'); |
|
|
243
|
+ $setup_tpl->set_var($name, '<input name="times['.$name.']" size="5" value="'.$default.'" />'); |
|
245
|
244
|
} |
|
246
|
|
-$setup_tpl->set_var('next_run',' '); |
|
247
|
|
-$setup_tpl->set_var('actions','<input type="submit" name="schedule" value="'.htmlspecialchars(lang('schedule')).'" />'); |
|
248
|
|
-$setup_tpl->parse('schedule_rows','schedule_row',true); |
|
|
245
|
+$setup_tpl->set_var('next_run', ' '); |
|
|
246
|
+$setup_tpl->set_var('actions', '<input type="submit" name="schedule" value="'.htmlspecialchars(lang('schedule')).'" />'); |
|
|
247
|
+$setup_tpl->parse('schedule_rows', 'schedule_row', true); |
|
249
|
248
|
|
|
250
|
249
|
// listing the availible backup sets |
|
251
|
|
-$setup_tpl->set_var('backup_dir',$db_backup->backup_dir); |
|
252
|
|
-$setup_tpl->set_var('set_rows',''); |
|
|
250
|
+$setup_tpl->set_var('backup_dir', $db_backup->backup_dir); |
|
|
251
|
+$setup_tpl->set_var('set_rows', ''); |
|
253
|
252
|
$handle = @opendir($db_backup->backup_dir); |
|
254
|
253
|
$files = array(); |
|
255
|
|
-while($handle && ($file = readdir($handle))) |
|
|
254
|
+while ($handle && ($file = readdir($handle))) |
|
256
|
255
|
{ |
|
257
|
256
|
if ($file != '.' && $file != '..') |
|
258
|
257
|
{ |
|
@@ -262,13 +261,13 @@ discard block |
|
|
block discarded – undo |
|
262
|
261
|
if ($handle) closedir($handle); |
|
263
|
262
|
|
|
264
|
263
|
arsort($files); |
|
265
|
|
-foreach($files as $file => $ctime) |
|
|
264
|
+foreach ($files as $file => $ctime) |
|
266
|
265
|
{ |
|
267
|
266
|
$size = filesize($db_backup->backup_dir.'/'.$file); |
|
268
|
267
|
$setup_tpl->set_var(array( |
|
269
|
268
|
'filename' => $file, |
|
270
|
|
- 'mod' => date('Y-m-d H:i',$ctime), |
|
271
|
|
- 'size' => sprintf('%3.1lf MB (%d)',$size/(1024*1024),$size), |
|
|
269
|
+ 'mod' => date('Y-m-d H:i', $ctime), |
|
|
270
|
+ 'size' => sprintf('%3.1lf MB (%d)', $size / (1024 * 1024), $size), |
|
272
|
271
|
'actions' => '<input type="submit" name="download['.$file.']" value="'.htmlspecialchars(lang('download')).'" /> '."\n". |
|
273
|
272
|
'<input type="submit" name="delete['.$file.']" value="'.htmlspecialchars(lang('delete')).'" onclick="return confirm(\''. |
|
274
|
273
|
htmlspecialchars(lang('Confirm to delete this backup?')).'\');" /> '."\n". |
|
@@ -276,7 +275,7 @@ discard block |
|
|
block discarded – undo |
|
276
|
275
|
'<input type="submit" name="restore['.$file.']" value="'.htmlspecialchars(lang('restore')).'" onclick="return confirm(\''. |
|
277
|
276
|
htmlspecialchars(lang('Restoring a backup will delete/replace all content in your database. Are you sure?')).'\');" />', |
|
278
|
277
|
)); |
|
279
|
|
- $setup_tpl->parse('set_rows','set_row',true); |
|
|
278
|
+ $setup_tpl->parse('set_rows', 'set_row', true); |
|
280
|
279
|
} |
|
281
|
280
|
|
|
282
|
281
|
$setup_tpl->set_var(array( |
|
@@ -300,8 +299,8 @@ discard block |
|
|
block discarded – undo |
|
300
|
299
|
'lang_size' => lang('size'), |
|
301
|
300
|
)); |
|
302
|
301
|
|
|
303
|
|
-$setup_tpl->set_var('self',$self); |
|
304
|
|
-$setup_tpl->pparse('out','T_db_backup'); |
|
|
302
|
+$setup_tpl->set_var('self', $self); |
|
|
303
|
+$setup_tpl->pparse('out', 'T_db_backup'); |
|
305
|
304
|
|
|
306
|
305
|
if ($run_in_egw) |
|
307
|
306
|
{ |