#readwise # Database Remote-Copy Tool for SQLite ![rw-book-cover](https://readwise-assets.s3.amazonaws.com/static/images/article1.be68295a7e40.png) ## Metadata - Author: [[sqlite.org]] - Full Title: Database Remote-Copy Tool for SQLite - URL: https://www.sqlite.org/rsync.html ## Summary `sqlite3_rsync` copies an SQLite database from `ORIGIN` to `REPLICA` over SSH. It uses a bandwidth-efficient, rsync-like protocol that sends only changed pages. The replica is read-only while syncing and the program must be available on both sides (or given with `--exe`); some version-compatibility limits apply. Unlike ordinary `rsync`, `sqlite3_rsync` preserves transactional consistency so the replica is never a corrupted mix of transactions. ## Highlights The following command causes REPLICA to become a copy of ORIGIN: ```sh sqlite3_rsync ORIGIN REPLICA ?OPTIONS? ``` ^f9uo4r ([View Highlight](https://read.readwise.io/read/01k2vnssejrasc81kzwb74bezw)) --- Both databases may be "live" while this utility is running. Other programs can have active connections to the databases on either end while this utility is running. Other programs can write to `ORIGIN` and can read from `REPLICA` while this utility runs. **`REPLICA` becomes a copy of a snapshot of `ORIGIN` as it existed when the `sqlite3_rsync` command started. If other processes change the content of `ORIGIN` while this command is running, those changes will be applied to `ORIGIN`, but they are not transferred to `REPLICA`**. Thus, `REPLICA` ends up as a fully-consistent snapshot of `ORIGIN` at an instant in time. ([View Highlight](https://read.readwise.io/read/01k2vnv1s0mfx73ahwzqqpd7yn)) --- ### Limitations While `sqlite3_rsync` is running, `REPLICA` is read-only. Queries can be run against `REPLICA` while this utility is running, just not write transactions. ([View Highlight](https://read.readwise.io/read/01k2vnw9ewwsswjbftx1rmxfsy)) --- At least one of `ORIGIN` or `REPLICA` must be on the local machine. They cannot both be databases on other machines. ([View Highlight](https://read.readwise.io/read/01k2vnwm1ffczq93b6r8knhkz2)) --- On the remote system, this utility must be installed in one of the directories in the default `$PATH` for SSH. The `/usr/local/bin` directory is often a good choice. Alternately, the `--exe NAME` flag may be used to specify a remote location for the binary, e.g. `--exe /opt/bin/sqlite3_rsync`. ([View Highlight](https://read.readwise.io/read/01k2vnx14c6d8s2ppphxzq0bh2)) --- The replica will be a very close copy of the origin, but not an exact copy. All of the table (and index) content will be byte-for-byte identical in the replica. However, there can be some minor changes in the [database header](https://www.sqlite.org/rsync.html/fileformat2.html#database_header). In particular, the replica will have the following differences from the origin: 1. The [change counter](https://www.sqlite.org/rsync.html/fileformat2.html#chngctr) in bytes 24 through 27 of the database header might be incremented in the replica. 2. The [version-valid-for number](https://www.sqlite.org/rsync.html/fileformat2.html#validfor) in bytes in 96 through 99 of the database header will be the SQLite version number of the sqlite3_rsync program that made the copy, not the version number of the last writer to the origin database. ([View Highlight](https://read.readwise.io/read/01k2vny1s26mrd56avara3aphp)) ---