Andresch Serj
Andresch Serj

Reputation: 37438

How do I synchronize two databases?

I need to regularly synchronize two SQLite databases. One on a Raspberry Pi 4 running Node.js/NestJS (always on but without internet connection), another provided to the Raspberry Pi 4 via a USB drive from a dev system.

I want to connect the USB drive to the Raspberry Pi, wait for a while and unplug it knowing it got synchronized. I will run a NestJS cron job checking for the USB drive using libusb. My problem is the synchronization.

My ideas:

Upvotes: 0

Views: 56

Answers (1)

Binaek Sarkar
Binaek Sarkar

Reputation: 636

With sqldiff you could plug in the USB drive and run:

$ sqldiff /usb/my_db.db primary.db > changes.sql

This produces an SQL file that if ran on the database file on your USB drive should result in a replicated primary database file.

sqlite3 /usb/my_db.db < changes.sql should do the trick, but if you change the file on your USB drive it may not work reliably if there are conflicts.

Upvotes: 1

Related Questions