option('bucket') ?: config('filesystems.s3.bucket') ?: $serverName; if (!$bucket) { $this->error("Backup bucket not configured!"); return 1; } $this->info("Using backup bucket: $bucket"); $this->info("Starting DOWNLOAD process..."); // 2️⃣ Download ALL .sql.gz files $downloadCommand = "rclone copy s3:$bucket/databases/ /root/ --include \"*.sql.gz\" --progress"; exec($downloadCommand, $downloadOutput, $downloadResult); if ($downloadResult !== 0) { $this->error("Failed to download databases backups ❌"); return 1; } $this->info("Download completed ✅"); // 3️⃣ Unzip and delete .gz files $files = glob('/root/*.sql.gz'); if (empty($files)) { $this->error("No .sql.gz files found in /root ❌"); return 1; } foreach ($files as $file) { $this->info("Unzipping: " . basename($file)); $unzipCommand = "gzip -d -f $file"; exec($unzipCommand, $unzipOutput, $unzipResult); if ($unzipResult !== 0) { $this->error("Failed to unzip $file ❌"); continue; } $this->info("Unzipped successfully ✅"); // 🗑️ Delete the .gz file after successful unzip if (file_exists($file)) { unlink($file); $this->info("Deleted compressed file: " . basename($file) . " 🗑️"); } } $this->info("Process finished 🎯"); return 0; } }