Documentation
¶
Overview ¶
Package backup makes and lists data-directory backups: a consistent copy of the database (VACUUM INTO) and a tar.gz of data trees and local recovery configuration, both under <data>/backups/<UTC timestamp>. `gorun backup` and the admin's System → Backups share it.
Index ¶
- Constants
- Variables
- func Decrypt(r io.Reader, key []byte, name string) ([]byte, error)
- func Dir(dataDir string) string
- func Encrypt(r io.Reader, key []byte, name string) ([]byte, error)
- func File(dataDir, name string) (string, error)
- func ManifestFile(dataDir, stamp string) (string, error)
- func PartialPath(destination string) string
- func Prune(dataDir string, keep int) (removed int, err error)
- func PruneVerified(dataDir string, keep int) (removed int, err error)
- func RemovePartial(destination string) error
- func RestoreDestination(dataDir, stamp string) (string, error)
- func Restored(dataDir, stamp string) (string, bool)
- func StoreUploadReceipt(res Result, receipt UploadReceipt) error
- func ValidStamp(s string) bool
- type Entry
- type ExternalRequirement
- type FileDigest
- type Inspection
- type Manifest
- type Options
- type Result
- type UploadFile
- type UploadReceipt
Constants ¶
const ManifestVersion = 1
const MaxEncryptedFile = 64 << 20
Variables ¶
var Dirs = []string{"media", "overrides", "extensions", "form-uploads"}
Dirs are the data-directory trees archived next to the database copy.
var ErrPartialRestore = errors.New("backup: an interrupted restore left a partial directory")
ErrPartialRestore reports that an interrupted restore left its staging directory (see PartialPath); remove it before restoring again.
Functions ¶
func Encrypt ¶
Encrypt authenticates both the file bytes and original backup filename. Keep the site's secret.key/GORUN_SECRET_KEY independently to recover these files.
func File ¶
File returns the path of the backup file name (<stamp>.db or <stamp>.tar.gz); any other name, or a missing file, is fs.ErrNotExist.
func ManifestFile ¶ added in v0.2.0
ManifestFile returns the path of <stamp>.manifest.json under the backups directory when it exists as a regular file.
func PartialPath ¶ added in v0.2.0
PartialPath is the staging directory Restore fills before it renames it to destination: a hidden sibling, so an interrupted restore never looks complete.
func Prune ¶ added in v0.2.0
Prune deletes the oldest complete local backup pairs under dataDir so that at most keep complete pairs remain (newest first). A complete pair has both .db and .tar.gz. Incomplete stamps are left alone. keep < 1 is a no-op. Each pruned stamp removes .db, .tar.gz, .manifest.json and .remote.json when present. Create is unchanged: callers opt into Prune after Create.
func PruneVerified ¶ added in v0.4.0
PruneVerified counts only pairs that pass a fresh integrity/archive inspection. Incomplete, legacy, and corrupt copies never displace a known-good copy and are left for the operator to inspect rather than silently deleted.
func RemovePartial ¶ added in v0.2.0
RemovePartial deletes the leftover staging directory for destination (see PartialPath). It only removes that exact sibling name under the destination's parent via os.OpenRoot — never a path outside restores/.
func RestoreDestination ¶ added in v0.2.0
RestoreDestination is the confined path for an admin restore of stamp: <dataDir>/restores/<stamp>. The directory must not exist before Restore.
func Restored ¶ added in v0.2.0
Restored reports whether a previous restore for stamp is present under <dataDir>/restores/<stamp> (directory with gorun.db).
func StoreUploadReceipt ¶
func StoreUploadReceipt(res Result, receipt UploadReceipt) error
func ValidStamp ¶ added in v0.2.0
ValidStamp reports whether s is a backup timestamp name.
Types ¶
type Entry ¶
type Entry struct {
Stamp string
Time time.Time
DBSize int64 // -1 when the .db is missing
FilesSize int64 // -1 when the .tar.gz is missing
LocalState string
HasManifest bool
Remote UploadReceipt
}
Entry is one backup in the backups directory (either file may be missing).
type ExternalRequirement ¶
type FileDigest ¶
type Inspection ¶
type Inspection struct {
Stamp string `json:"stamp"`
CheckedAt string `json:"checked_at"`
LocalComplete bool `json:"local_complete"`
IntegrityOK bool `json:"integrity_ok"`
ForeignKeyViolations int `json:"foreign_key_violations"`
ArchiveFiles int `json:"archive_files"`
RecoveryKeyArchived bool `json:"recovery_key_archived"`
Consistency string `json:"consistency"`
Readiness string `json:"readiness"`
Errors []string `json:"errors"`
Warnings []string `json:"warnings"`
CutoverChecklist []string `json:"cutover_checklist"`
ExternalRequirements []ExternalRequirement `json:"external_requirements"`
Remote UploadReceipt `json:"remote"`
}
func Inspect ¶
func Inspect(manifestPath string) (*Inspection, error)
Inspect never creates a DB, secret or receipt, and makes no network requests. Readiness tiers:
- blocked: local pair cannot be restored (errors)
- review_required: local pair usable, but site-specific warnings need attention before cutover
- local_ok: local checksums/integrity passed; cutover_checklist still lists secrets/themes/writes/remote
func Restore ¶
func Restore(manifestPath, destination string) (report *Inspection, resultErr error)
Restore writes only into a new directory. It never merges into an existing installation; the caller must review external requirements before booting it. Everything is written into PartialPath(destination) first and renamed to destination only after the database and archive checksums verify, so destination exists only for a complete restore.
type Manifest ¶
type Manifest struct {
FormatVersion int `json:"format_version"`
Stamp string `json:"stamp"`
CreatedAt string `json:"created_at"`
Database FileDigest `json:"database"`
Archive FileDigest `json:"archive"`
Consistency string `json:"consistency"`
RecoveryFiles []string `json:"recovery_files"`
Limitations []string `json:"limitations"`
EncryptedFileLimit int64 `json:"encrypted_file_limit"`
}
func ReadManifest ¶
type Options ¶
type Options struct {
// IncludeSecrets archives secret.key and gorun.toml in plain text
// (`gorun backup --include-secrets`). Keep such archives offline and
// encrypted; the admin never sets it.
IncludeSecrets bool
}
Options adjust Create.
type Result ¶
Result names the files one backup wrote.
type UploadFile ¶
type UploadReceipt ¶
type UploadReceipt struct {
State string `json:"state"`
Files []UploadFile `json:"files"`
ReadBackVerified bool `json:"read_back_verified"`
DatabaseSHA256 string `json:"database_sha256,omitempty"`
ArchiveSHA256 string `json:"archive_sha256,omitempty"`
}
UploadReceipt records provider acknowledgments, never remote read-back proof.