This commit is contained in:
Bozhidar 2024-04-29 19:34:15 +03:00
parent e68b198d74
commit 71ba6c2946
2 changed files with 14 additions and 7 deletions

View file

@ -3,6 +3,7 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Models\Backup; use App\Models\Backup;
use App\Models\HostingSubscriptionBackup;
use App\Models\RemoteBackupServer; use App\Models\RemoteBackupServer;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@ -41,12 +42,21 @@ class RunUploadBackupsToRemoteServers extends Command
$findBackups = Backup::where('status', 'completed')->get(); $findBackups = Backup::where('status', 'completed')->get();
if ($findBackups->count() > 0) { if ($findBackups->count() > 0) {
foreach ($findBackups as $backup) { foreach ($findBackups as $backup) {
$uploadStatus = $remoteBackupServer->uploadFile($backup->filepath); $uploadStatus = $remoteBackupServer->uploadFile($backup->filepath, 'phyre-system-backups');
} }
} else { } else {
$this->info('No backups found to upload.'); $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 { } else {
$this->info('No remote backup servers found.'); $this->info('No remote backup servers found.');

View file

@ -73,7 +73,7 @@ class RemoteBackupServer extends Model
} }
public function uploadFile($filepath) public function uploadFile($filepath, $directory)
{ {
$username = trim($this->username); $username = trim($this->username);
$password = trim($this->password); $password = trim($this->password);
@ -82,12 +82,9 @@ class RemoteBackupServer extends Model
if ($this->type == 'ftp') { if ($this->type == 'ftp') {
$path = trim($this->path); $directory = trim($directory);
if ($path == '/') {
$path = '';
}
$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); $uploadCurlCommand = trim($uploadCurlCommand);
$uploadCurlProcess = Process::fromShellCommandline($uploadCurlCommand); $uploadCurlProcess = Process::fromShellCommandline($uploadCurlCommand);