Fast MariaDB / MySQL dump restore with per-table exclusion.
sqlrestore streams a mysqldump-format .sql (or .sql.gz) file straight
into the mariadb client, skipping the structure and data of any tables you
name on the command line. It never loads the dump into memory, so it works on
dumps of arbitrary size.
Typical use case: you have a 200 GB nightly dump that includes a giant
assets / assetcache table you don't actually want on this machine. Restore
everything else in one pass without unpacking, editing, or pre-processing the
dump.
If sqlrestore saves you time, please consider sponsoring our work — it
funds the open-source tools we publish.
- Streams the dump line-by-line — handles dumps far larger than RAM.
- Filters whole table sections (DROP, CREATE, LOCK, INSERT, UNLOCK) by parsing
the
mysqldumpsection markers — no SQL re-parsing required. - Transparent
.gzdecompression (multi-member safe). - Pipes filtered SQL into the
mariadb(ormysql) client over a 1 MiB buffered pipe. - Wraps the session in
AUTOCOMMIT=0,UNIQUE_CHECKS=0,FOREIGN_KEY_CHECKS=0,SQL_NOTES=0and a single trailingCOMMITfor significantly faster InnoDB restores. - Password is passed via the
MYSQL_PWDenvironment variable, never on the command line. --dry-runmode prints the filtered SQL to stdout for inspection.- Single static binary — no runtime dependencies, runs on any Linux distro.
Statically-linked binaries for x86_64 and aarch64 are published with every
release, so you don't need a Rust toolchain to install:
curl -fsSL https://raw.githubusercontent.com/wolfsoftwaresystemsltd/sqlrestore/main/setup.sh | bashPin a version or change the install prefix:
curl -fsSL https://raw.githubusercontent.com/wolfsoftwaresystemsltd/sqlrestore/main/setup.sh \
| VERSION=v0.1.0 PREFIX=$HOME/.local bashGrab the right tarball for your CPU from the releases page:
| Platform | Asset |
|---|---|
| Linux x86_64 (Intel/AMD) | sqlrestore-<ver>-linux-x86_64.tar.gz |
| Linux aarch64 (ARM64) | sqlrestore-<ver>-linux-aarch64.tar.gz |
tar -xzf sqlrestore-*-linux-x86_64.tar.gz
sudo install -m 0755 sqlrestore /usr/local/bin/Each tarball ships with a matching .sha256 sidecar.
Requires Rust 1.74+ and the mariadb (or mysql) client binary on PATH.
git clone https://github.com/wolfsoftwaresystemsltd/sqlrestore.git
cd sqlrestore
cargo build --release
# binary at ./target/release/sqlrestoresqlrestore <user> <password> <database> <file> [options]
| Argument | Description |
|---|---|
<user> |
Database user |
<password> |
Database password (use "" for none) |
<database> |
Target database name (must already exist) |
<file> |
Path to dump file (.sql or .sql.gz) |
| Option | Default | Description |
|---|---|---|
--exclude a,b,c |
(none) | Comma-separated list of tables to skip |
-H, --host |
localhost |
Database host |
-P, --port |
3306 |
Database port |
--client |
mariadb |
Client binary (e.g. mysql) |
--client-arg a,b |
(none) | Extra args passed through to the client |
--dry-run |
off | Print filtered SQL to stdout instead |
--no-tune |
off | Skip the speed-tuning SET wrapper |
--progress-mib N |
256 |
Print progress every N MiB read (0 to off) |
Restore a dump into mydb, skipping two large tables:
sqlrestore root '' mydb backup.sql --exclude assets,assetcacheRestore from a gzipped dump on a remote MariaDB:
sqlrestore admin 'p@ss' prod_clone backup.sql.gz \
--exclude audit_log,sessions \
-H db.internal -P 3306Inspect what would be restored without touching the database:
sqlrestore u p mydb backup.sql --exclude assets --dry-run | lessUse the mysql client instead of mariadb, with extra client flags:
sqlrestore root '' mydb backup.sql \
--client mysql \
--client-arg --ssl-mode=DISABLED,--local-infile=1mysqldump always emits section markers like:
--
-- Table structure for table `users`
--
...
--
-- Dumping data for table `users`
--
...
sqlrestore watches for these markers (also the Temporary table structure for view and Final view structure for view variants). When a marker names
an excluded table, every following line is dropped until the next section
marker. That cleanly removes the table's DROP, CREATE, LOCK TABLES,
INSERT, UNLOCK TABLES, and trigger statements as a single unit, without
having to tokenize SQL.
Table name matching is case-insensitive.
- The target database must already exist;
sqlrestoredoes not runCREATE DATABASE. - Foreign key constraints from kept tables that reference excluded tables
will fail at
CREATE TABLEtime. Either also exclude the dependent table or drop the foreign key from the source schema. sqlrestoreonly understands dumps produced bymysqldump/mariadb-dump. Hand-crafted SQL files without the standard section markers are passed through unchanged.
Pushes to main and pull requests are validated by the
CI workflow (rustfmt, clippy, build, test on both
glibc and musl).
Tagging vX.Y.Z triggers the
release workflow, which cross-builds static
binaries for x86_64-unknown-linux-musl and aarch64-unknown-linux-musl and
attaches them — with SHA-256 sidecars — to the GitHub release.
- Wolf Software Systems Ltd — maintainer
- Fang the AI — implementation & docs
Contributions welcome — please open an issue or PR.
MIT. See LICENSE.