From 71ba6c294642d0c196f5cd9371ca8b899c907e44 Mon Sep 17 00:00:00 2001 From: Bozhidar Date: Mon, 29 Apr 2024 19:34:15 +0300 Subject: [PATCH] update --- .../Commands/RunUploadBackupsToRemoteServers.php | 12 +++++++++++- web/app/Models/RemoteBackupServer.php | 9 +++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/web/app/Console/Commands/RunUploadBackupsToRemoteServers.php b/web/app/Console/Commands/RunUploadBackupsToRemoteServers.php index 596cf3f..b3d38ae 100644 --- a/web/app/Console/Commands/RunUploadBackupsToRemoteServers.php +++ b/web/app/Console/Commands/RunUploadBackupsToRemoteServers.php @@ -3,6 +3,7 @@ namespace App\Console\Commands; use App\Models\Backup; +use App\Models\HostingSubscriptionBackup; use App\Models\RemoteBackupServer; use Illuminate\Console\Command; @@ -41,12 +42,21 @@ class RunUploadBackupsToRemoteServers extends Command $findBackups = Backup::where('status', 'completed')->get(); if ($findBackups->count() > 0) { foreach ($findBackups as $backup) { - $uploadStatus = $remoteBackupServer->uploadFile($backup->filepath); + $uploadStatus = $remoteBackupServer->uploadFile($backup->filepath, 'phyre-system-backups'); } } else { $this->info('No backups found to upload.'); } + $findHostingSubscriptionBackups = HostingSubscriptionBackup::where('status', 'completed')->get(); + if ($findHostingSubscriptionBackups->count() > 0) { + foreach ($findHostingSubscriptionBackups as $hostingSubscriptionBackup) { + $uploadStatus = $remoteBackupServer->uploadFile($hostingSubscriptionBackup->filepath, 'phyre-hosting-subscription-backups'); + } + } else { + $this->info('No hosting subscription backups found to upload.'); + } + } } else { $this->info('No remote backup servers found.'); diff --git a/web/app/Models/RemoteBackupServer.php b/web/app/Models/RemoteBackupServer.php index adef308..3ed222a 100644 --- a/web/app/Models/RemoteBackupServer.php +++ b/web/app/Models/RemoteBackupServer.php @@ -73,7 +73,7 @@ class RemoteBackupServer extends Model } - public function uploadFile($filepath) + public function uploadFile($filepath, $directory) { $username = trim($this->username); $password = trim($this->password); @@ -82,12 +82,9 @@ class RemoteBackupServer extends Model if ($this->type == 'ftp') { - $path = trim($this->path); - if ($path == '/') { - $path = ''; - } + $directory = trim($directory); - $uploadCurlCommand = "curl -T $filepath ftp://$username:$password@$hostname:$port "." $path"; + $uploadCurlCommand = "curl -T $filepath ftp://$hostname:$port/$directory/ -u '$username:$password' --ftp-create-dirs"; $uploadCurlCommand = trim($uploadCurlCommand); $uploadCurlProcess = Process::fromShellCommandline($uploadCurlCommand);