refactor(database-backup): move unique UUID generation for backup execution to database loop
- Refactored the DatabaseBackupJob to generate a unique UUID for each database backup execution within the loop, improving clarity and ensuring uniqueness for each backup attempt. - Removed redundant UUID generation logic from the initial part of the handle method.
This commit is contained in:
@@ -79,16 +79,6 @@ class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue
|
|||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$attempts = 0;
|
|
||||||
do {
|
|
||||||
$this->backup_log_uuid = (string) new Cuid2;
|
|
||||||
$exists = ScheduledDatabaseBackupExecution::where('uuid', $this->backup_log_uuid)->exists();
|
|
||||||
$attempts++;
|
|
||||||
if ($attempts >= 3 && $exists) {
|
|
||||||
throw new \Exception('Unable to generate unique UUID for backup execution after 3 attempts');
|
|
||||||
}
|
|
||||||
} while ($exists);
|
|
||||||
|
|
||||||
$databasesToBackup = null;
|
$databasesToBackup = null;
|
||||||
|
|
||||||
$this->team = Team::find($this->backup->team_id);
|
$this->team = Team::find($this->backup->team_id);
|
||||||
@@ -296,6 +286,17 @@ class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue
|
|||||||
$this->backup_dir = backup_dir().'/coolify'."/coolify-db-$ip";
|
$this->backup_dir = backup_dir().'/coolify'."/coolify-db-$ip";
|
||||||
}
|
}
|
||||||
foreach ($databasesToBackup as $database) {
|
foreach ($databasesToBackup as $database) {
|
||||||
|
// Generate unique UUID for each database backup execution
|
||||||
|
$attempts = 0;
|
||||||
|
do {
|
||||||
|
$this->backup_log_uuid = (string) new Cuid2;
|
||||||
|
$exists = ScheduledDatabaseBackupExecution::where('uuid', $this->backup_log_uuid)->exists();
|
||||||
|
$attempts++;
|
||||||
|
if ($attempts >= 3 && $exists) {
|
||||||
|
throw new \Exception('Unable to generate unique UUID for backup execution after 3 attempts');
|
||||||
|
}
|
||||||
|
} while ($exists);
|
||||||
|
|
||||||
$size = 0;
|
$size = 0;
|
||||||
try {
|
try {
|
||||||
if (str($databaseType)->contains('postgres')) {
|
if (str($databaseType)->contains('postgres')) {
|
||||||
|
Reference in New Issue
Block a user