In today's increasingly distributed, mobile, and cloud-based software environments, database synchronization is a common requirement. When working with SQLite databases, sharing data across different devices and locations becomes necessary. Enter SymmetricDS, an open-source data replication and synchronization tool that can work wonders for SQLite database synchronization.
SymmetricDS offers a flexible and scalable solution for synchronizing data across a wide range of databases and systems. In this tutorial, we’ll explore how to use SymmetricDS to synchronize SQLite databases with detailed instructions and practical code examples.
Why Use SymmetricDS?
SymmetricDS supports more than 20 database systems, including SQLite. It provides:
- Multimaster replication
- Filter-based data routing
- Transforms and enrichments of data during synchronization
Setting Up SymmetricDS
Begin by installing SymmetricDS. As it is Java-based, you'll need Java installed on your system. Download the SymmetricDS standalone package from the official website and extract it.
Configuration Steps
- Install Java:sudo apt-get install openjdk-8-jdk
- Download SymmetricDS: Unzip the downloaded package.wget https://sourceforge.net/projects/symmetricds/files/latest/download unzip SymmetricDS-.*.zip
- Setup the SymmetricDS Properties: Each node needs a properties file that defines its configuration.# Configuration for Node 1 engine.name=client symmetric.username=symmetric symmetric.password=symmetric sync.url=http://localhost:31415/sync/client
Configuring SQLite Databases
Now, let’s configure our SQLite databases. We will use two SQLite databases and set one as a "client" and the other as a "server".
Create Sample Databases
-- Server Database CREATE TABLE users ( user_id INTEGER PRIMARY KEY, username TEXT NOT NULL, password TEXT NOT NULL ); -- Client Database CREATE TABLE customers ( customer_id INTEGER PRIMARY KEY, customer_name TEXT NOT NULL, contact_email TEXT NOT NULL );
Synchronizing Data
Next, we execute the synchronization process. Start by launching the SymmetricDS engine for the client and server nodes.
Starting Synchronization Engine
- Server Node:./sym_admin --engine server start
- Client Node:./sym_admin --engine client start
Once both engines are running, SymmetricDS will monitor for changes in either database and apply the necessary updates to the other, ensuring both stay in sync.
Monitoring and Testing
Use the SymmetricDS admin tools to monitor activity and ensure proper synchronization.
Example of Monitoring Sync with Console:
./symadmin --engine server open-console
The admin console provides detailed logs and status of synchronizations allowing you to check which data has been synced, and any errors or warnings.
Summary
SymmetricDS provides a powerful, flexible, and easy-to-use tool for synchronizing SQLite databases across different nodes and environments. By following the steps outlined, developers can set up and use SymmetricDS effectively, enforcing robust data synchronization in applications that rely on distributed database architecture.