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 6 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 @@ func (n *Node) GetCustomCertificates(ctx context.Context) (certs *NodeCertificat
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?

return nil, fmt.Errorf("empty params")
}

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
}
26 changes: 26 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1242,3 +1242,29 @@ type FirewallIPSet struct {
Digest string `json:"digest,omitempty"`
Comment string `json:"comment,omitempty"`
}

type (
ModeType = string
CompressType = string
Copy link
Owner

Choose a reason for hiding this comment

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

these are already types and "mode" and "compress" are pretty generic and these are specific for the vzdump params. maybe better if you do VirtualMachineBackupMode and VirtualMachineBackupCompress

)

const (
ModeSnapshot = ModeType("snapshot")
ModeSuspend = ModeType("suspend")
ModeStop = ModeType("stop")

CompressZero = CompressType("0")
CompressOne = CompressType("1")
CompressGzip = CompressType("gzip")
CompressLzo = CompressType("lzo")
CompressZstd = CompressType("zstd")
)

type VirtualMachineBackupOptions struct {
VMID uint64 `json:"vmid"`
Storage string `json:"storage"`
Remove int `json:"remove,omitempty"`
Mode ModeType `json:"mode,omitempty"`
Compress CompressType `json:"compress,omitempty"`
Notes string `json:"notes,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