DBTrail

Restore Tables to a Moment

Rebuild whole tables as they were at any past second, as a .sql dump you load into MySQL. Point-in-time restore from a backup plus the recorded changes.

Your tables as they were yesterday at 14:30: the nearest backup before that time, plus every recorded change up to it, written as a mydumper dump. To undo a few rows instead: Recovery.

Point-in-time restore: the backup taken closest before the target time has the recorded changes replayed on top of it up to the target time, producing an importable mydumper-format SQL dump.

What it needs

  • A backup taken before the target time: taking snapshots.
  • Recorded changes covering the time from that backup to the target. Check Status for coverage and continuity. No backup before the target fails with no baseline snapshot found.

From the web interface

Snapshots → Download → To load into MySQL → target time (UTC) → Build → Download .sql export (.tar.gz). Covers every table with a backup.

The Download tab of the Snapshots page: the Take a copy with you box. On the left, To open in DuckDB: Parquet files plus views.sql, with Download the data and Download views.sql, and a note that the newest snapshot is the one downloaded. On the right, To load into MySQL: .sql files in mydumper format, built for the moment you pick, with a date and time field and a Build button. Your database is never touched.

The build is a plaintext copy of your tables. It stays on the daemon's disk until the first of: your download completes, 4 hours pass unclaimed, a new build for that server starts, the daemon restarts. Staged builds, in the same To load into MySQL lane, lists what is waiting.

On a PostgreSQL server (from 0.139.1) the card says To load into PostgreSQL. The build writes one <schema>.<table>.sql file per table, and the download is one .tar.gz of them. Load each file with psql:

psql -v ON_ERROR_STOP=1 -f <file>

From the CLI

bintrail reconstruct --index-dsn "$IDX" --baseline-dir /data/backups \
  --at "2026-09-13 14:30:00" --tables shop.orders,shop.customers \
  --output-format mydumper --output-dir ./pitr-output
  • --at: second precision, UTC or RFC 3339. Changes at that second are included.
  • --tables: fewer tables, faster and smaller.
  • A table with no snapshot at or before --at fails the run (since 0.130.0). Nothing is written for it, the folder is marked _INCOMPLETE, and the error says why, one line per table. The other tables are written. Without a snapshot the only source is the recorded changes, which miss every row they never touched. --allow-changes-only writes those changed rows anyway and marks the table as changes only. The web interface's .sql build also writes nothing for such a table.
  • bintrail baseline refuses such a folder: a table written with --allow-changes-only, or a folder marked _INCOMPLETE, is not turned into a snapshot.
  • On the folder the daemon keeps, --baseline-dir sees only its newest snapshots. Since 0.131.0 the daemon's cleanup leaves alone each table's snapshot while the command reads it, for 24 hours at most. A snapshot can still go before its table starts; that table then fails and is named in the error: run it again, or point --baseline-s3 at the bucket.
  • Into a folder used before (since 0.131.0): before writing, the run removes the files it writes for each table you asked for, so no rows from an earlier run stay behind, and says what it removed. Files of other tables are left. A run refused before any table starts (a wrong --tables entry, a snapshot location it cannot read, an index it cannot reach) leaves the folder as it was; before, it marked an earlier complete dump _INCOMPLETE. A mistyped --baseline-dir, or a bucket that does not exist, is refused at once.
  • Every flag: query and recovery reference.

A gap means wrong data

The build refuses when changes between the backup and the target are missing: hours rotated out without an archive, downtime, purged binlogs. --allow-gaps builds anyway, and rows changed during the gap keep their backup values.

Load it

pitr-output/
├── mydb.orders-schema.sql      # CREATE TABLE
├── mydb.orders.00000.sql       # data, chunked at --chunk-size
└── metadata                    # target time, backup binlog position and GTID set
myloader -h your-host -u your-user -p your-password -d ./pitr-output/ -o

# or file by file
mysql -h your-host -u your-user -p your_database < pitr-output/mydb.orders-schema.sql
mysql -h your-host -u your-user -p your_database < pitr-output/mydb.orders.00000.sql

Review before loading into production: that moment may hold data you no longer want. Rehearse the whole chain regularly: Data Verification.

On this page