# Which SQLite files do you need when copying a Rust database?

[Rust server guides](https://rustsc.com/learn/index.html.md) / [Backups and recovery](https://rustsc.com/learn/recovery/index.html.md)

When manually copying a Rust SQLite database, preserve the database with its matching side files from one stopped capture. For a running database, use a tool that takes a consistent SQLite backup.

## Keep the database and its changes together

A matching `-wal` file can contain changes SQLite has already committed that are still missing from the main database. For example, a manual copy of `player.blueprints.18.db` that skips its existing `player.blueprints.18.db-wal` could miss recent blueprint unlocks. Your filename may have a different number. Combining the database from one backup with the `-wal` from another can corrupt the result.

A clean shutdown can leave no `-wal` file because SQLite put the changes into the main database and removed the side file. Use the files present after a known clean stop. The absence of a side file from a running copy calls for checking how the copy was made.

## Make and check a working copy

If you can stop the writers, stop Rust cleanly and stop any separate service using that database. For a manual filesystem copy, copy the database and the side files that still exist, such as `-wal`, `-shm` or `-journal`, with their names unchanged. If the writers need to stay up, use a SQLite-aware backup tool or the plugin's documented export.

1. Extract the database and its matching files into a new, empty folder. Keep the backup intact, since opening the database can change the working copy.
2. Use your backup tool's database check if it has one, or run `PRAGMA integrity_check` in a SQLite tool on the working copy. The expected result is `ok`.
3. Use a separate Rust instance or the plugin's test environment to check a known record from near the capture time. A readable database can still be missing the data you need.

## Sources

- [SQLite documentation on the write-ahead log](https://sqlite.org/wal.html)
- [SQLite online backup documentation](https://www.sqlite.org/backup.html)
- [SQLite reference for the database integrity check](https://www.sqlite.org/pragma.html#pragma_integrity_check)
- [Facepunch reference for SQLite in Rust save folders](https://wiki.facepunch.com/rust/Getting-Started_w-Server)

## Related resources

- [Should you stop a Rust server before taking a backup?](https://rustsc.com/learn/recovery/rust-backup-running-or-stopped/index.html.md)
- [How to prove your Rust server backup can be restored](https://rustsc.com/learn/recovery/prove-a-local-backup-with-a-test-restore/index.html.md)

---

HTML version: https://rustsc.com/learn/recovery/copy-rust-sqlite-database-and-wal/
