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 ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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
// 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
}
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.
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. |
|
Package pbs is a Proxmox Backup Server client for creating backups.
|
Package pbs is a Proxmox Backup Server client for creating backups. |
|
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).
|
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). |
|
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. |