From 959a03214aee7254f5f3f15fc5730224c10df9d3 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 2 May 2024 11:45:53 +0200 Subject: [PATCH] fix: mongo 4.0 db backup --- app/Jobs/DatabaseBackupJob.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/app/Jobs/DatabaseBackupJob.php b/app/Jobs/DatabaseBackupJob.php index a09ebeada..ed9694536 100644 --- a/app/Jobs/DatabaseBackupJob.php +++ b/app/Jobs/DatabaseBackupJob.php @@ -318,10 +318,15 @@ class DatabaseBackupJob implements ShouldQueue, ShouldBeEncrypted private function backup_standalone_mongodb(string $databaseWithCollections): void { try { + ray($this->database->toArray()); $url = $this->database->get_db_url(useInternal: true); if ($databaseWithCollections === 'all') { $commands[] = "mkdir -p " . $this->backup_dir; - $commands[] = "docker exec $this->container_name mongodump --authenticationDatabase=admin --uri=$url --gzip --archive > $this->backup_location"; + if (str($this->database->image)->startsWith('mongo:4.0')) { + $commands[] = "docker exec $this->container_name mongodump --uri=$url --gzip --archive > $this->backup_location"; + } else { + $commands[] = "docker exec $this->container_name mongodump --authenticationDatabase=admin --uri=$url --gzip --archive > $this->backup_location"; + } } else { if (str($databaseWithCollections)->contains(':')) { $databaseName = str($databaseWithCollections)->before(':'); @@ -332,9 +337,17 @@ class DatabaseBackupJob implements ShouldQueue, ShouldBeEncrypted } $commands[] = "mkdir -p " . $this->backup_dir; if ($collectionsToExclude->count() === 0) { - $commands[] = "docker exec $this->container_name mongodump --authenticationDatabase=admin --uri=$url --db $databaseName --gzip --archive > $this->backup_location"; + if (str($this->database->image)->startsWith('mongo:4.0')) { + $commands[] = "docker exec $this->container_name mongodump --uri=$url --gzip --archive > $this->backup_location"; + } else { + $commands[] = "docker exec $this->container_name mongodump --authenticationDatabase=admin --uri=$url --db $databaseName --gzip --archive > $this->backup_location"; + } } else { - $commands[] = "docker exec $this->container_name mongodump --authenticationDatabase=admin --uri=$url --db $databaseName --gzip --excludeCollection " . $collectionsToExclude->implode(' --excludeCollection ') . " --archive > $this->backup_location"; + if (str($this->database->image)->startsWith('mongo:4.0')) { + $commands[] = "docker exec $this->container_name mongodump --uri=$url --gzip --excludeCollection " . $collectionsToExclude->implode(' --excludeCollection ') . " --archive > $this->backup_location"; + } else { + $commands[] = "docker exec $this->container_name mongodump --authenticationDatabase=admin --uri=$url --db $databaseName --gzip --excludeCollection " . $collectionsToExclude->implode(' --excludeCollection ') . " --archive > $this->backup_location"; + } } } $this->backup_output = instant_remote_process($commands, $this->server);