Skip to content
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
916e9a0
fix(backup): Improve cleanup when handling errors
Hipska May 23, 2025
e77b376
chore(backup): Remove redundant commands
Hipska May 23, 2025
3c67eb0
fix(backup): ZipArchiveEx support is removed since 2019
Hipska May 23, 2025
c8c46de
Keep naming consistent
Hipska May 23, 2025
9f4f0e0
Use default backup format
Hipska Jun 20, 2025
e4d21c9
Add option to specify preferred tmp directory in config
Hipska Jun 20, 2025
4e2a674
Update Archive_Tar to 1.6.0
Hipska Jul 23, 2025
bec4813
Run composer update pear/archive_tar
Hipska Sep 12, 2025
396a977
Add test for RestoreFromCompressedBackup failure
Hipska Sep 12, 2025
19ae119
Merge branch 'release/3.2' into fix/backup
Hipska Sep 15, 2025
481fb74
Update composer to revert platform_check.php changes
Hipska Sep 15, 2025
5089f0a
Use integrated RequireOnce method
Hipska Sep 15, 2025
5362f7f
The returned path already contains a slash
Hipska Sep 15, 2025
9149895
Create the directory to ensure it exists
Hipska Sep 15, 2025
cef5319
Add tests for GetTmpDir method
Hipska Sep 15, 2025
d17fa4b
Add breakout detection
Hipska Sep 15, 2025
2bcb4f6
Merge branch 'support/3.2' into fix/backup
Hipska Sep 15, 2025
8952cff
Remove protection to stay inside APPROOT
Hipska Oct 23, 2025
d92eacc
Add support for non-relative paths
Hipska Oct 23, 2025
d75904b
Merge branch 'release/3.2' into fix/backup
Hipska Oct 23, 2025
91a6fd2
Apply comments from review received offline
Hipska Oct 27, 2025
38806e7
Revert unsafe changes
Hipska Oct 27, 2025
bffd654
Returned directory is already created
Hipska Oct 27, 2025
d9cfc9b
Add extra test
Hipska Oct 27, 2025
d8faa78
Apply suggestions from code review
Hipska Nov 7, 2025
f45a085
Merge branch 'release/3.2' into fix/backup
Hipska Dec 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"laminas/laminas-servicemanager": "^3.5",
"league/oauth2-google": "^4.0.1",
"nikic/php-parser": "^4.14.0",
"pear/archive_tar": "~1.4.14",
"pear/archive_tar": "^1.6.0",
"pelago/emogrifier": "^7.2.0",
"psr/log": "^3.0.0",
"scssphp/scssphp": "^1.12.1",
Expand Down
26 changes: 8 additions & 18 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions datamodels/2.x/itop-backup/backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ function ExecuteMainOperation($oP){
exit;
}


$sDefaultBackupFileName = SetupUtils::GetTmpDir().'/'."__DB__-%Y-%m-%d";
$sBackupFile = utils::ReadParam('backup_file', $sDefaultBackupFileName, true, 'raw_data');
$sBackupFile = utils::ReadParam('backup_file', BACKUP_DEFAULT_FORMAT, true, 'raw_data');

