diff --git a/api/src/Db/Backup.php b/api/src/Db/Backup.php
index 15771bdfd7..65fd2c5ba6 100644
--- a/api/src/Db/Backup.php
+++ b/api/src/Db/Backup.php
@@ -189,9 +189,9 @@ class Backup
if (!$name)
{
//echo '-> !$name
'; // !
- if (!$this->backup_dir || !is_writable($this->backup_dir))
+ if (empty($this->backup_dir) || !is_writable($this->backup_dir))
{
- //echo ' -> !$this->backup_dir || !is_writable($this->backup_dir)
'; // !
+ $this->log($name, $reading, null, lang("backupdir '%1' is not writeable by the webserver", $this->backup_dir));
return lang("backupdir '%1' is not writeable by the webserver",$this->backup_dir);
}
$name = $this->backup_dir.'/db_backup-'.date('YmdHi');
@@ -209,37 +209,40 @@ class Backup
if(!class_exists('ZipArchive', false))
{
$this->backup_files = false;
- //echo ' -> (new ZipArchive) == NULL
'; // !
+ $this->log($name, $reading, null, lang("Cant open %1, needs ZipArchive", $name));
return lang("Cant open %1, needs ZipArchive", $name)."
\n";
}
- if(!($f = fopen($name, $mode)))
+ if(!($f = fopen($path=$name, $mode)))
{
//echo ' -> !($f = fopen($name, $mode))
'; // !
$lang_mode = $reading ? lang("reading") : lang("writing");
+ $this->log($name, $reading, null, lang("Cant open '%1' for %2", $name, $lang_mode));
return lang("Cant open '%1' for %2", $name, $lang_mode)."
";
}
- return $f;
}
- if(class_exists('ZipArchive', false) && !$reading && $this->backup_files)
+ elseif (class_exists('ZipArchive', false) && !$reading && $this->backup_files)
{
//echo '-> (new ZipArchive) != NULL && !$reading; '.$name.'
'; // !
- if(!($f = fopen($name, $mode)))
+ if (!($f = fopen($path=$name, $mode)))
{
- //echo ' -> !($f = fopen($name, $mode))
'; // !
$lang_mode = $reading ? lang("reading") : lang("writing");
+ $this->log($name, $reading, null, lang("Cant open '%1' for %2", $name, $lang_mode));
return lang("Cant open '%1' for %2", $name, $lang_mode)."
";
}
- return $f;
}
- if(!($f = fopen("compress.bzip2://$name.bz2", $mode)) &&
- !($f = fopen("compress.zlib://$name.gz",$mode)) &&
- !($f = fopen($name,$mode))
+ elseif (!($f = fopen('compress.bzip2://'.($path=$name.'.bz2'), $mode)) &&
+ !($f = fopen('compress.zlib://'.($path=$name.'.gz'),$mode)) &&
+ !($f = fopen($path=$name,$mode))
)
{
- //echo '-> !($f = fopen("compress.bzip2://$name.bz2", $mode))
'; // !
$lang_mode = $reading ? lang("reading") : lang("writing");
+ $this->log($name, $reading, null, lang("Cant open '%1' for %2", $name, $lang_mode));
return lang("Cant open '%1' for %2", $name, $lang_mode)."
";
}
+
+ // Log start of backup/restore
+ $this->log($path, $reading, true);
+
return $f;
}
@@ -280,7 +283,9 @@ class Backup
{
if ($count >= $this->backup_mincount)//
{
+ $this->log($file, lang('Housekeeping removed'));
$ret = unlink($this->backup_dir.'/'.$file);
+ if (!$ret) $this->log($file, 'remove', null, "Failed to remove $file");
if (($ret) && (is_array($files_return)))
{
array_push($files_return, $file);
@@ -414,6 +419,7 @@ class Backup
$name = $dir.'/database_backup/'.basename($list[0]);
if(!($f = fopen($name, 'rb')))
{
+ $this->log($name, true, null, lang("Cant open '%1' for %2", $filename, lang("reading")));
return lang("Cant open '%1' for %2", $filename, lang("reading"))."
\n";
}
}
@@ -476,6 +482,7 @@ class Backup
{
if (!$this->db->transaction_commit())
{
+ $this->log($filename, true, false, lang('Restore failed'));
return lang('Restore failed');
}
}
@@ -497,6 +504,9 @@ class Backup
// search-and-register-hooks
Api\Hooks::read(true);
+ // log end of successful restore
+ $this->log($filename, true, false);
+
return '';
}
@@ -907,7 +917,7 @@ class Backup
$res = $zip->open($filename, ZipArchive::CREATE);
if($res !== TRUE)
{
- //echo ' -> !$res
'; // !
+ $this->log($filename, false, null, lang("Cant open '%1' for %2", $filename, lang("writing")));
return lang("Cant open '%1' for %2", $filename, lang("writing"))."
\n";
}
$file_list = $this->get_file_list($dir);
@@ -975,11 +985,19 @@ class Backup
{
if ($this->backup_files && !$skip_files_backup)
{
+ $this->log($name, false, null, lang("Cant open %1, needs ZipArchive", $name));
echo '
'.$msg."
\n".($backtrace ? 'Backtrace: '.function_backtrace(1)."
'.lang('backup started, this might take a few minutes ...')."
\n"; $starttime = microtime(true); $db_backup->backup($f); if(is_resource($f)) @@ -147,7 +147,9 @@ if($_POST['backup']) $setup_tpl->set_var('error_msg',$f); } } -$setup_tpl->set_var('backup_now_button',''); +$setup_tpl->set_var('backup_now_button',''); $setup_tpl->set_var('upload',' '. ''); $setup_tpl->set_var('backup_mincount',''); @@ -158,22 +160,22 @@ $setup_tpl->set_var('backup_files','set_var('backup_save_settings',''); $setup_tpl->set_var('backup_mount',''); -if ($_POST['upload'] && is_array($_FILES['uploaded']) && !$_FILES['uploaded']['error'] && +if (!empty($_POST['upload']) && is_array($_FILES['uploaded']) && !$_FILES['uploaded']['error'] && is_uploaded_file($_FILES['uploaded']['tmp_name'])) { - move_uploaded_file($_FILES['uploaded']['tmp_name'],$db_backup->backup_dir.'/'.$_FILES['uploaded']['name']); + move_uploaded_file($_FILES['uploaded']['tmp_name'], $filename=$db_backup->backup_dir.'/'.$_FILES['uploaded']['name']); - $md5 = ', md5='.md5_file($db_backup->backup_dir.'/'.$_FILES['uploaded']['name']); - $md5 .= ', sha1='.sha1_file($db_backup->backup_dir.'/'.$_FILES['uploaded']['name']); + $md5 = ', md5='.md5_file($filename).', sha1='.sha1_file($filename); - $setup_tpl->set_var('error_msg',lang("succesfully uploaded file %1",$_FILES['uploaded']['name'].', '. - sprintf('%3.1f MB (%d)',$_FILES['uploaded']['size']/(1024*1024),$_FILES['uploaded']['size']).$md5)); + $setup_tpl->set_var('error_msg', ($msg=lang("succesfully uploaded file %1", $filename.', '. + sprintf('%3.1f MB (%d)',$_FILES['uploaded']['size']/(1024*1024),$_FILES['uploaded']['size']))).$md5); + $db_backup->log($filename, $msg); } // delete a backup if (!empty($_POST['delete'])) { - $file = key($_POST['delete']); - $file = $db_backup->backup_dir.'/'.basename($file); // basename to not allow to change the dir + $file = $db_backup->backup_dir.'/'.basename(key($_POST['delete'])); // basename to not allow to change the dir + $db_backup->log($file, lang("backup '%1' deleted", $file)); if (unlink($file)) $setup_tpl->set_var('error_msg',lang("backup '%1' deleted",$file)); } @@ -190,7 +192,11 @@ if (!empty($_POST['rename'])) $file = $db_backup->backup_dir.'/'.basename($file); // basename to not allow to change the dir $ext = preg_match('/(\.gz|\.bz2)+$/i',$file,$matches) ? $matches[1] : ''; $new_file = $db_backup->backup_dir.'/'.preg_replace('/(\.gz|\.bz2)+$/i','',basename($new_name)).$ext; - if (rename($file,$new_file)) $setup_tpl->set_var('error_msg',lang("backup '%1' renamed to '%2'",basename($file),basename($new_file))); + if (rename($file,$new_file)) + { + $setup_tpl->set_var('error_msg',lang("backup '%1' renamed to '%2'",basename($file),basename($new_file))); + $db_backup->log($new_file, lang("backup '%1' renamed to '%2'",basename($file),basename($new_file))); + } } } // restore a backup @@ -201,7 +207,6 @@ if (!empty($_POST['restore'])) if (is_resource($f = $db_backup->fopen_backup($file,true))) { - echo ''.lang('restore started, this might take a few minutes ...')."
\n".str_repeat(' ',4096); $start = time(); $db_backup->restore($f, true, $file); // allways convert to current system charset on restore $setup_tpl->set_var('error_msg',lang("backup '%1' restored",$file).' ('.(time()-$start).' s)'); @@ -274,11 +279,14 @@ foreach($files as $file => $ctime) 'mod' => date('Y-m-d H:i',$ctime), 'size' => sprintf('%3.1f MB (%d)',$size/(1024*1024),$size), 'actions' => ' '."\n". + ($file === Api\Db\Backup::LOG_FILE ? '' : ' '."\n". ' '."\n". - '', + ''), )); $setup_tpl->parse('set_rows','set_row',true); } diff --git a/setup/templates/default/db_backup.tpl b/setup/templates/default/db_backup.tpl index 5372e47593..15c8c1eb38 100644 --- a/setup/templates/default/db_backup.tpl +++ b/setup/templates/default/db_backup.tpl @@ -1,7 +1,14 @@{error_msg}
-