Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic backup logic #133

Merged
merged 8 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,16 @@
err = n.client.Get(ctx, fmt.Sprintf("/nodes/%s/certificates/info", n.Name), &certs)
return
}

func (n *Node) Vzdump(ctx context.Context, params *VirtualMachineBackupOptions) (task *Task, err error) {
var upid UPID

if params == nil {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API docs read like all params are optional https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/vzdump

you sure you dont want to allow nil params? I haven't tested this but it reads like empty post data should still create a backup with some form of defaults. maybe confirm and let's drop the check?

params = &VirtualMachineBackupOptions{}
}

Check warning on line 285 in nodes.go

View check run for this annotation

Codecov / codecov/patch

nodes.go#L280-L285

Added lines #L280 - L285 were not covered by tests

if err = n.client.Post(ctx, fmt.Sprintf("/nodes/%s/vzdump", n.Name), params, &upid); err != nil {
return nil, err
}
return NewTask(upid, n.client), nil

Check warning on line 290 in nodes.go

View check run for this annotation

Codecov / codecov/patch

nodes.go#L287-L290

Added lines #L287 - L290 were not covered by tests
}
55 changes: 55 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1242,3 +1242,58 @@ type FirewallIPSet struct {
Digest string `json:"digest,omitempty"`
Comment string `json:"comment,omitempty"`
}

type (
VirtualMachineBackupMode = string
VirtualMachineBackupCompress = string
VirtualMachineBackupNotificationPolicy = string
)

const (
VirtualMachineBackupModeSnapshot = VirtualMachineBackupMode("snapshot")
VirtualMachineBackupModeSuspend = VirtualMachineBackupMode("suspend")
VirtualMachineBackupModeStop = VirtualMachineBackupMode("stop")

VirtualMachineBackupCompressZero = VirtualMachineBackupCompress("0")
VirtualMachineBackupCompressOne = VirtualMachineBackupCompress("1")
VirtualMachineBackupCompressGzip = VirtualMachineBackupCompress("gzip")
VirtualMachineBackupCompressLzo = VirtualMachineBackupCompress("lzo")
VirtualMachineBackupCompressZstd = VirtualMachineBackupCompress("zstd")

VirtualMachineBackupNotificationPolicyAlways = VirtualMachineBackupNotificationPolicy("always")
VirtualMachineBackupNotificationPolicyFailure = VirtualMachineBackupNotificationPolicy("failure")
VirtualMachineBackupNotificationPolicyNever = VirtualMachineBackupNotificationPolicy("never")
)

type VirtualMachineBackupOptions struct {
All bool `json:"all,omitempty"`
BwLimit uint `json:"bwlimit,omitempty"`
Compress VirtualMachineBackupCompress `json:"compress,omitempty"`
DumpDir string `json:"dumpDir,omitempty"`
Exclude string `json:"exclude,omitempty"`
ExcludePath []string `json:"exclude-path,omitempty"`
IoNice uint `json:"ionice,omitempty"`
LockWait uint `json:"lockwait,omitempty"`
MailTo string `json:"mailto,omitempty"`
Mode VirtualMachineBackupMode `json:"mode,omitempty"`
Node string `json:"node,omitempty"`
NotesTemplate string `json:"notes-template,omitempty"`
NotificationPolicy VirtualMachineBackupNotificationPolicy `json:"notification-policy,omitempty"`
NotificationTarget string `json:"notification-target,omitempty"`
Performance string `json:"performance,omitempty"`
Pigz int `json:"pigz,omitempty"`
Pool string `json:"pool,omitempty"`
Protected string `json:"protected,omitempty"`
PruneBackups string `json:"prune-backups,omitempty"`
Quiet bool `json:"quiet,omitempty"`
Remove bool `json:"remove,omitempty"`
Script string `json:"script,omitempty"`
StdExcludes bool `json:"stdexcludes,omitempty"`
StdOut bool `json:"stdout,omitempty"`
Stop bool `json:"stop,omitempty"`
StopWait uint `json:"stopwait,omitempty"`
Storage string `json:"storage,omitempty"`
TmpDir string `json:"tmpdir,omitempty"`
VMID uint64 `json:"vmid,omitempty"`
Zstd uint `json:"zstd,omitempty"`
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really one to talk here as I've definitely not finished param types before but if you could finish the params for this one I would appreciate it as it's an important feature and we should probably do it the first time. https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/vzdump note

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will finish it