Skip to content

How to restore SQLite to a specific time

List the versions your server keeps, then restore the one from right before the mistake into a new file.

Restore the moment before a mistake

Run it on any machine that joined your server.

// 1. Get your Litebackup server: litebackup.com/get-started
// 2. In your shell, with the token from Machines, Add machine in your console:
//      npm install @litebackup/sdk
//      export LITEBACKUP_TOKEN=YOUR_JOIN_TOKEN

import { backup, restore, versions } from "@litebackup/sdk";

// 3. Back up, once: every change becomes a version you can restore
backup("/var/lib/app/main.sqlite", { prefix: "app/" });

// 4. When you need it: list versions, then restore a moment into a new file
console.table(await versions("app/main.sqlite"));
await restore("app/main.sqlite", {
  to: "/tmp/main-0929.sqlite",
  time: new Date("2026-11-16T09:29:00Z"),
});

Pick a time or a version

Option What you get
--time (time) The newest version at or before an RFC 3339 time, in UTC with Z or with an offset such as +01:00
--version (version) One exact version, by its number from litebackup versions
Neither The newest version

A restore writes a new file and never overwrites one. Its directory must exist. It runs SQLite's quick_check before it finishes.

Put it back

Open the restored file and look before you replace anything. If you need only a few rows, Recover deleted SQLite rows copies them across while your app runs.

To replace the whole database:

  1. Stop your app, so nothing has the database open.
  2. Rename the old file and its -wal and -shm files.
  3. Move the restored file into place, and start your app.

Keep the old file until you are sure. It holds everything written after the moment you restored.

How far back you can go

You choose how long versions are kept in the console, under How long to keep backups. Every change is a version, so within that window you can go back to within seconds of any moment.

Restore without continuous backup

With copies from .backup, VACUUM INTO, or snapshots, you can go back only to a moment you copied. Restore the newest copy from before the mistake. Writes between that copy and the mistake are lost.

Next time

Get started

Install your Litebackup server and back up a first database in minutes: get started, or see pricing.