fix: restore falsely deleted coolify-db-backup
This commit is contained in:
		| @@ -7,6 +7,7 @@ use App\Jobs\CleanupHelperContainersJob; | ||||
| use App\Models\Application; | ||||
| use App\Models\ApplicationDeploymentQueue; | ||||
| use App\Models\InstanceSettings; | ||||
| use App\Models\ScheduledDatabaseBackup; | ||||
| use App\Models\Server; | ||||
| use App\Models\Service; | ||||
| use App\Models\ServiceApplication; | ||||
| @@ -31,6 +32,9 @@ class Init extends Command | ||||
|         if ($cleanup) { | ||||
|             echo "Running cleanup\n"; | ||||
|             $this->cleanup_stucked_resources(); | ||||
|             // Required for falsely deleted coolify db
 | ||||
|             $this->restore_coolify_db_backup(); | ||||
| 
 | ||||
|             // $this->cleanup_ssh();
 | ||||
|         } | ||||
|         $this->cleanup_in_progress_application_deployments(); | ||||
| @@ -51,6 +55,30 @@ class Init extends Command | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     private function restore_coolify_db_backup() { | ||||
|         try { | ||||
|             $database = StandalonePostgresql::withTrashed()->find(0); | ||||
|             if ($database) { | ||||
|                 echo "Restoring coolify db backup\n"; | ||||
|                 $database->restore(); | ||||
|                 $scheduledBackup = ScheduledDatabaseBackup::find(0); | ||||
|                 if (!$scheduledBackup) { | ||||
|                     ScheduledDatabaseBackup::create([ | ||||
|                         'id' => 0, | ||||
|                         'enabled' => true, | ||||
|                         'save_s3' => false, | ||||
|                         'frequency' => '0 0 * * *', | ||||
|                         'database_id' => $database->id, | ||||
|                         'database_type' => 'App\Models\StandalonePostgresql', | ||||
|                         'team_id' => 0, | ||||
|                     ]); | ||||
|                 } | ||||
| 
 | ||||
|             } | ||||
|         } catch(\Throwable $e) { | ||||
|             echo "Error in restoring coolify db backup: {$e->getMessage()}\n"; | ||||
|         } | ||||
|     } | ||||
|     private function cleanup_stucked_helper_containers() | ||||
|     { | ||||
|         $servers = Server::all(); | ||||
| @@ -134,7 +162,7 @@ class Init extends Command | ||||
|             echo "Error in application: {$e->getMessage()}\n"; | ||||
|         } | ||||
|         try { | ||||
|             $postgresqls = StandalonePostgresql::all(); | ||||
|             $postgresqls = StandalonePostgresql::all()->where('id', '!=', 0); | ||||
|             foreach ($postgresqls as $postgresql) { | ||||
|                 if (!data_get($postgresql, 'environment')) { | ||||
|                     echo 'Postgresql without environment: ' . $postgresql->name . ' soft deleting\n'; | ||||
|   | ||||
| @@ -7,7 +7,7 @@ return [ | ||||
| 
 | ||||
|     // The release version of your application
 | ||||
|     // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD'))
 | ||||
|     'release' => '4.0.0-beta.173', | ||||
|     'release' => '4.0.0-beta.174', | ||||
|     // When left empty or `null` the Laravel environment will be used
 | ||||
|     'environment' => config('app.env'), | ||||
| 
 | ||||
|   | ||||
| @@ -1,3 +1,3 @@ | ||||
| <?php | ||||
| 
 | ||||
| return '4.0.0-beta.173'; | ||||
| return '4.0.0-beta.174'; | ||||
|   | ||||
| @@ -4,7 +4,7 @@ | ||||
|             "version": "3.12.36" | ||||
|         }, | ||||
|         "v4": { | ||||
|             "version": "4.0.0-beta.173" | ||||
|             "version": "4.0.0-beta.174" | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Andras Bacsai
					Andras Bacsai