Commit e980fb51 authored by Jorge Muñoz's avatar Jorge Muñoz
Browse files

Fix an error where it wouldnt detect a manual database name to download

parent 40fd6cab
Pipeline #9148 passed with stage
in 10 minutes and 17 seconds
......@@ -1927,7 +1927,7 @@ class backup
return $success;
}
public static function restoreBackupDatabaseRepos($backup_format, $password, $backup_dir, $archive_name, $backup_mode, $backup_type)
public static function restoreBackupDatabaseRepos($backup_format, $password, $backup_dir, $backup_archive, $backup_mode, $backup_type)
{
global $app;
......@@ -1938,21 +1938,21 @@ class backup
$backup_format = 'borg';
}
$success = false;
preg_match('@^(manual-)?db_(?P<db>.+)_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}$@', $archive_name, $matches);
preg_match('@^(manual-)?db_(?P<db>.+)_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}$@', $backup_archive, $matches);
if (!isset($matches['db']) || empty($matches['db'])) {
$app->log('Failed to detect database name during restore of ' . $archive_name, LOGLEVEL_ERROR);
$app->log('Failed to detect database name during restore of ' . $backup_archive, LOGLEVEL_ERROR);
return false;
}
$db_name = $matches['db'];
$backup_repos_folder = self::getBackupReposFolder($backup_format, 'mysql') . '_' . $db_name;
$backup_repos_path = $backup_dir . DIRECTORY_SEPARATOR . $backup_repos_folder;
$full_archive_path = $backup_repos_path . '::' . $archive_name;
$full_archive_path = $backup_repos_path . '::' . $backup_archive;
$app->log('Restoring MySQL backup ' . $full_archive_path . ', backup format "' . $backup_format . '", backup mode "' . $backup_mode . '"', LOGLEVEL_DEBUG);
$archives = self::getReposArchives($backup_format, $backup_repos_path, $password);
if (is_array($archives) && in_array($archive_name, $archives)) {
if (is_array($archives) && in_array($backup_archive, $archives)) {
switch ($backup_format) {
case "borg":
$password_cmd = self::getPasswordCommand($backup_format, $password);
......@@ -1984,7 +1984,7 @@ class backup
return $success;
}
public static function restoreBackupWebFilesRepos($backup_format, $password, $backup_dir, $archive_name, $backup_mode, $backup_type, $web_root, $web_user, $web_group)
public static function restoreBackupWebFilesRepos($backup_format, $password, $backup_dir, $backup_archive, $backup_mode, $backup_type, $web_root, $web_user, $web_group)
{
global $app;
......@@ -1993,7 +1993,7 @@ class backup
}
$backup_repos_folder = self::getBackupReposFolder($backup_format, 'web');
$backup_repos_path = $backup_dir . DIRECTORY_SEPARATOR . $backup_repos_folder;
$full_archive_path = $backup_repos_path . '::' . $archive_name;
$full_archive_path = $backup_repos_path . '::' . $backup_archive;
$result = false;
$app->log('Restoring web backup ' . $full_archive_path . ', backup format "' . $backup_format . '", backup mode "' . $backup_mode . '"', LOGLEVEL_DEBUG);
......@@ -2003,7 +2003,7 @@ class backup
$user_mode = $backup_mode == 'userzip';
$archives = self::getReposArchives($backup_format, $backup_repos_path, $password);
if (in_array($archive_name, $archives) && $web_root != '' && $web_root != '/' && !stristr($full_filename, '..') && !stristr($full_filename, 'etc')) {
if (in_array($backup_archive, $archives) && $web_root != '' && $web_root != '/' && !stristr($full_filename, '..') && !stristr($full_filename, 'etc')) {
$success = false;
$retval = 0;
switch ($backup_format) {
......@@ -2043,7 +2043,7 @@ class backup
if ($backup_type != 'web') {
preg_match('@^(manual-)?db_(?P<db>.+)_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}$@', $backup_archive, $matches);
if (!isset($matches['db']) || empty($matches['db'])) {
$app->log('Failed to detect database name during restore of ' . $archive_name, LOGLEVEL_ERROR);
$app->log('Failed to detect database name during restore of ' . $backup_archive, LOGLEVEL_ERROR);
return false;
}
$db_name = $matches['db'];
......@@ -2081,16 +2081,17 @@ class backup
{
global $app;
if (self::formatIsRepos($backup_format, $backup_type)) {
$archive_name = $filename;
$backup_archive = $filename;
if ($backup_type == 'web') {
$backup_repos_folder = self::getBackupReposFolder($backup_format, 'web');
$filename .= '.tar.gz';
} else {
if ( ! preg_match('@^db_(.+)_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}$@', $archive_name, $matches)) {
$app->log('Failed to detect database name during restore of ' . $archive_name, LOGLEVEL_ERROR);
preg_match('@^(manual-)?db_(?P<db>.+)_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}$@', $backup_archive, $matches);
if (!isset($matches['db']) || empty($matches['db'])) {
$app->log('Failed to detect database name during restore of ' . $backup_archive, LOGLEVEL_ERROR);
return false;
}
$db_name = $matches[1];
$db_name = $matches['db'];
$backup_repos_folder = self::getBackupReposFolder($backup_format, $backup_type) . '_' . $db_name;
if ($backup_type == 'mysql') {
$filename .= '.sql.gz';
......@@ -2099,9 +2100,9 @@ class backup
}
}
$backup_repos_path = $backup_dir . DIRECTORY_SEPARATOR . $backup_repos_folder;
$full_archive_path = $backup_repos_path . '::' . $archive_name;
$full_archive_path = $backup_repos_path . '::' . $backup_archive;
$archives = self::getReposArchives($backup_format, $backup_repos_path, $password);
if ( $archives === FALSE || ! in_array($archive_name, $archives)) {
if ( $archives === FALSE || ! in_array($backup_archive, $archives)) {
$app->log('Failed to find archive ' . $full_archive_path . ' for download', LOGLEVEL_ERROR);
return false;
}
......
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