Class BackupOperations
The facade's WAL-archive side (#1418): plan a restore, list the archive, resolve a time, read the log.
public static class BackupOperations
- Inheritance
-
BackupOperations
- Inherited Members
Remarks
A store is a directory bound to one database: store.json, packs/ of immutable .tpack files, a rebuildable
catalog.json. Every pack byte is under a CRC (BKP-08); a restore opens through the engine's crash path to exactly its point's committed state
(BKP-05).
Methods
ApplyRetention(string, BackupRetentionPolicy, BackupRetentionPlan, BackupLifecycleOptions)
Applies a retention under the store's lock (05 §3, BKP-14): compacts the oldest kept point of each chain that needs it, then deletes, newest first, every pack no kept point resolves through; a kept point is never lost, and a limit MinKeep or KeepLastDrilled prevents is reported, not met.
public static BackupRetentionResult ApplyRetention(string store, BackupRetentionPolicy policy, BackupRetentionPlan approved = null, BackupLifecycleOptions options = null)
Parameters
storestringThe store directory.
policyBackupRetentionPolicyThe policy (validated).
approvedBackupRetentionPlanA plan from PlanRetention(string, BackupRetentionPolicy) the operator approved: refused with BackupPlanChangedException when the store would now delete a pack it did not list.
nullapplies the policy as it stands.optionsBackupLifecycleOptionsRead budget, cancellation, progress, logging.
Returns
Exceptions
- ArgumentException
The policy is invalid.
- BackupStoreLockedException
Another writer holds the store.
- BackupPlanChangedException
The plan changed since
approved.
Classify(Exception)
What an exception a backup operation threw means to its caller: typhon backup maps it to its exit code, the Workbench to its error category,
so the same failure is reported the same way by both. By exception type, never by message.
public static BackupFailureKind Classify(Exception exception)
Parameters
exceptionExceptionWhat the operation threw.
Returns
- BackupFailureKind
Defect for an exception that is not an outcome of the operation.
Compact(string, PointSelector, BackupLifecycleOptions)
Turns a point into a base without touching the database (05 §2): {id}-C.tpack holds every page of its image and its tail, so the points
after it rest on it and the packs before it can go. Published only once a full verify of it passed; nothing is deleted.
public static BackupCompactionResult Compact(string store, PointSelector point, BackupLifecycleOptions options = null)
Parameters
storestringThe store directory.
pointPointSelectorWhich point; a full or already compacted one is a no-op.
optionsBackupLifecycleOptionsRead budget, cancellation, progress, logging.
Returns
Exceptions
- BackupStoreLockedException
Another writer holds the store.
- BackupChainBrokenException
The point does not resolve.
- BackupPackCorruptException
A page of its chain, or the compacted pack, failed a check: nothing was published.
- IOException
The volume is short of the space a whole image needs, or another I/O failure.
Create(string, string, BackupCreateOptions)
Backs up a closed database into a store (created when absent): a full point, or an incremental one when the database's last clean close kept a lineage this store's chain head continues.
public static BackupPointSummary Create(string bundle, string store, BackupCreateOptions options = null)
Parameters
bundlestringThe database's
{name}.typhondirectory.storestringThe store directory.
optionsBackupCreateOptionsFull, WAL directory, cancellation, logging.
Returns
- BackupPointSummary
The published point.
Exceptions
- DatabaseLockedException
A process holds the database (online capture is the engine's).
- StorageException
The bundle cannot be backed up as configured (e.g. an unclean database whose WAL is elsewhere).
- BackupStoreLockedException
Another writer holds the store.
- BackupStoreMismatchException
The store belongs to another database.
Drill(string, PointSelector, BackupDrillOptions)
Drills a point (04 §6): restores it into ScratchDirectory, opens it (its WAL tail replays) and closes it, checks
it deep, records the result in the store's drills/ and deletes the scratch. The only check that proves a backup restores into a database;
what it records feeds the engine's health and KeepLastDrilled. Takes no store lock: it only reads the packs.
public static BackupDrillReport Drill(string store, PointSelector point, BackupDrillOptions options)
Parameters
storestringThe store directory.
pointPointSelectorWhich point.
optionsBackupDrillOptionsScratch directory, opener, progress, cancellation.
Returns
- BackupDrillReport
The outcome: Failed when the point does not restore, open or check sound (the backup is not trustworthy); Error when the drill itself could not run (scratch I/O, cancelled).
Exceptions
- RestoreRefusedException
The scratch directory lies inside the store, or the point is of another on-disk format revision.
- BackupChainBrokenException
The store holds no such point.
List(string, bool)
What the store holds, from its catalog (rebuilt in memory when stale).
public static BackupStoreListing List(string store, bool computeRestorable = false)
Parameters
storestringThe store directory.
computeRestorableboolAlso run a quick verify and list the restorable points.
Returns
ListArchive(string)
The store's WAL archive: every timeline (parents before children) with its segments, its gaps (whether a later point covers each), and a time sample per segment. Read-only, from each timeline's index cache where it still describes its files.
public static BackupArchiveListing ListArchive(string store)
Parameters
storestringThe store directory.
Returns
OpenAndCloseRestored(string, ILogger)
Opens a restored bundle with no application schema and closes it cleanly: the drill's default opener, and a restore's settle. The open runs
InitializeArchetypes from the persisted schema, which rebuilds the derived structures and seals the image; the WAL tail replays there too,
but only records of archetypes this process registers. A tail holding the application's records fails the open
(RecoveryArchetypeNotRegistered): a point with no record past its checkpoint settles, most online points do not.
For those, the application opens with its own registrations: OpenAndCloseRestored(string, Action<TyphonOptions>, ILogger).
public static BackupSettleResult OpenAndCloseRestored(string bundle, ILogger logger = null)
Parameters
Returns
- BackupSettleResult
Whether the crash path ran, and what its recovery did.
OpenAndCloseRestored(string, Action<TyphonOptions>, ILogger)
Opens a restored bundle with the application's registrations and closes it cleanly, so its WAL tail replays whatever archetypes it holds: the
in-process drill's opener. OpenAndClose = b => BackupOperations.OpenAndCloseRestored(b, o => o.Register<Position>()).
The open is exact (Exact, #1485): a build other than the one that wrote the point — another assembly version, a component
or archetype that differs, one the database does not hold — is refused with SchemaMismatchException, never migrated.
public static BackupSettleResult OpenAndCloseRestored(string bundle, Action<TyphonOptions> configure, ILogger logger = null)
Parameters
bundlestringThe restored
{name}.typhonbundle.configureAction<TyphonOptions>The registrations (and any option) the application opens its database with; passed to Open(string, Action<TyphonOptions>, ILoggerFactory).
loggerILoggerThe engine's log;
null= none.
Returns
- BackupSettleResult
Whether the crash path ran, and what its recovery did — what the drill's guard checks.
PlanRestore(string, PointSelector, string, BackupRestoreOptions)
What Restore(string, PointSelector, string, BackupRestoreOptions) would do with these arguments, without doing any of it: read-only, no lock taken, nothing written. Every refusal the restore would raise is reported, never thrown: a target that exists, a live one, a misnamed one, an image of another format revision, a foreign staging, an LSN or a time that cannot be reached. Pass its Fingerprint as ApprovedPlan to make the restore refuse if what it would restore has changed since.
public static BackupRestorePlan PlanRestore(string store, PointSelector point, string to = null, BackupRestoreOptions options = null)
Parameters
storestringThe store directory.
pointPointSelectorA point, or an LSN or a time of an archived timeline.
tostringThe bundle path or its parent directory; null to plan the source only.
optionsBackupRestoreOptionsReplace and format mismatch, as the restore would take them.
Returns
PlanRetention(string, BackupRetentionPolicy)
What a retention would do now, without doing it (05 §3, the mandatory preview): the points it keeps, compacts and removes, and the packs it
deletes. Reads the packs' headers only; takes no lock, so a writer may change the store before the plan is applied (see
ApplyRetention(string, BackupRetentionPolicy, BackupRetentionPlan, BackupLifecycleOptions)'s approved).
public static BackupRetentionPlan PlanRetention(string store, BackupRetentionPolicy policy)
Parameters
storestringThe store directory.
policyBackupRetentionPolicyThe policy (validated).
Returns
Exceptions
- ArgumentException
The policy is invalid.
ReadLog(string, Guid, DateTime, DateTime, bool, int)
A range of a timeline's archive by time: the frames durable after fromUtc and at or before toUtc, as the
time samples place them (ResolveTime(string, DateTime, Guid?)'s rule at each end).
public static BackupArchiveLog ReadLog(string store, Guid timeline, DateTime fromUtc, DateTime toUtc, bool commits, int max)
Parameters
storestringThe store directory.
timelineGuidThe timeline; Empty for the newest.
fromUtcDateTimeThe range's start (UTC).
toUtcDateTimeThe range's end (UTC).
commitsboolAlso list every frame of the range.
maxintThe most frames listed.
Returns
ReadLog(string, Guid, long, long, bool, int)
A range of a timeline's archive by LSN, [fromLsn, toLsn]; with commits, every frame ending inside it.
public static BackupArchiveLog ReadLog(string store, Guid timeline, long fromLsn, long toLsn, bool commits, int max)
Parameters
storestringThe store directory.
timelineGuidThe timeline; Empty for the newest.
fromLsnlongThe range's first LSN.
toLsnlongThe range's last LSN.
commitsboolAlso list every frame of the range.
maxintThe most frames listed.
Returns
ReadSchemaManifest(string)
The schema assemblies a database names (its manifest, ADR-055), read from the file without opening it — for a restored bundle, which an open would settle: the build to open it with (#1485). Empty for a database whose manifest names none.
public static IReadOnlyList<AssemblyName> ReadSchemaManifest(string bundle)
Parameters
bundlestringThe
{name}.typhonbundle.
Returns
ReadStatus(string)
The backup status of a bundle (from its engine's backup.status.json and its store) or of a store (from its packs): typhon backup status's
answer. A stopped engine's time rules are judged again now (DL-23), so its status degrades by itself; a bundle with no status file is
Off.
public static BackupStatusReport ReadStatus(string bundleOrStore)
Parameters
bundleOrStorestringA
{name}.typhonbundle directory, or a store directory.
Returns
RequestBackup(string, BackupRequestKind, string)
Asks the engine running on bundle for a point (07 §3, DL-24): writes backup.request whole. Only when a live engine's status
file says it accepts requests; the engine writes to its own configured store, never to a path the request could name.
public static Guid RequestBackup(string bundle, BackupRequestKind kind, string requestedBy)
Parameters
bundlestringThe bundle directory.
kindBackupRequestKindAuto or full.
requestedBystringWho asks, for the record.
Returns
- Guid
The request's id, which the engine's status echoes once its job starts.
Exceptions
- TyphonException
BackupNotConfigured: no live engine, backup off, or requests refused. BackupInProgress: another request is still pending after a short wait.
ResolveTime(string, DateTime, Guid?)
The LSN a restore to utc restores to: the highest LSN sampled durable at or before it on timeline's ancestry
(null: the store's newest timeline). Never a commit durable after the instant.
public static BackupTimeResolution ResolveTime(string store, DateTime utc, Guid? timeline = null)
Parameters
Returns
Exceptions
- RestoreTargetUnreachableException
No sample lies at or before the instant (BeforeCoverage).
Restore(string, PointSelector, string, BackupRestoreOptions)
Restores a point into a bundle: target is a {name}.typhon path carrying the database's own name, or a directory to put
it in. Nothing is written before every refusal is checked; an existing bundle is moved aside, never deleted. For AtLsn(long, Guid?)
or AtTime(DateTime, Guid?), the newest point of the timeline at or below the target is restored with the archived WAL replayed up to the
last transaction ending at or below it (BKP-11).
public static BackupRestoreResult Restore(string store, PointSelector point, string target, BackupRestoreOptions options = null)
Parameters
storestringThe store directory.
pointPointSelectorWhich point, or an LSN or a time of an archived timeline.
targetstringThe bundle path or its parent directory.
optionsBackupRestoreOptionsReplace, format mismatch, forensics, settle, progress.
Returns
- BackupRestoreResult
What was restored, and where.
Exceptions
- RestoreRefusedException
The target exists, is live, is misnamed, or the image is of another format revision.
- BackupChainBrokenException
A pack of the point's chain is missing or inconsistent; the message names what is restorable.
- BackupPackCorruptException
A byte the restore needs failed its check.
- RestoreTargetUnreachableException
An LSN or a time cannot be reached; the message names what can.
- BackupPlanChangedException
An approved plan no longer holds.
Status(string)
The store's health from its packs' headers and footers and the chains they form: typhon backup status --store's answer and exit code.
Cheap by design (each pack's header and footer, no index, no tail); Verify(string, BackupVerifyLevel) reads the rest.
public static BackupStoreStatus Status(string store)
Parameters
storestringThe store directory.
Returns
Verify(string, BackupVerifyLevel)
Verifies the whole store. Never throws for damage: it reports it.
public static BackupVerifyReport Verify(string store, BackupVerifyLevel level)
Parameters
storestringThe store directory.
levelBackupVerifyLevelQuick or full.
Returns
Exceptions
- DirectoryNotFoundException
The directory is not a store.
- BackupFormatUnsupportedException
The store was written by a newer format.
Verify(string, BackupVerifyLevel, BackupVerifyOptions)
Verifies the whole store, cancellable and with progress. Never throws for damage: it reports it.
public static BackupVerifyReport Verify(string store, BackupVerifyLevel level, BackupVerifyOptions options)
Parameters
storestringThe store directory.
levelBackupVerifyLevelQuick, full or deep.
optionsBackupVerifyOptionsCancellation, progress, logging;
null= none.
Returns
Exceptions
- DirectoryNotFoundException
The directory is not a store.
- BackupFormatUnsupportedException
The store was written by a newer format.
- OperationCanceledException
Cancelled through Cancellation.
Verify(string, PointSelector, BackupVerifyLevel)
Verifies one point: the packs of its chain, and whether it is restorable. Never throws for damage.
public static BackupVerifyReport Verify(string store, PointSelector point, BackupVerifyLevel level)
Parameters
storestringThe store directory.
pointPointSelectorWhich point.
levelBackupVerifyLevelQuick or full.
Returns
Verify(string, PointSelector, BackupVerifyLevel, BackupVerifyOptions)
Verifies one point, cancellable and with progress. Never throws for damage.
public static BackupVerifyReport Verify(string store, PointSelector point, BackupVerifyLevel level, BackupVerifyOptions options)
Parameters
storestringThe store directory.
pointPointSelectorWhich point.
levelBackupVerifyLevelQuick, full or deep.
optionsBackupVerifyOptionsCancellation, progress, logging;
null= none.
Returns
Exceptions
- OperationCanceledException
Cancelled through Cancellation.