@cardonjs/backups 0.0.0-stage → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/FORMAT.md +147 -0
- package/LICENSE +21 -0
- package/README.md +1237 -2
- package/dist/copy.d.ts +175 -0
- package/dist/copy.d.ts.map +1 -0
- package/dist/copy.js +863 -0
- package/dist/copy.js.map +1 -0
- package/dist/encryption.d.ts +203 -0
- package/dist/encryption.d.ts.map +1 -0
- package/dist/encryption.js +609 -0
- package/dist/encryption.js.map +1 -0
- package/dist/export.d.ts +201 -0
- package/dist/export.d.ts.map +1 -0
- package/dist/export.js +447 -0
- package/dist/export.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/keys.d.ts +28 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +97 -0
- package/dist/keys.js.map +1 -0
- package/dist/metadata.d.ts +49 -0
- package/dist/metadata.d.ts.map +1 -0
- package/dist/metadata.js +51 -0
- package/dist/metadata.js.map +1 -0
- package/dist/restore.d.ts +97 -0
- package/dist/restore.d.ts.map +1 -0
- package/dist/restore.js +276 -0
- package/dist/restore.js.map +1 -0
- package/dist/retention.d.ts +153 -0
- package/dist/retention.d.ts.map +1 -0
- package/dist/retention.js +295 -0
- package/dist/retention.js.map +1 -0
- package/dist/run.d.ts +94 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +129 -0
- package/dist/run.js.map +1 -0
- package/dist/sniff.d.ts +15 -0
- package/dist/sniff.d.ts.map +1 -0
- package/dist/sniff.js +47 -0
- package/dist/sniff.js.map +1 -0
- package/dist/workflow.d.ts +102 -0
- package/dist/workflow.d.ts.map +1 -0
- package/dist/workflow.js +298 -0
- package/dist/workflow.js.map +1 -0
- package/llms.txt +249 -0
- package/package.json +76 -3
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@cardonjs/backups/workflow`: the backup as a Cloudflare Workflow, built with
|
|
3
|
+
* `@cardonjs/workflows-cf` (an optional peer, needed only by this entry). Steps: plan the backup
|
|
4
|
+
* (its key's moment and the run's identity), start the export, poll it with bounded sleeps up to
|
|
5
|
+
* a deadline, and prune old backups.
|
|
6
|
+
*
|
|
7
|
+
* Cloudflare hands out a completed export's signed URL once: the poll that first reports
|
|
8
|
+
* `complete` is the only one carrying it (observed on 2026-11-20). So the step that receives a
|
|
9
|
+
* `ready` answer (a poll, or a start that is complete at once) copies the dump into R2 itself,
|
|
10
|
+
* and no step polls after it. If that step fails midway and is retried, its poll answers
|
|
11
|
+
* `not_exporting`: the poll first looks for this run's finished object (a copy that finished but
|
|
12
|
+
* lost its step result is used as it is); otherwise the instance starts a new export
|
|
13
|
+
* (`restart export <n>`, at most `MAX_RESTARTS`), after checking the key again.
|
|
14
|
+
*
|
|
15
|
+
* Cloudflare stores every step's result and shows it in its dashboard: results hold ids, sizes
|
|
16
|
+
* and counts only. The API token and the signed URL never leave the step that uses them.
|
|
17
|
+
*/
|
|
18
|
+
import type { Environment } from "@cardonjs/core";
|
|
19
|
+
import { type WorkflowDefinition } from "@cardonjs/workflows-cf";
|
|
20
|
+
import { z } from "zod";
|
|
21
|
+
import { type BackupEncryption, type BackupEncryptionInfo, type BackupEncryptionOptions } from "./encryption.js";
|
|
22
|
+
import { type D1ExportOptions } from "./export.js";
|
|
23
|
+
import { type Retention } from "./retention.js";
|
|
24
|
+
/** What the `database` and `bucket` callbacks receive: the run's context. */
|
|
25
|
+
export interface BackupContext<Adapters, Config> {
|
|
26
|
+
readonly adapters: Adapters;
|
|
27
|
+
readonly config: Config;
|
|
28
|
+
readonly environment: Environment;
|
|
29
|
+
}
|
|
30
|
+
export interface BackupWorkflowOptions<Adapters, Config> {
|
|
31
|
+
/** The definition's name (`defineWorkflow`'s rules: `^[a-z0-9][a-z0-9_-]{0,63}$`). */
|
|
32
|
+
readonly name: string;
|
|
33
|
+
/** The export target and token, read from the config (the token is a secret). */
|
|
34
|
+
readonly database: (c: BackupContext<Adapters, Config>) => D1ExportOptions;
|
|
35
|
+
/** The R2 binding of a bucket used only for backups. */
|
|
36
|
+
readonly bucket: (c: BackupContext<Adapters, Config>) => R2Bucket;
|
|
37
|
+
/**
|
|
38
|
+
* Where the backups go, e.g. `"d1/main"` (see `backupKey`): one prefix per database. After a
|
|
39
|
+
* restore into a new database, change it in the same deploy as the database id.
|
|
40
|
+
*/
|
|
41
|
+
readonly prefix: string;
|
|
42
|
+
/** What `pruneBackups` keeps after each backup. */
|
|
43
|
+
readonly keep: Retention;
|
|
44
|
+
/**
|
|
45
|
+
* Between polls, a sleep of `intervalSeconds` (1 to 300, default 10); after `timeoutMinutes`
|
|
46
|
+
* of polls (1 to 1440, default 60) the instance fails. At most 400 polls.
|
|
47
|
+
*/
|
|
48
|
+
readonly polling?: {
|
|
49
|
+
readonly intervalSeconds?: number;
|
|
50
|
+
readonly timeoutMinutes?: number;
|
|
51
|
+
};
|
|
52
|
+
/** See `copyExport`. */
|
|
53
|
+
readonly partSize?: number;
|
|
54
|
+
/**
|
|
55
|
+
* For tests: the clock the backup's key is built from and future-dated backups are judged by.
|
|
56
|
+
* Default `() => new Date()`.
|
|
57
|
+
*/
|
|
58
|
+
readonly clock?: () => Date;
|
|
59
|
+
/**
|
|
60
|
+
* Encrypt each dump (opt-in): the keys, read from the config (secrets of the backup Worker),
|
|
61
|
+
* e.g. `(c) => backupEncryption({ keys: { "k2026-11": c.config.BACKUP_KEY_K2026_11 }, current:
|
|
62
|
+
* "k2026-11" })`. Called on every run and replay, outside the steps (nothing secret is stored).
|
|
63
|
+
* Once defined, it must return valid settings: invalid keys, and also `null` or `undefined`
|
|
64
|
+
* (a missing secret never means "plain"), stop the instance before any step with
|
|
65
|
+
* `backup: invalid encryption options`.
|
|
66
|
+
*/
|
|
67
|
+
readonly encryption?: (c: BackupContext<Adapters, Config>) => BackupEncryption | BackupEncryptionOptions;
|
|
68
|
+
}
|
|
69
|
+
/** What a finished instance returns (and Cloudflare stores). */
|
|
70
|
+
export interface BackupOutput {
|
|
71
|
+
readonly key: string;
|
|
72
|
+
/** The stored object's size (encrypted, for an encrypted backup). */
|
|
73
|
+
readonly size: number;
|
|
74
|
+
readonly bookmark: string;
|
|
75
|
+
/** The database that was exported (the `database-id` metadata of the backup). */
|
|
76
|
+
readonly databaseId: string;
|
|
77
|
+
/**
|
|
78
|
+
* The stored object's SHA-256 (also in `<key>.sha256`; of the encrypted bytes for an encrypted
|
|
79
|
+
* backup); `null` where it cannot be computed.
|
|
80
|
+
*/
|
|
81
|
+
readonly sha256: string | null;
|
|
82
|
+
/** The key already held this backup (a retried copy). */
|
|
83
|
+
readonly reused: boolean;
|
|
84
|
+
/** Scheme and key id (never the key): only for an encrypted backup. */
|
|
85
|
+
readonly encryption?: BackupEncryptionInfo;
|
|
86
|
+
readonly kept: number;
|
|
87
|
+
readonly deleted: number;
|
|
88
|
+
}
|
|
89
|
+
declare const params: z.ZodObject<{}, z.core.$strict>;
|
|
90
|
+
type NoEvents = Record<never, z.ZodType>;
|
|
91
|
+
/** The definition `defineBackupWorkflow` returns. */
|
|
92
|
+
export type BackupWorkflowDefinition<Adapters, Config> = WorkflowDefinition<typeof params, NoEvents, Adapters, Config, BackupOutput>;
|
|
93
|
+
/**
|
|
94
|
+
* The backup Workflow for one database. Export it from a module, bind it with
|
|
95
|
+
* `workflowEntrypoint` from `@cardonjs/workflows-cf/entrypoint` in the Worker entry, and start
|
|
96
|
+
* it from the daily cron with `backupInstanceId(new Date(controller.scheduledTime))` as the
|
|
97
|
+
* instance id: a second start the same day finds the instance and starts nothing. Throws a
|
|
98
|
+
* `TypeError` for invalid options.
|
|
99
|
+
*/
|
|
100
|
+
export declare function defineBackupWorkflow<Adapters = unknown, Config = unknown>(options: BackupWorkflowOptions<Adapters, Config>): BackupWorkflowDefinition<Adapters, Config>;
|
|
101
|
+
export { backupInstanceId } from "./keys.js";
|
|
102
|
+
//# source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;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,GAAG,OAAO,EAAE,MAAM,GAAG,OAAO,EACvE,OAAO,EAAE,qBAAqB,CAAC,QAAQ,EAAE,MAAM,CAAC,GAC/C,wBAAwB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAyO5C;AAED,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/workflow.js
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { defineWorkflow, permanent } from "@cardonjs/workflows-cf";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { copyExport, findCopy } from "./copy.js";
|
|
4
|
+
import { requireEncryption, } from "./encryption.js";
|
|
5
|
+
import { d1Export, isRestartable, MAX_RESTARTS, } from "./export.js";
|
|
6
|
+
import { assertValidPrefix, backupKey } from "./keys.js";
|
|
7
|
+
import { assertValidRetention, PruneRefusedError, pruneBackups, } from "./retention.js";
|
|
8
|
+
const params = z.strictObject({});
|
|
9
|
+
const MAX_POLLS = 400;
|
|
10
|
+
/**
|
|
11
|
+
* One `start` call per attempt (a failed attempt has no bookmark to resume); the step copies
|
|
12
|
+
* when the start is complete at once, hence the copy's 30 minutes (its own deadline is 25).
|
|
13
|
+
*/
|
|
14
|
+
const START = {
|
|
15
|
+
retries: { limit: 3, delay: "30 seconds", backoff: "exponential" },
|
|
16
|
+
timeout: "30 minutes",
|
|
17
|
+
};
|
|
18
|
+
/** One poll per attempt; the poll that sees `complete` copies in the same step. */
|
|
19
|
+
const POLL = {
|
|
20
|
+
retries: { limit: 5, delay: "10 seconds", backoff: "exponential" },
|
|
21
|
+
timeout: "30 minutes",
|
|
22
|
+
};
|
|
23
|
+
const PRUNE = {
|
|
24
|
+
retries: { limit: 3, delay: "30 seconds", backoff: "exponential" },
|
|
25
|
+
timeout: "5 minutes",
|
|
26
|
+
};
|
|
27
|
+
function wholeIn(value, min, max) {
|
|
28
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= min && value <= max;
|
|
29
|
+
}
|
|
30
|
+
/** A step error: retryable failures retry, the rest stop the instance with a fixed message. */
|
|
31
|
+
function stepError(what, failure) {
|
|
32
|
+
const message = `backup: ${what} failed (${failure.reason})`;
|
|
33
|
+
return failure.retryable ? new Error(message) : permanent(new Error(message), message);
|
|
34
|
+
}
|
|
35
|
+
/** What an instance started by an earlier version of this package fails with on replay. */
|
|
36
|
+
const EARLIER_VERSION = "backup: this instance was started by an earlier version of @cardonjs/backups; start a new one";
|
|
37
|
+
/**
|
|
38
|
+
* A start, restart or poll step's result as stored, checked (Cloudflare replays stored results,
|
|
39
|
+
* including those of instances started before an upgrade). The version before B-004 stored
|
|
40
|
+
* `{ bookmark, ready, at?, databaseId? }`, without `copied`: a not-ready one is still a pending
|
|
41
|
+
* export (`copied: null`) when its database is this one; a ready one was meant for a copy step
|
|
42
|
+
* that no longer exists, and anything else is unknown: the instance fails with a fixed message
|
|
43
|
+
* (never a `TypeError` outside a step).
|
|
44
|
+
*/
|
|
45
|
+
function readExportStep(value, databaseId) {
|
|
46
|
+
if (typeof value === "object" && value !== null) {
|
|
47
|
+
const step = value;
|
|
48
|
+
if (typeof step.bookmark === "string") {
|
|
49
|
+
if ("copied" in step) {
|
|
50
|
+
// `typeof null` is "object": a pending step (`null`) or a copy's summary.
|
|
51
|
+
if (typeof step.lost === "boolean" && typeof step.copied === "object") {
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else if (step.ready === false &&
|
|
56
|
+
(step.databaseId === undefined || step.databaseId === databaseId)) {
|
|
57
|
+
return { bookmark: step.bookmark, copied: null, lost: false };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
throw permanent(EARLIER_VERSION);
|
|
62
|
+
}
|
|
63
|
+
function summary(result) {
|
|
64
|
+
return {
|
|
65
|
+
key: result.key,
|
|
66
|
+
size: result.size,
|
|
67
|
+
bookmark: result.bookmark,
|
|
68
|
+
databaseId: result.databaseId,
|
|
69
|
+
sha256: result.sha256,
|
|
70
|
+
reused: result.reused,
|
|
71
|
+
...(result.encryption === undefined ? {} : { encryption: result.encryption }),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The backup Workflow for one database. Export it from a module, bind it with
|
|
76
|
+
* `workflowEntrypoint` from `@cardonjs/workflows-cf/entrypoint` in the Worker entry, and start
|
|
77
|
+
* it from the daily cron with `backupInstanceId(new Date(controller.scheduledTime))` as the
|
|
78
|
+
* instance id: a second start the same day finds the instance and starts nothing. Throws a
|
|
79
|
+
* `TypeError` for invalid options.
|
|
80
|
+
*/
|
|
81
|
+
export function defineBackupWorkflow(options) {
|
|
82
|
+
if (typeof options !== "object" || options === null) {
|
|
83
|
+
throw new TypeError("defineBackupWorkflow: options { name, database, bucket, prefix, keep } are required.");
|
|
84
|
+
}
|
|
85
|
+
const { database, bucket: bucketOf, prefix, keep, partSize } = options;
|
|
86
|
+
const clock = options.clock ?? (() => new Date());
|
|
87
|
+
if (typeof database !== "function") {
|
|
88
|
+
throw new TypeError("defineBackupWorkflow: database must be a function of the context.");
|
|
89
|
+
}
|
|
90
|
+
if (typeof bucketOf !== "function") {
|
|
91
|
+
throw new TypeError("defineBackupWorkflow: bucket must be a function of the context.");
|
|
92
|
+
}
|
|
93
|
+
if (typeof clock !== "function")
|
|
94
|
+
throw new TypeError("defineBackupWorkflow: clock must be a function.");
|
|
95
|
+
// Only an absent property means plain: `encryption: secret ? (c) => … : undefined` must not
|
|
96
|
+
// turn encryption off silently, so a present property must be a function.
|
|
97
|
+
const encryptionOf = "encryption" in options ? options.encryption : undefined;
|
|
98
|
+
if ("encryption" in options && typeof encryptionOf !== "function") {
|
|
99
|
+
throw new TypeError("defineBackupWorkflow: encryption must be a function of the context.");
|
|
100
|
+
}
|
|
101
|
+
assertValidPrefix(prefix, "defineBackupWorkflow");
|
|
102
|
+
assertValidRetention(keep, "defineBackupWorkflow");
|
|
103
|
+
const intervalSeconds = options.polling?.intervalSeconds ?? 10;
|
|
104
|
+
const timeoutMinutes = options.polling?.timeoutMinutes ?? 60;
|
|
105
|
+
if (!wholeIn(intervalSeconds, 1, 300)) {
|
|
106
|
+
throw new TypeError("defineBackupWorkflow: polling.intervalSeconds must be 1 to 300.");
|
|
107
|
+
}
|
|
108
|
+
if (!wholeIn(timeoutMinutes, 1, 1440)) {
|
|
109
|
+
throw new TypeError("defineBackupWorkflow: polling.timeoutMinutes must be 1 to 1440.");
|
|
110
|
+
}
|
|
111
|
+
const maxPolls = Math.ceil((timeoutMinutes * 60) / intervalSeconds);
|
|
112
|
+
if (maxPolls > MAX_POLLS) {
|
|
113
|
+
throw new TypeError(`defineBackupWorkflow: polling allows at most ${MAX_POLLS} polls; raise intervalSeconds or lower timeoutMinutes.`);
|
|
114
|
+
}
|
|
115
|
+
const keepPolicy = { ...keep };
|
|
116
|
+
return defineWorkflow()({
|
|
117
|
+
name: options.name,
|
|
118
|
+
params,
|
|
119
|
+
events: {},
|
|
120
|
+
async run({ step, logger, adapters, config, environment }) {
|
|
121
|
+
const context = { adapters, config, environment };
|
|
122
|
+
// Built on every run and replay, outside the steps: nothing secret is stored.
|
|
123
|
+
let exporter;
|
|
124
|
+
try {
|
|
125
|
+
exporter = d1Export(database(context));
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
throw permanent(error, "backup: invalid database options");
|
|
129
|
+
}
|
|
130
|
+
// The keys, validated (and imported later, once per run) outside the steps: nothing
|
|
131
|
+
// secret is stored. Invalid keys stop the instance before anything is exported.
|
|
132
|
+
let encryption = null;
|
|
133
|
+
if (encryptionOf !== undefined) {
|
|
134
|
+
try {
|
|
135
|
+
encryption = requireEncryption(encryptionOf(context), "defineBackupWorkflow");
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
// Not the error itself: a fixed message, nothing of the options.
|
|
139
|
+
throw permanent("backup: invalid encryption options");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const withEncryption = encryption === null ? {} : { encryption };
|
|
143
|
+
const bucket = bucketOf(context);
|
|
144
|
+
// Fixed before any export starts, so every later step (retries and restarted exports
|
|
145
|
+
// included) writes to one key under one run identity.
|
|
146
|
+
const planned = await step.do("plan backup", async () => ({
|
|
147
|
+
at: clock().toISOString(),
|
|
148
|
+
run: crypto.randomUUID(),
|
|
149
|
+
// The database this instance exports: a replay after a deploy that changed it must not
|
|
150
|
+
// carry this instance's export over to another database.
|
|
151
|
+
databaseId: exporter.databaseId,
|
|
152
|
+
}));
|
|
153
|
+
// Code outside steps runs again on every replay, with the config of the deployed version:
|
|
154
|
+
// checked here, before any later step can start, poll, copy or prune with the other
|
|
155
|
+
// database.
|
|
156
|
+
if (planned.databaseId !== exporter.databaseId) {
|
|
157
|
+
logger.error("backup database changed since the instance started");
|
|
158
|
+
throw permanent("backup: the database id changed since this instance started");
|
|
159
|
+
}
|
|
160
|
+
const key = backupKey(prefix, new Date(planned.at));
|
|
161
|
+
const run = planned.run;
|
|
162
|
+
/** Copies from the answer that reported the export complete: the only one with the URL. */
|
|
163
|
+
async function copyReady(ready) {
|
|
164
|
+
const result = await copyExport({
|
|
165
|
+
exporter,
|
|
166
|
+
ready,
|
|
167
|
+
bucket,
|
|
168
|
+
key,
|
|
169
|
+
run,
|
|
170
|
+
...(partSize === undefined ? {} : { partSize }),
|
|
171
|
+
...withEncryption,
|
|
172
|
+
});
|
|
173
|
+
if (!result.ok) {
|
|
174
|
+
// Logged: a retryable failure ends in a restarted export, whose message would not say.
|
|
175
|
+
logger.warn("backup copy failed", { reason: result.reason });
|
|
176
|
+
throw stepError("copy", result);
|
|
177
|
+
}
|
|
178
|
+
return summary(result);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* This run's finished object at the key, if any (a copy whose step result was lost); another
|
|
182
|
+
* run's object fails the step as `exists`.
|
|
183
|
+
*/
|
|
184
|
+
async function finishedCopy() {
|
|
185
|
+
const found = await findCopy({ exporter, bucket, key, run, ...withEncryption });
|
|
186
|
+
if (found === null)
|
|
187
|
+
return null;
|
|
188
|
+
if (!found.ok)
|
|
189
|
+
throw stepError("copy", found);
|
|
190
|
+
return { bookmark: found.bookmark, copied: summary(found), lost: false };
|
|
191
|
+
}
|
|
192
|
+
/** A start (or restart) step: unless this run's copy is already finished, a new export. */
|
|
193
|
+
async function beginExport(what) {
|
|
194
|
+
const finished = await finishedCopy();
|
|
195
|
+
if (finished !== null)
|
|
196
|
+
return finished;
|
|
197
|
+
const result = await exporter.start();
|
|
198
|
+
if (result.status === "failed") {
|
|
199
|
+
// A start told "not exporting" is retried like any transient failure (a new start).
|
|
200
|
+
throw stepError(what, {
|
|
201
|
+
reason: result.reason,
|
|
202
|
+
retryable: result.retryable || isRestartable(result.reason),
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
if (result.status === "ready") {
|
|
206
|
+
return { bookmark: result.bookmark, copied: await copyReady(result), lost: false };
|
|
207
|
+
}
|
|
208
|
+
return { bookmark: result.bookmark, copied: null, lost: false };
|
|
209
|
+
}
|
|
210
|
+
const databaseId = exporter.databaseId;
|
|
211
|
+
let state = readExportStep(await step.do("start export", START, () => beginExport("export start")), databaseId);
|
|
212
|
+
logger.info("backup export started", { databaseId: exporter.databaseId });
|
|
213
|
+
let polls = 0;
|
|
214
|
+
let restarts = 0;
|
|
215
|
+
while (state.copied === null) {
|
|
216
|
+
if (state.lost) {
|
|
217
|
+
if (restarts >= MAX_RESTARTS) {
|
|
218
|
+
logger.error("backup export stopped too many times", { restarts });
|
|
219
|
+
throw permanent(`backup: the export stopped before its dump was copied (${MAX_RESTARTS} restarts)`);
|
|
220
|
+
}
|
|
221
|
+
restarts += 1;
|
|
222
|
+
logger.warn("backup export restarted", { restart: restarts });
|
|
223
|
+
state = readExportStep(await step.do(`restart export ${restarts}`, START, () => beginExport("export restart")), databaseId);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
polls += 1;
|
|
227
|
+
if (polls > maxPolls) {
|
|
228
|
+
logger.error("backup export not ready before the deadline", { polls: maxPolls });
|
|
229
|
+
throw permanent("backup: the export was not ready before the deadline");
|
|
230
|
+
}
|
|
231
|
+
await step.sleep(`wait ${polls}`, intervalSeconds * 1000);
|
|
232
|
+
const bookmark = state.bookmark;
|
|
233
|
+
const polled = await step.do(`poll export ${polls}`, POLL, async () => {
|
|
234
|
+
const result = await exporter.poll(bookmark);
|
|
235
|
+
if (result.status === "failed") {
|
|
236
|
+
// Cloudflare runs no export for this bookmark any more: the completion was handed
|
|
237
|
+
// out to an earlier attempt of this step, or the export was cancelled. Polling again
|
|
238
|
+
// cannot help; the loop starts a new export. But an earlier attempt may have finished
|
|
239
|
+
// its copy and lost only its result (or its sidecar landed past its deadline): look
|
|
240
|
+
// for this run's finished object first, so a backup that is in R2 is never failed,
|
|
241
|
+
// also once the restarts are used up.
|
|
242
|
+
if (isRestartable(result.reason)) {
|
|
243
|
+
return (await finishedCopy()) ?? { bookmark, copied: null, lost: true };
|
|
244
|
+
}
|
|
245
|
+
throw stepError("export poll", result);
|
|
246
|
+
}
|
|
247
|
+
if (result.status === "pending") {
|
|
248
|
+
return { bookmark: result.bookmark, copied: null, lost: false };
|
|
249
|
+
}
|
|
250
|
+
// The one answer that carries the signed URL: copy from it here, in this step.
|
|
251
|
+
return { bookmark: result.bookmark, copied: await copyReady(result), lost: false };
|
|
252
|
+
});
|
|
253
|
+
state = readExportStep(polled, databaseId);
|
|
254
|
+
}
|
|
255
|
+
const copied = state.copied;
|
|
256
|
+
// Logged right after the copy, before pruning can fail the instance: with the instance's
|
|
257
|
+
// output, the place a digest is kept outside the bucket (none of these is secret).
|
|
258
|
+
logger.info("backup copied", {
|
|
259
|
+
key: copied.key,
|
|
260
|
+
size: copied.size,
|
|
261
|
+
sha256: copied.sha256,
|
|
262
|
+
databaseId: copied.databaseId,
|
|
263
|
+
reused: copied.reused,
|
|
264
|
+
...(copied.encryption === undefined ? {} : { keyId: copied.encryption.keyId }),
|
|
265
|
+
});
|
|
266
|
+
const pruned = await step.do("prune backups", PRUNE, async () => {
|
|
267
|
+
let result;
|
|
268
|
+
try {
|
|
269
|
+
result = await pruneBackups(bucket, {
|
|
270
|
+
prefix,
|
|
271
|
+
databaseId: exporter.databaseId,
|
|
272
|
+
keep: keepPolicy,
|
|
273
|
+
now: clock,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
catch (error) {
|
|
277
|
+
// A misconfiguration (another database's backups, future-dated keys): retrying cannot
|
|
278
|
+
// fix it, and the instance must fail loudly.
|
|
279
|
+
if (error instanceof PruneRefusedError) {
|
|
280
|
+
throw permanent(new Error(error.message), `backup: prune refused (${error.reason})`);
|
|
281
|
+
}
|
|
282
|
+
throw error;
|
|
283
|
+
}
|
|
284
|
+
return {
|
|
285
|
+
kept: result.kept.length,
|
|
286
|
+
deleted: result.deleted.length,
|
|
287
|
+
ignored: result.ignored,
|
|
288
|
+
// The key ids the kept backups need (not secret): which keys must still be kept.
|
|
289
|
+
keyIds: result.keyIds,
|
|
290
|
+
};
|
|
291
|
+
});
|
|
292
|
+
logger.info("backups pruned", pruned);
|
|
293
|
+
return { ...copied, kept: pruned.kept, deleted: pruned.deleted };
|
|
294
|
+
},
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
export { backupInstanceId } from "./keys.js";
|
|
298
|
+
//# sourceMappingURL=workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow.js","sourceRoot":"","sources":["../src/workflow.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,cAAc,EAAE,SAAS,EAA2B,MAAM,wBAAwB,CAAC;AAC5F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAA2C,UAAU,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC1F,OAAO,EAIL,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAGL,QAAQ,EAGR,aAAa,EACb,YAAY,GACb,MAAM,aAAa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