Documentation
¶
Overview ¶
Package gopbs creates PXAR archives (Proxmox archive format, versions 1 and 2) and uploads them to Proxmox Backup Server.
The subpackages are usable independently:
- pxar: the pure PXAR format layer (record encoders, goodbye tables)
- catalog: the .pcat1 catalog encoder (v1 archives)
- scan: filesystem scanning with full metadata recording (Linux only currently)
- archive: archive planning and (async) stream generation
- chunker: the buzhash chunker used by PBS
- pbs: the Proxmox Backup Server client (backup sessions, chunk upload)
This package ties them together with Backup: one call that scans, plans, generates, chunks, deduplicates and uploads with no intermediate files.
Index ¶
- func Browse(ctx context.Context, sess *pbs.ReaderSession, name string) (*catalog.Entry, error)
- func OpenArchive(ctx context.Context, sess *pbs.ReaderSession, name string) (*pxar.FS, error)
- func OpenSnapshot(ctx context.Context, cfg pbs.Config, ref pbs.SnapshotRef, ...) (*pbs.ReaderSession, error)
- type BackupOptions
- type BackupResult
- type Blob
- type Format
- type Progress
- type RestoreOptions
- type RestoreResult
- type Stream
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Browse ¶ added in v0.4.0
Browse returns an archive's directory tree with names, types, and file sizes and mtimes, without reading file contents: from the .pcat1 catalog for a v1 archive that has one, otherwise from the archive's metadata (for v2 the metadata stream alone). The returned root is the archive root, named by its index file ("root.pxar.didx", "root.mpxar.didx").
func OpenArchive ¶ added in v0.4.0
OpenArchive opens one archive of a snapshot as a file system, for browsing and reading single files; only the chunks a lookup or read touches are downloaded. name is the archive name as given to Backup.
func OpenSnapshot ¶ added in v0.4.0
func OpenSnapshot(ctx context.Context, cfg pbs.Config, ref pbs.SnapshotRef, masterKey *rsa.PrivateKey) (*pbs.ReaderSession, error)
OpenSnapshot opens a reader session on a snapshot. Type defaults to "host", ID to the hostname, and a zero Time selects the group's newest snapshot. With masterKey set and cfg.Crypt nil, the encryption key is recovered from the snapshot first (see pbs.ReaderSession.RecoverKey) and the returned session reads with it. Close the session when done.
Types ¶
type BackupOptions ¶
type BackupOptions struct {
// Client configures the PBS connection (server, auth, datastore,
// namespace, upload workers, chunk size). Set Client.Crypt to encrypt
// the backup client-side (or sign its manifest); see pbs.CryptConfig.
Client pbs.Config
// Archive configures generation (name, workers, buffer, scan policy).
// Exclusions live in Archive.Scan: Exclude patterns in
// proxmox-backup-client syntax (recorded in the archive like the
// official client's --exclude: a .pxarexclude-cli root file in v1, the
// prelude in v2), PxarExcludeFiles to honour .pxarexclude files in the
// tree, and Filter for arbitrary caller logic that leaves no trace in
// the archive. Invalid patterns fail before any connection is made.
// Its OnWarn is honored in addition to warnings being collected into
// the result.
Archive archive.Options
// Ref identifies the snapshot; zero-value fields get the usual defaults
// (type "host", hostname id, current time).
Ref pbs.SnapshotRef
// Format selects the archive format (FormatV1 or FormatV2).
Format Format
// Paths are the directories and files to back up. A single directory
// becomes the archive root; any other combination lives under a virtual
// root named Archive.Name.
Paths []string
// Streams are virtual files backed by readers, placed under the virtual
// root alongside Paths. Readers are consumed during the backup, so a
// BackupOptions value with streams is good for one call.
Streams []Stream
// Trees are caller-built virtual directory trees (scan.KindDirectory
// nodes with scan.KindStream leaves), see archive.Archive.AddTree. A
// single tree and nothing else is the archive root; otherwise each tree
// sits under the virtual root with its own name. Like Streams, good for
// one call.
Trees []*scan.Node
// Blobs are uploaded as separate blob files in the snapshot, alongside
// the archive indexes and listed in the manifest — they are not part of
// the archive. Use them for backup metadata PBS has no native place for
// (application state, retention hints, tool versions, …). Contents are
// downloaded back with `proxmox-backup-client restore <snapshot>
// <name>.blob <target>`.
Blobs []Blob
// SkipCatalog omits the .pcat1 upload (the snapshot will not be
// browsable in the PBS UI). FormatV1 only; v2 has no catalog.
SkipCatalog bool
// OnProgress, when set, receives live upload progress: one call per
// committed chunk plus a final call with Done=true per index. Setting it
// costs one extra metadata scan (the size estimate for Total). Called
// from the uploading goroutine; keep it fast. FormatV2 uploads its two
// indexes concurrently, so calls can arrive from two goroutines at once —
// synchronize any shared state.
OnProgress func(Progress)
}
BackupOptions configures one Backup call.
type BackupResult ¶
type BackupResult struct {
// Ref is the snapshot identity as written (defaults resolved) — what a
// restore addresses.
Ref pbs.SnapshotRef
// ArchiveName is the uploaded index name: "<base>.pxar.didx" for v1, the
// metadata stream's "<base>.mpxar.didx" for v2.
ArchiveName string
// Archive is the pxar index's upload stats (the metadata stream's, for
// v2).
Archive pbs.UploadStats
// Catalog is the .pcat1 index's upload stats (v1 only).
Catalog pbs.UploadStats
// Payload is the payload stream's ("<base>.ppxar.didx") upload stats
// (v2 only).
Payload pbs.UploadStats
// Warnings collects the non-fatal generation events (skipped entries,
// padded/truncated files, torn reads).
Warnings []archive.Warning
// Reuse reports metadata change detection (v2 with Archive.Previous)
Reuse archive.ReuseStats
}
BackupResult reports a finished backup.
func Backup ¶
func Backup(ctx context.Context, opts BackupOptions) (*BackupResult, error)
Backup performs one complete backup: scan → plan → generate → chunk → deduplicate → upload → catalog → manifest → finish, fully streamed.
Example ¶
A complete backup in one call: scan, plan, generate, chunk, deduplicate against the previous snapshot, upload, catalog, manifest, finish.
package main
import (
"context"
"fmt"
"log"
"github.com/osshield/gopbs"
"github.com/osshield/gopbs/archive"
"github.com/osshield/gopbs/pbs"
"github.com/osshield/gopbs/scan"
)
func main() {
result, err := gopbs.Backup(context.Background(), gopbs.BackupOptions{
Client: pbs.Config{
BaseURL: "https://pbs.example.com:8007",
Auth: pbs.TokenAuth{AuthID: "backup@pbs!mytoken", Secret: "…"},
Fingerprint: "AA:BB:…", // sha256 of the server certificate
Datastore: "backups",
},
Archive: archive.Options{
Name: "root",
Scan: scan.Options{SkipOnError: true},
},
Ref: pbs.SnapshotRef{Type: "host", ID: "myhost"},
Paths: []string{"/etc", "/srv"},
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s/%s/%s: %d bytes in %d chunks (%d new)\n",
result.Ref.Type, result.Ref.ID, result.Ref.Time,
result.Archive.Size, result.Archive.ChunkCount, result.Archive.NewChunks)
}
Output:
type Blob ¶
Blob is a metadata file for BackupOptions.Blobs: stored in the snapshot as "<Name>.blob" (the suffix is appended when missing), zstd-compressed when that is smaller. Data is held in memory — blobs are for small metadata; bulk content belongs in the archive or a Stream. The name "index.json" is reserved for the manifest, "rsa-encrypted.key" for the wrapped encryption key. Blobs are encrypted when Client.Crypt is in encrypt mode.
type Format ¶
type Format int
Format selects the pxar archive format.
const ( // FormatV1 is the classic single-stream pxar plus a .pcat1 catalog. FormatV1 Format = iota // FormatV2 is the split format: a metadata stream (.mpxar) and a payload // stream (.ppxar) uploaded as two dynamic indexes. No catalog — the // metadata stream itself serves browsing. Requires proxmox-backup-client // >= 3.2 to restore. FormatV2 )
type Progress ¶
type Progress struct {
// Archive is the index being uploaded (e.g. "root.pxar.didx" or
// "catalog.pcat1.didx").
Archive string
// Total is the estimated byte size of this index from scan metadata
// (0 = unknown; the catalog has no estimate). The actual size may
// differ slightly when files change during the backup.
Total uint64
// Stats carries the live counters; Stats.Size is the number of bytes
// committed so far and grows monotonically per index.
Stats pbs.UploadStats
// Done marks the final report for this index.
Done bool
}
Progress is one live progress report during Backup.
type RestoreOptions ¶ added in v0.4.0
type RestoreOptions struct {
// Client configures the PBS connection. For an encrypted backup set
// Client.Crypt to its key, or MasterKey.
Client pbs.Config
// MasterKey, used when Client.Crypt is nil, recovers the encryption key
// from the snapshot's master-key wrapped copy (see pbs.LoadMasterKey).
MasterKey *rsa.PrivateKey
// Ref selects the snapshot: Type defaults to "host", ID to the
// hostname, and a zero Time selects the group's newest snapshot.
Ref pbs.SnapshotRef
// Archive is the archive name as given to Backup (Archive.Name; empty
// means "backup"); v1 and v2 are told apart by the snapshot manifest.
Archive string
// Target is the directory to restore into. It must be missing or
// empty unless Restore.Overwrite is set.
Target string
// Paths restricts the restore to these archive paths and their
// subtrees, read by random access (hardlinks become copies). Empty
// restores the whole archive in one streamed pass.
Paths []string
// Restore configures writing: Overwrite, the MetadataWriter, and
// OnWarn, which is called in addition to warnings being collected into
// the result.
Restore restore.Options
}
RestoreOptions configures one Restore call.
type RestoreResult ¶ added in v0.4.0
type RestoreResult struct {
// Ref is the snapshot restored, with defaults resolved.
Ref pbs.SnapshotRef
// Format is the archive's format.
Format Format
// Warnings collects the non-fatal events: metadata that could not be
// applied, entries the platform cannot create.
Warnings []restore.Warning
}
RestoreResult reports what Restore did.
func Restore ¶ added in v0.4.0
func Restore(ctx context.Context, opts RestoreOptions) (*RestoreResult, error)
Restore restores one archive of a snapshot into a directory.
A full restore streams the archive once, fetching Client.Workers chunks in parallel (the payload stream of a v2 archive is read by random access). Everything read is verified: the manifest (and its signature, with a key), every index against the manifest, every chunk against its digest.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package archive turns scanned node trees into PXAR archive streams.
|
Package archive turns scanned node trees into PXAR archive streams. |
|
Package catalog encodes the Proxmox .pcat1 catalog format used alongside PXAR v1 archives.
|
Package catalog encodes the Proxmox .pcat1 catalog format used alongside PXAR v1 archives. |
|
Package chunker implements the buzhash content-defined chunker used by Proxmox Backup Server (a port of pbs-datastore's chunker): a 64-byte rolling window over the casync hash table, cutting chunks between min (avg/4) and max (avg*4) with a 4 MiB default average.
|
Package chunker implements the buzhash content-defined chunker used by Proxmox Backup Server (a port of pbs-datastore's chunker): a 64-byte rolling window over the casync hash table, cutting chunks between min (avg/4) and max (avg*4) with a 4 MiB default average. |
|
cmd
|
|
|
gopbs-pxar
command
Command gopbs-pxar creates a PXAR archive from a directory tree.
|
Command gopbs-pxar creates a PXAR archive from a directory tree. |
|
examples
|
|
|
backup-async
command
Command backup-async backs up a directory to Proxmox Backup Server with a single gopbs.Backup call, using asynchronous archive generation (the library default): the tree layout is planned first, then a pool of workers reads file contents in parallel while the stream is chunked, deduplicated against the previous snapshot, and uploaded concurrently.
|
Command backup-async backs up a directory to Proxmox Backup Server with a single gopbs.Backup call, using asynchronous archive generation (the library default): the tree layout is planned first, then a pool of workers reads file contents in parallel while the stream is chunked, deduplicated against the previous snapshot, and uploaded concurrently. |
|
backup-streams
command
Command backup-streams backs up multiple streams of data — virtual files that exist nowhere on disk — in one gopbs.Backup call.
|
Command backup-streams backs up multiple streams of data — virtual files that exist nowhere on disk — in one gopbs.Backup call. |
|
backup-sync
command
Command backup-sync backs up a directory to Proxmox Backup Server with a single gopbs.Backup call, using fully synchronous archive generation (Archive.Workers: 1): one goroutine walks the tree and reads contents, producing byte-identical output to the asynchronous default.
|
Command backup-sync backs up a directory to Proxmox Backup Server with a single gopbs.Backup call, using fully synchronous archive generation (Archive.Workers: 1): one goroutine walks the tree and reads contents, producing byte-identical output to the asynchronous default. |
|
backup-v2
command
Command backup-v2 backs up a directory to Proxmox Backup Server as a v2 split archive: one gopbs.Backup call with Format: gopbs.FormatV2 uploads a metadata stream (<name>.mpxar.didx) and a payload stream (<name>.ppxar.didx) as two dynamic indexes, generated and uploaded concurrently.
|
Command backup-v2 backs up a directory to Proxmox Backup Server as a v2 split archive: one gopbs.Backup call with Format: gopbs.FormatV2 uploads a metadata stream (<name>.mpxar.didx) and a payload stream (<name>.ppxar.didx) as two dynamic indexes, generated and uploaded concurrently. |
|
restore
command
Command restore restores an archive from Proxmox Backup Server into a directory with a single gopbs.Restore call: the newest snapshot of the backup group by default, the whole archive or only the -path entries, v1 or v2 (told apart by the snapshot manifest).
|
Command restore restores an archive from Proxmox Backup Server into a directory with a single gopbs.Restore call: the newest snapshot of the backup group by default, the whole archive or only the -path entries, v1 or v2 (told apart by the snapshot manifest). |
|
restore-stream
command
Command restore-stream copies one dynamic index of a backup group's newest snapshot to a file.
|
Command restore-stream copies one dynamic index of a backup group's newest snapshot to a file. |
|
Package pbs is a Proxmox Backup Server client for creating and reading backups.
|
Package pbs is a Proxmox Backup Server client for creating and reading backups. |
|
pbstest
Package pbstest provides an in-process mock PBS server for testing code built on package pbs: a TLS listener that answers the regular API's ticket login and snapshot listing, performs the backup- and reader-protocol 101 upgrades, then serves the session endpoints over HTTP/2 — verifying chunk framing (magic, CRC, compression, digest) as the real server would, and recording everything for assertions.
|
Package pbstest provides an in-process mock PBS server for testing code built on package pbs: a TLS listener that answers the regular API's ticket login and snapshot listing, performs the backup- and reader-protocol 101 upgrades, then serves the session endpoints over HTTP/2 — verifying chunk framing (magic, CRC, compression, digest) as the real server would, and recording everything for assertions. |
|
Package pxar implements the PXAR archive format: record framing constants, encoders for every entry type (v1 and the v2 split-archive additions), and the goodbye-table construction (siphash naming hash plus the casync implicit binary search tree layout), and Reader, a validating decoder for v1 archives and v2 split pairs.
|
Package pxar implements the PXAR archive format: record framing constants, encoders for every entry type (v1 and the v2 split-archive additions), and the goodbye-table construction (siphash naming hash plus the casync implicit binary search tree layout), and Reader, a validating decoder for v1 archives and v2 split pairs. |
|
Package restore writes decoded pxar archives to disk.
|
Package restore writes decoded pxar archives to disk. |
|
Package reuse carries previously uploaded payload chunks through a v2 payload stream.
|
Package reuse carries previously uploaded payload chunks through a v2 payload stream. |
|
Package scan walks filesystem trees into immutable node trees carrying the full metadata a PXAR archive needs: mode, ownership, timestamps, symlink targets, hardlink identity, device numbers, xattrs, POSIX ACLs, file capabilities and quota project IDs.
|
Package scan walks filesystem trees into immutable node trees carrying the full metadata a PXAR archive needs: mode, ownership, timestamps, symlink targets, hardlink identity, device numbers, xattrs, POSIX ACLs, file capabilities and quota project IDs. |