// Interpret strftime specifications (like %Y) and database placeholders
$oBackup = new MyDBBackup($oP);
Expand Down
30 changes: 13 additions & 17 deletions datamodels/2.x/itop-backup/dbrestore.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,30 +128,26 @@ public function RestoreFromCompressedBackup($sFile, $sEnvironment = 'production'
IssueLog::Info('Backup Restore - LOCK acquired, executing...');
$bReadonlyBefore = SetupUtils::EnterMaintenanceMode(MetaModel::GetConfig());

$sDataDir = static::GetTmpDir($this->oConfig);
SetupUtils::builddir($sDataDir); // Here is the directory

try {
//safe zone for db backup => cron is stopped/ itop in readonly
$this->LogInfo("Starting restore of ".basename($sFile));


$sNormalizedFile = strtolower(basename($sFile));
if (substr($sNormalizedFile, -4) == '.zip') {
$this->LogInfo('zip file detected');
$oArchive = new ZipArchiveEx();
$oArchive->open($sFile);
} elseif (substr($sNormalizedFile, -7) == '.tar.gz') {
if (str_ends_with($sNormalizedFile, '.tar.gz')) {
$this->LogInfo('tar.gz file detected');
$oArchive = new TarGzArchive($sFile);
if (!$oArchive->extractTo($sDataDir)) {
throw new BackupException('Failed to extract archive.');
}
} else {
throw new BackupException('Unsupported format for a backup file: '.$sFile);
}

// Load the database
//
$sDataDir = APPROOT.'data/tmp-backup-'.rand(10000, getrandmax());

SetupUtils::builddir($sDataDir); // Here is the directory
$oArchive->extractTo($sDataDir);

$sDataFile = $sDataDir.'/itop-dump.sql';
$this->LoadDatabase($sDataFile);

Expand Down Expand Up @@ -187,12 +183,6 @@ public function RestoreFromCompressedBackup($sFile, $sEnvironment = 'production'
rename($sSourceFilePath, $sDestinationFilePath);
}

try {
SetupUtils::rrmdir($sDataDir);
} catch (Exception $e) {
throw new BackupException("Can't remove data dir", 0, $e);
}

$oEnvironment = new RunTimeEnvironment($sEnvironment);
$oEnvironment->CompileFrom($sEnvironment);
} finally {
Expand All @@ -202,6 +192,12 @@ public function RestoreFromCompressedBackup($sFile, $sEnvironment = 'production'
//we are in the scope of main process that needs to handle/keep readonly mode.
$this->LogInfo("Keep maintenance mode after restore");
}

try {
SetupUtils::rrmdir($sDataDir);
} catch (Exception $e) {
throw new BackupException("Can't remove tmp folder", 0, $e);
}
}
}
finally
Expand Down
1 change: 1 addition & 0 deletions datamodels/2.x/itop-backup/module.itop-backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
'retention_count' => 5,
'enabled' => true,
'itop_backup_incident' => '',
'backup_tmpdir' => 'data/',
),
)
);
26 changes: 8 additions & 18 deletions lib/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -1165,22 +1165,22 @@
},
{
"name": "pear/archive_tar",
"version": "1.4.14",
"version_normalized": "1.4.14.0",
"version": "1.6.0",
"version_normalized": "1.6.0.0",
"source": {
"type": "git",
"url": "https://github.com/pear/Archive_Tar.git",
"reference": "4d761c5334c790e45ef3245f0864b8955c562caa"
"reference": "dc3285537f1832da8ddbbe45f5a007248b6cc00e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pear/Archive_Tar/zipball/4d761c5334c790e45ef3245f0864b8955c562caa",
"reference": "4d761c5334c790e45ef3245f0864b8955c562caa",
"url": "https://api.github.com/repos/pear/Archive_Tar/zipball/dc3285537f1832da8ddbbe45f5a007248b6cc00e",
"reference": "dc3285537f1832da8ddbbe45f5a007248b6cc00e",
"shasum": ""
},
"require": {
"pear/pear-core-minimal": "^1.10.0alpha2",
"php": ">=5.2.0"
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "*"
Expand All @@ -1190,7 +1190,7 @@
"ext-xz": "Lzma2 compression support.",
"ext-zlib": "Gzip compression support."
},
"time": "2021-07-20T13:53:39+00:00",
"time": "2025-07-19T14:49:16+00:00",
"type": "library",
"extra": {
"branch-alias": {
Expand All @@ -1208,7 +1208,7 @@
"./"
],
"license": [
"BSD-3-Clause"
"BSD-2-Clause"
],
"authors": [
{
Expand All @@ -1234,16 +1234,6 @@
"issues": "http://pear.php.net/bugs/search.php?cmd=display&package_name[]=Archive_Tar",
"source": "https://github.com/pear/Archive_Tar"
},
"funding": [
{
"url": "https://github.com/mrook",
"type": "github"
},
{
"url": "https://www.patreon.com/michielrook",
"type": "patreon"
}
],
"install-path": "../pear/archive_tar"
},
{
Expand Down
10 changes: 5 additions & 5 deletions lib/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'name' => 'combodo/itop',
'pretty_version' => 'dev-develop',
'version' => 'dev-develop',
'reference' => '7a3e770c00619e93628235b12fe820f3f1ce6c77',
'reference' => '19ae119a551b860d7ff50b5c0f592219ac6b313c',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand All @@ -22,7 +22,7 @@
'combodo/itop' => array(
'pretty_version' => 'dev-develop',
'version' => 'dev-develop',
'reference' => '7a3e770c00619e93628235b12fe820f3f1ce6c77',
'reference' => '19ae119a551b860d7ff50b5c0f592219ac6b313c',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand Down Expand Up @@ -161,9 +161,9 @@
'dev_requirement' => false,
),
'pear/archive_tar' => array(
'pretty_version' => '1.4.14',
'version' => '1.4.14.0',
'reference' => '4d761c5334c790e45ef3245f0864b8955c562caa',
'pretty_version' => '1.6.0',
'version' => '1.6.0.0',
'reference' => 'dc3285537f1832da8ddbbe45f5a007248b6cc00e',
'type' => 'library',
'install_path' => __DIR__ . '/../pear/archive_tar',
'aliases' => array(),
Expand Down
29 changes: 0 additions & 29 deletions lib/pear/archive_tar/.travis.yml

This file was deleted.

Loading