server->service->product->settings()->where('key', 'backups')->first(); if ($settings?->value <= 0) { $this->redirect(route('proxmox.server.overview', $this->server->id), true); return; } $this->backups = $proxmox->request('/nodes/' . $this->server->node->name . '/storage/' . $this->server->node->backup_location . '/content', data: [ 'content' => 'backup', 'vmid' => $this->server->vm_id, ])->json()['data']; } public function restoreBackup() { $this->validate([ 'volid' => 'required', ]); if (!$this->confirmRestore) { $this->notify('Please confirm the restore action', 'error'); return; } // Check if backup exists $backup = collect($this->backups)->firstWhere('volid', $this->volid); if (!$backup) { $this->notify('Backup not found', 'error'); return; } $proxmox = new Proxmox; $proxmox->request('/nodes/' . $this->server->node->name . '/qemu', 'post', data: [ 'vmid' => $this->server->vm_id, 'force' => true, 'archive' => $this->volid, ]); $this->notify('Backup restoration in progress', 'success'); $this->showRestore = false; // Redirect to the server overview page $this->redirect(route('proxmox.server.overview', $this->server->id), true); } public function promptDelete(string $volid): void { $this->volid = $volid; $this->confirmDelete = false; $this->showDelete = true; } public function deleteBackup(?string $volid = null) { $volid = $volid ?? $this->volid; if (!$volid) { $this->notify('Select a backup to delete.', 'error'); return; } if (!$this->confirmDelete) { $this->notify('Please confirm the delete action', 'error'); return; } // Check if backup exists $backup = collect($this->backups)->firstWhere('volid', $volid); if (!$backup) { $this->notify('Backup not found', 'error'); return; } $proxmox = new Proxmox; $proxmox->requestAndWait('/nodes/' . $this->server->node->name . '/qemu/' . $this->server->vm_id . '/status/stop', 'post', [ 'vmid' => $this->server->vm_id, ], $this->server->node->name); $response = $proxmox->request('/nodes/' . $this->server->node->name . '/storage/' . $this->server->node->backup_location . '/content/' . $volid, 'delete'); if ($response->status() == 200) { $this->notify('Backup deleted successfully', 'success'); $this->backups = array_filter($this->backups, fn ($backup) => $backup['volid'] !== $volid); $this->showDelete = false; $this->confirmDelete = false; $this->volid = null; } else { $this->notify('Failed to delete backup: ' . $response->json()['errors'][0]['message'], 'error'); } } public function render() { return view('proxmox::backups')->layoutData([ 'sidebar' => true, ]); } }