go_proxmox_backup_client

package module
v0.0.0-...-b7f2bd6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2023 License: MIT Imports: 3 Imported by: 2

README

go-proxmox-backup-client

Library for accessing the Proxmox Backup API from Go

Example

package main

import (
	"fmt"
	"log"
	bps "github.com/elbandi/go-proxmox-backup-client"
	"time"
)

const (
	repo        = "admin@1.2.3.4:storage"
	password    = "changeme"
	fingerprint = "11:22:33:44:55:66:77..."
)

func backup(id string, backupTime time.Time) {
	t := uint64(backupTime.Unix())
	client, err := bps.NewBackup(repo, id, t, password, fingerprint)
	if err != nil {
		log.Fatalln(err)
	}
	defer client.Close()

	err = client.AddConfig("test", []byte("test2"))
	log.Println(err)

	image, err := client.RegisterImage("test", 16)
	if err != nil {
		log.Println(err)
	} else {
		fmt.Println(image.Write([]byte("1234567890123456"), 0))
		fmt.Println(image.Close())
	}
	err = client.Finish()
	log.Println(err)
}

func restore(id string, backupTime time.Time) {
	t := uint64(backupTime.Unix())
	client, err := bps.NewRestore(repo, "vm", id, t, password, fingerprint)
	if err != nil {
		log.Fatalln(err)
	}
	defer client.Close()

	image, err := client.OpenImage("test.img.fidx")
	if err != nil {
		log.Println(err)
	} else {
		data := make([]byte, 10)
		fmt.Println(image.ReadAt(data, 10))
		fmt.Println(string(data))
	}
}

func main() {
	fmt.Println(bps.GetVersion())
	t := time.Now()
	backup("123", t)
	restore("123", t)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDefaultChunkSize

func GetDefaultChunkSize() uint64

func GetVersion

func GetVersion() string

Types

type BackupImage

type BackupImage struct {
	// contains filtered or unexported fields
}

func (*BackupImage) Close

func (image *BackupImage) Close() error

func (*BackupImage) WriteAt

func (image *BackupImage) WriteAt(data []byte, offset int64) (int, error)

type ProxmoxBackup

type ProxmoxBackup struct {
	// contains filtered or unexported fields
}

func NewBackup

func NewBackup(repo string, namespace string, id string, backupTime uint64, password string, fingerprint string, keyFile string, keyPassword string, compress bool) (*ProxmoxBackup, error)

func (*ProxmoxBackup) Abort

func (pbs *ProxmoxBackup) Abort(reason string)

func (*ProxmoxBackup) AddConfig

func (pbs *ProxmoxBackup) AddConfig(name string, data []byte) error

func (*ProxmoxBackup) Close

func (pbs *ProxmoxBackup) Close()

func (*ProxmoxBackup) Finish

func (pbs *ProxmoxBackup) Finish() error

func (*ProxmoxBackup) RegisterImage

func (pbs *ProxmoxBackup) RegisterImage(name string, size uint64) (*BackupImage, error)

type ProxmoxRestore

type ProxmoxRestore struct {
	// contains filtered or unexported fields
}

func NewRestore

func NewRestore(repo string, namespace string, btype string, id string, backupTime uint64, password string, fingerprint string, keyFile string, keyPassword string) (*ProxmoxRestore, error)

func (*ProxmoxRestore) Close

func (pbs *ProxmoxRestore) Close()

func (*ProxmoxRestore) OpenImage

func (pbs *ProxmoxRestore) OpenImage(name string) (*RestoreImage, error)

type RestoreImage

type RestoreImage struct {
	// contains filtered or unexported fields
}

func (*RestoreImage) ReadAt

func (image *RestoreImage) ReadAt(p []byte, off int64) (int, error)

func (*RestoreImage) Size

func (image *RestoreImage) Size() (uint64, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL