DeleteBackup deletes a backup volume.
(vm *VM, volID string)
| 208 | |
| 209 | // DeleteBackup deletes a backup volume. |
| 210 | func (c *Client) DeleteBackup(vm *VM, volID string) error { |
| 211 | // volID format: "storage:backup/filename" |
| 212 | // We need to call DELETE /nodes/{node}/storage/{storage}/content/{volume} |
| 213 | |
| 214 | // Parse storage and volume from volID |
| 215 | parts := strings.SplitN(volID, ":", 2) |
| 216 | if len(parts) != 2 { |
| 217 | return fmt.Errorf("invalid volume ID format: %s", volID) |
| 218 | } |
| 219 | |
| 220 | storageName := parts[0] |
| 221 | // Use the full volume ID (e.g. "storage:backup/file") as the volume parameter |
| 222 | // Proxmox API expects the full ID for the content endpoint |
| 223 | encodedVolume := url.PathEscape(volID) |
| 224 | |
| 225 | path := fmt.Sprintf("/nodes/%s/storage/%s/content/%s", vm.Node, storageName, encodedVolume) |
| 226 | |
| 227 | c.logger.Info("Deleting backup '%s' for %s %s", volID, vm.Type, vm.Name) |
| 228 | |
| 229 | var result map[string]interface{} |
| 230 | err := c.httpClient.Delete(context.Background(), path, &result) |
| 231 | if err != nil { |
| 232 | c.logger.Error("DeleteBackup API request failed: %v", err) |
| 233 | return fmt.Errorf("delete request failed: %w", err) |
| 234 | } |
| 235 | |
| 236 | // Check result |
| 237 | if upid, ok := result["data"].(string); ok && strings.HasPrefix(upid, "UPID:") { |
| 238 | // It returns a UPID. |
| 239 | return c.waitForTaskCompletion(upid, "backup deletion") |
| 240 | } |
| 241 | |
| 242 | return nil |
| 243 | } |
| 244 | |
| 245 | // RestoreBackup restores a backup to the VM. |
| 246 | // If the VM exists, it will be overwritten. |
nothing calls this directly
no test coverage detected