Browse Source

fixed issue if backup folder was inside data folder (#1891)

CauseFX 3 years ago
parent
commit
865bbefc40
1 changed files with 3 additions and 5 deletions
  1. 3 5
      api/functions/backup-functions.php

+ 3 - 5
api/functions/backup-functions.php

@@ -75,9 +75,9 @@ trait BackupFunctions
 			default:
 		}
 		$this->setLoggerChannel('Backup')->notice('Backing up Organizr');
-		$zipname = $directory . 'backup[' . date('Y-m-d_H-i') . ' - ' . $this->random_ascii_string(2) . '][' . $this->version . '].zip';
+		$zipName = $directory . 'backup[' . date('Y-m-d_H-i') . ' - ' . $this->random_ascii_string(2) . '][' . $this->version . '].zip';
 		$zip = new ZipArchive;
-		$zip->open($zipname, ZipArchive::CREATE);
+		$zip->open($zipName, ZipArchive::CREATE);
 		if ($this->config['driver'] == 'sqlite3') {
 			$zip->addFile($this->config['dbLocation'] . $this->config['dbName'], basename($this->config['dbLocation'] . $this->config['dbName']));
 		}
@@ -87,7 +87,7 @@ trait BackupFunctions
 		foreach ($files as $name => $file) {
 			// Skip directories (they would be added automatically)
 			if (!$file->isDir()) {
-				if (stripos($name, 'data' . DIRECTORY_SEPARATOR . 'cache') == false) {
+				if (!stripos($name, 'data' . DIRECTORY_SEPARATOR . 'cache') && !stripos($name, 'backups')) {
 					// Get real and relative path for current file
 					$filePath = $file->getRealPath();
 					$relativePath = substr($filePath, strlen($rootPath));
@@ -96,8 +96,6 @@ trait BackupFunctions
 				}
 			}
 		}
-
-
 		$zip->close();
 		$this->setLoggerChannel('Backup')->notice('Backup process finished');
 		$this->setAPIResponse('success', 'Backup has been created', 200);