Skip to content

Commit 4785b1b

Browse files
committed
Moving point in time recovery section to SQL Storage chapter.
1 parent 173f642 commit 4785b1b

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

src/content/docs/durable-objects/api/sql-storage.mdx

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ SQL API methods accessed with `ctx.storage.sql` are only allowed on [Durable Obj
1414

1515
## Methods
1616

17-
### exec
17+
### `exec`
1818

1919
<code>exec(query: <Type text='string'/>, ...bindings: <Type text='any[]'/>)</code>: <Type text='SqlStorageCursor' />
2020

@@ -69,7 +69,7 @@ Note that `sql.exec()` cannot execute transaction-related statements like `BEGIN
6969

7070
<Render file="durable-objects-sql" />
7171

72-
### databaseSize
72+
### `databaseSize`
7373

7474
`databaseSize`: <Type text ='number' />
7575

@@ -80,3 +80,36 @@ The current SQLite database size in bytes.
8080
let size = ctx.storage.sql.databaseSize;
8181
```
8282

83+
## Point in time recovery
84+
85+
For [Durable Objects classes with SQL storage](/durable-objects/reference/durable-objects-migrations/#enable-sqlite-storage-backend-on-new-durable-object-class-migration), the following point-in-time-recovery (PITR) API methods are available to restore a Durable Object's embedded SQLite database to any point in time in the past 30 days. These methods apply to the entire SQLite database contents, including both the object's stored SQL data and stored key-value data using the key-value `put()` API. The PITR API is not supported in local development because a durable log of data changes is not stored locally.
86+
87+
The PITR API represents points in times using "bookmarks". A bookmark is a mostly alphanumeric string like `0000007b-0000b26e-00001538-0c3e87bb37b3db5cc52eedb93cd3b96b`. Bookmarks are designed to be lexically comparable: a bookmark representing an earlier point in time compares less than one representing a later point, using regular string comparison.
88+
89+
### `getCurrentBookmark`
90+
91+
<code>ctx.storage.getCurrentBookmark()</code>: <Type text='Promise<string>' />
92+
93+
* Returns a bookmark representing the current point in time in the object's history.
94+
95+
### `getBookmarkForTime`
96+
97+
<code>ctx.storage.getBookmarkForTime(timestamp: <Type text='number'/> | <Type text='Date'/>)</code>: <Type text='Promise<string>' />
98+
99+
* Returns a bookmark representing approximately the given point in time, which must be within the last 30 days. If the timestamp is represented as a number, it is converted to a date as if using `new Date(timestamp)`.
100+
101+
### `onNextSessionRestoreBookmark`
102+
103+
<code>ctx.storage.onNextSessionRestoreBookmark(bookmark: <Type text='string'/>)</code>: <Type text='Promise<string>' />
104+
105+
* Configure the Durable Object so that the next time it restarts, it should restore its storage to exactly match what the storage contained at the given bookmark. After calling this, the application should typically invoke `ctx.abort()` to restart the Durable Object, thus completing the point-in-time recovery.
106+
107+
This method returns a special bookmark representing the point in time immediately before the recovery takes place (even though that point in time is still technically in the future). Thus, after the recovery completes, it can be undone by performing a second recovery to this bookmark.
108+
109+
110+
```ts
111+
let now = new Date();
112+
// restore to 2 days ago
113+
let bookmark = ctx.storage.getBookmarkForTime(now - 2);
114+
ctx.storage.onNextSessionRestoreBookmark(bookmark);
115+
```

src/content/docs/durable-objects/api/storage-api.mdx

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -243,34 +243,6 @@ The `put()` method returns a `Promise`, but most applications can discard this p
243243

244244
* `setAlarm()` and `deleteAlarm()` support the same options as [`put()`](/durable-objects/api/storage-api/#put), but without `noCache`.
245245

246-
### Point in time recovery
247-
248-
For [Durable Objects classes with SQL storage](/durable-objects/reference/durable-objects-migrations/#enable-sqlite-storage-backend-on-new-durable-object-class-migration), the following point-in-time-recovery (PITR) API methods are available to restore a Durable Object's embedded SQLite database to any point in time in the past 30 days. These methods apply to the entire SQLite database contents, including both the object's stored SQL data and stored key-value data using the key-value `put()` API. The PITR API is not supported in local development because a durable log of data changes is not stored locally.
249-
250-
The PITR API represents points in times using "bookmarks". A bookmark is a mostly alphanumeric string like `0000007b-0000b26e-00001538-0c3e87bb37b3db5cc52eedb93cd3b96b`. Bookmarks are designed to be lexically comparable: a bookmark representing an earlier point in time compares less than one representing a later point, using regular string comparison.
251-
252-
`ctx.storage.getCurrentBookmark()`: <Type text='Promise<string>' />
253-
254-
* Returns a bookmark representing the current point in time in the object's history.
255-
256-
<code>ctx.storage.getBookmarkForTime(timestamp: <Type text='number'/> | <Type text='Date'/>)</code>: <Type text='Promise<string>' />
257-
258-
* Returns a bookmark representing approximately the given point in time, which must be within the last 30 days. If the timestamp is represented as a number, it is converted to a date as if using `new Date(timestamp)`.
259-
260-
<code>ctx.storage.onNextSessionRestoreBookmark(bookmark: <Type text='string'/>)</code>: <Type text='Promise<string>' />
261-
262-
* Configure the Durable Object so that the next time it restarts, it should restore its storage to exactly match what the storage contained at the given bookmark. After calling this, the application should typically invoke `ctx.abort()` to restart the Durable Object, thus completing the point-in-time recovery.
263-
264-
This method returns a special bookmark representing the point in time immediately before the recovery takes place (even though that point in time is still technically in the future). Thus, after the recovery completes, it can be undone by performing a second recovery to this bookmark.
265-
266-
267-
```ts
268-
let now = new Date();
269-
// restore to 2 days ago
270-
let bookmark = ctx.storage.getBookmarkForTime(now - 2);
271-
ctx.storage.onNextSessionRestoreBookmark(bookmark);
272-
```
273-
274246
### sql
275247

276248
<code>ctx.storage.sql.METHOD</code>: <Type text="SqlStorage"/>

0 commit comments

Comments
 (0)