Skip to content

Time Travel

Temp edited this page Feb 11, 2026 · 2 revisions

Time Travel

D1 Manager provides visibility into Cloudflare D1's Time Travel feature, helping you understand database state and providing CLI guidance for point-in-time recovery.

Overview

D1 Time Travel allows point-in-time recovery for any D1 database. While restore operations require the Wrangler CLI, D1 Manager provides:

  • Current bookmark visibility - See your database's current state identifier
  • Checkpoint history - Track bookmarks captured before destructive operations
  • CLI command generation - Copy-ready Wrangler commands for restore operations
  • Manual checkpoints - Create snapshots at any point in time

Accessing Time Travel

  1. Select a database from the database list
  2. Click the Time Travel tab in the database view
  3. View current bookmark, retention info, and checkpoint history

Current Bookmark

The current bookmark represents your database's exact state at this moment. Bookmarks are:

  • Lexicographically sortable - Later bookmarks sort after earlier ones
  • Deterministic - Derived from timestamps
  • Unique identifiers - Each bookmark points to a specific database state

Copy Bookmark

Click the Copy button next to the bookmark to copy it to your clipboard for use with Wrangler CLI.

CLI Restore Commands

D1 Manager generates ready-to-use Wrangler CLI commands:

Restore to Bookmark

wrangler d1 time-travel restore my-database --bookmark=00000085-0000024c-00004c6d-8e611177d83f7fb2f0396d0847be2cc62eaa94debb2f65eae0a58c44c4cf6a74

Get Time Travel Info

wrangler d1 time-travel info my-database

Click Copy to copy the command, then run it in your terminal.

Retention Periods

Time Travel retention depends on your Cloudflare plan:

Plan Retention Period
Free 7 days
Paid 30 days

Note: Bookmarks older than your retention period cannot be used for restore operations.

Checkpoint History

D1 Manager automatically captures bookmarks before destructive operations:

Operation Type When Captured
pre_drop_table Before DROP TABLE
pre_drop_column Before DROP COLUMN
pre_delete_rows Before DELETE operations
manual User-initiated checkpoint

Viewing History

The checkpoint history shows:

  • Bookmark - The captured state identifier
  • Operation - What triggered the capture
  • Description - Context about the operation
  • Captured At - When the bookmark was saved
  • User - Who performed the operation

Using Checkpoint History

  1. Find the checkpoint you want to restore to
  2. Click Copy to copy the restore command
  3. Run the command in your terminal with Wrangler

Manual Checkpoints

Create a checkpoint at any time:

  1. Click Create Checkpoint in the Time Travel panel
  2. Optionally add a description
  3. The current bookmark is saved to your checkpoint history

Deleting Checkpoints

Remove old checkpoints:

  1. Expand the checkpoint entry
  2. Click Delete
  3. Confirm the deletion

Note: Deleting a checkpoint only removes the saved record. The actual database state remains recoverable via Time Travel until the retention period expires.

Automatic Capture

D1 Manager automatically captures checkpoints before:

DROP TABLE

Before dropping any table, a checkpoint is captured with:

  • Table name
  • Timestamp
  • User email

DROP COLUMN

Before dropping a column, a checkpoint is captured with:

  • Table and column name
  • Timestamp
  • User email

DELETE Rows

Before deleting rows (via the UI), a checkpoint is captured with:

  • Table name
  • WHERE clause used
  • Timestamp
  • User email

API Endpoints

Get Current Bookmark

GET /api/time-travel/:dbId/bookmark

Response:

{
  "success": true,
  "result": {
    "bookmark": "00000085-0000024c-...",
    "capturedAt": "2025-11-27T10:30:00.000Z",
    "databaseId": "uuid-...",
    "databaseName": "my-database",
    "restoreCommand": "wrangler d1 time-travel restore my-database --bookmark=..."
  }
}

Get Checkpoint History

GET /api/time-travel/:dbId/history?limit=50

Response:

{
  "success": true,
  "result": [
    {
      "id": 1,
      "database_id": "uuid-...",
      "database_name": "my-database",
      "bookmark": "00000085-...",
      "operation_type": "pre_drop_table",
      "description": "Before dropping table: users",
      "captured_at": "2025-11-27T10:00:00.000Z",
      "user_email": "[email protected]",
      "restoreCommand": "wrangler d1 time-travel restore my-database --bookmark=..."
    }
  ]
}

Capture Manual Checkpoint

POST /api/time-travel/:dbId/capture
Content-Type: application/json

Body:

{
  "description": "Before schema changes"
}

Response:

{
  "success": true,
  "result": {
    "bookmark": "00000085-...",
    "capturedAt": "2025-11-27T10:30:00.000Z",
    "databaseId": "uuid-...",
    "databaseName": "my-database",
    "restoreCommand": "wrangler d1 time-travel restore my-database --bookmark=..."
  }
}

Delete Checkpoint

DELETE /api/time-travel/:dbId/history/:id

Response:

{
  "success": true,
  "deleted": true
}

Database Schema

Checkpoint history is stored in the bookmark_history table:

CREATE TABLE IF NOT EXISTS bookmark_history (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  database_id TEXT NOT NULL,
  database_name TEXT,
  bookmark TEXT NOT NULL,
  operation_type TEXT NOT NULL,
  description TEXT,
  captured_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  user_email TEXT
);

Best Practices

Before Major Changes

  1. Create a manual checkpoint before significant schema changes
  2. Add a descriptive note about what you're about to do
  3. Keep the checkpoint ID/bookmark for reference

Regular Checkpoints

For critical databases, consider creating regular checkpoints:

  • Before deployments
  • Before bulk data imports
  • Before schema migrations

Checkpoint Cleanup

Periodically review and delete old checkpoints:

  • Remove checkpoints for operations that completed successfully
  • Keep checkpoints for major changes or incidents
  • Note: Actual database states are available via Time Travel regardless of saved checkpoints

Limitations

CLI-Only Restore

Time Travel restore operations require the Wrangler CLI:

wrangler d1 time-travel restore my-database --bookmark=<bookmark>

There is no REST API for restore operations - this is a Cloudflare D1 limitation.

Retention Period

  • Bookmarks expire after the retention period (7/30 days)
  • Expired bookmarks cannot be used for restore
  • Plan accordingly for disaster recovery

FTS5 Compatibility

Time Travel works with all D1 databases, including those with FTS5 virtual tables.

Troubleshooting

"Failed to get bookmark"

  • Verify the database exists and you have access
  • Check API token permissions (D1 Edit required)
  • Ensure the database is not empty

"Bookmark expired"

  • The bookmark is older than your retention period
  • Use a more recent checkpoint if available
  • Consider upgrading to a Paid plan for 30-day retention

"Restore failed"

  • Verify the bookmark format is correct
  • Ensure you have Wrangler CLI installed and authenticated
  • Check the database name matches exactly

See Also


Need Help? See Troubleshooting or open an issue.

Clone this wiki locally