Created
August 30, 2024 13:51
-
-
Save abbbi/0f5e36823a023c9f4530846cf6b8e88a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"time" | |
bps "github.com/elbandi/go-proxmox-backup-client" | |
) | |
const ( | |
repo = "HLCO8099QIS65JFCVGCA@[email protected]:backups" | |
password = "CiaQIKdqt5z7zCDMMuhOlJur4Rc+oOo+V01bTNiS" | |
fingerprint = "55:BC:29:4B:BA:B6:A1:03:42:A9:D8:51:14:9D:BD:00:D2:2A:9C:A1:B8:4A:85:E1:AF:B2:0C:48:40:D6:CC:A4" | |
) | |
func backup(id string, backupTime time.Time) { | |
t := uint64(backupTime.Unix()) | |
client, err := bps.NewBackup(repo, "", id, t, password, fingerprint, "", "", false) | |
if err != nil { | |
log.Fatalln(err) | |
} | |
defer client.Close() | |
err = client.AddConfig("test", []byte("test2")) | |
if err != nil { | |
log.Println(err) | |
} | |
image, err := client.RegisterImage("test", 16) | |
if err != nil { | |
log.Println(err) | |
} else { | |
image.WriteAt([]byte("testcontent"), 0) | |
image.Close() | |
} | |
err = client.Finish() | |
if err != nil { | |
log.Println(err) | |
} | |
} | |
func restore(id string, backupTime time.Time) { | |
t := uint64(backupTime.Unix()) | |
client, err := bps.NewRestore(repo, "vm", "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, 11) | |
image.ReadAt(data, 0) | |
fmt.Println(string(data)) | |
} | |
} | |
func main() { | |
fmt.Println(bps.GetVersion()) | |
t := time.Now() | |
fmt.Println("Create backup") | |
backup("testbackup", t) | |
fmt.Println("Restore backup") | |
restore("testbackup", t) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment