SQLite User Forum

sqlite3-rsync bugs
Login

sqlite3-rsync bugs

(1) By Bo Lindbergh (_blgl_) on 2024-09-15 03:04:15 [link] [source]

Lost error messages: the origin side leaves its main loop immediately after sending ORIGIN_END. It should continue looping until it sees REPLICA_END. The replica side should aid this by sending REPLICA_END after seeing ORIGIN_END.

At the end of main, pclose2 is never called, because the pIn and pOut variables are not modified after their initialisations.

(2) By Bo Lindbergh (_blgl_) on 2024-09-15 20:42:40 in reply to 1 [source]

Once you can see all error messages, it becomes possible to investigate the serious bugs.

First, execute this SQL to set up a minimal example:

attach database 'origin.sqlite' as origin;
pragma origin.journal_mode='wal';
create table origin.one (id integer primary key);
detach database origin;
attach database 'replica.sqlite' as replica;
pragma replica.journal_mode='wal';
create table replica.two (id integer primary key);
create table replica.three (id integer primary key);
detach database replica;

Then, run

sqlite3-rsync origin.sqlite replica.sqlite

and frown at the output:

ERROR: SQL statement [INSERT INTO sqlite_dbpage(pgno,data) VALUES(?1,?2)] failed: database disk image is malformed
Databases where not synced due to errors

(3) By Richard Hipp (drh) on 2024-09-16 11:34:57 in reply to 2 [link] [source]

Please try again using check-in 39c56c836a8ae52c or later.

(4) By Bo Lindbergh (_blgl_) on 2024-09-16 16:22:01 in reply to 3 [link] [source]

That seems to have fixed it. Thank you!

(5) By anonymous on 2024-09-16 16:55:01 in reply to 2 [link] [source]

Databases where not synced due to errors

s/where/were/

Databases were not synced due to errors

(6) By Bo Lindbergh (_blgl_) on 2024-09-17 01:41:06 in reply to 1 [link] [source]

Just so it can be easily found by forum searches: there are a few unavoidable differences between the original and the replica.

  1. The change count stored at offsets 24 and 92 in the file header is incremented in the replica.

  2. The SQLite library version number stored at offset 96 is the one used on the replica side.

(7) By Bo Lindbergh (_blgl_) on 2024-09-17 02:04:43 in reply to 1 [link] [source]

If you're borrowing the host: or user@host: notation from rsync, you should parse it in the same way: the : must come before the first /. That is, sqlite3-rsync ./origin:sqlite ./replica:sqlite would operate on two local files in the current directory.