Redundant database: Difference between revisions
(Review: oprava {{Note}} šablony (prefix 1= pro text s =), nahrazení HTML <strong> za wiki formátování) |
(Rewrite: consolidated structure, removed redundancy, more concise) |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
{{DISPLAYTITLE:Database | {{DISPLAYTITLE:Database Redundancy and Migration}} | ||
[[Category: | [[Category:Configuration]] | ||
[[Category:High Availability]] | |||
This guide | This guide covers methods for replicating, synchronizing, and migrating the VoIPmonitor CDR database between instances. | ||
== Overview | == Overview == | ||
VoIPmonitor offers three methods for CDR synchronization: | |||
{| class="wikitable" | |||
|- | |||
! Method !! Description !! Use Case | |||
|- | |||
| '''Database Backup Mode''' || Dedicated sniffer reads from source DB, writes to destination DB || Online migration, read-only replicas, hot-standby | |||
|- | |||
| '''Master-Master Replication''' || Bidirectional MySQL/MariaDB replication || Full HA with automatic failover (see [[Mysql_master-master_replication_hints|Master-Master Replication]]) | |||
|- | |||
| '''Dual Write''' || Sniffer writes CDRs to two databases simultaneously || Real-time backup, centralized reporting | |||
|} | |||
{{Note|All methods synchronize CDR data only. GUI settings (users, alerts, capture rules) must be migrated separately via '''Tools → Backup & Restore'''.}} | |||
== Database Backup Mode == | |||
A dedicated VoIPmonitor instance reads CDRs from a source database and writes them to a destination database. This is the recommended method for online GUI migration. | |||
=== Architecture === | |||
=== Architecture | |||
<kroki lang="plantuml"> | <kroki lang="plantuml"> | ||
| Line 36: | Line 32: | ||
skinparam shadowing false | skinparam shadowing false | ||
skinparam defaultFontName Arial | skinparam defaultFontName Arial | ||
rectangle "OLD Server" | rectangle "OLD Server" { | ||
rectangle " | rectangle "Sniffer" as SNIFF | ||
database " | database "Source DB" as SRC | ||
} | } | ||
rectangle "NEW Server" | rectangle "NEW Server" { | ||
rectangle "Migration\nInstance" as MIG | rectangle "Migration\nInstance" as MIG | ||
database " | database "Destination DB" as DST | ||
} | } | ||
SNIFF -down-> | SNIFF -down-> SRC : writes CDRs | ||
MIG -left-> | MIG -left-> SRC : reads\n(database_backup_from_*) | ||
MIG -down-> | MIG -down-> DST : writes\n(mysql*) | ||
note bottom of MIG | note bottom of MIG | ||
No packet capture | |||
managerport = 5030 | |||
end note | end note | ||
@enduml | @enduml | ||
</kroki> | </kroki> | ||
== Online GUI Migration Workflow | === Online GUI Migration Workflow === | ||
=== | |||
# Install VoIPmonitor GUI on the new server with a fresh database | |||
# '''Backup configuration:''' On old GUI → '''Tools → Backup & Restore''' → backup configuration tables | |||
# Install VoIPmonitor GUI on the new server with a fresh | # '''Restore configuration:''' On new GUI → upload the backup file (do this BEFORE starting migration) | ||
# | # Create migration config file (see below) | ||
# Start migration instance | |||
# | |||
# Create | |||
# | |||
# Once replication catches up, switch users to the new GUI | # Once replication catches up, switch users to the new GUI | ||
# Stop migration instance and decommission | # Stop migration instance and decommission old server | ||
=== Configuration === | |||
Copy the original config and modify for migration mode: | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
scp root@old-server:/etc/voipmonitor.conf /etc/voipmonitor-migrate.conf | scp root@old-server:/etc/voipmonitor.conf /etc/voipmonitor-migrate.conf | ||
</syntaxhighlight> | </syntaxhighlight> | ||
'''Required modifications in <code>/etc/voipmonitor-migrate.conf</code>:''' | |||
<syntaxhighlight lang="ini"> | <syntaxhighlight lang="ini"> | ||
# | # 1. Avoid port conflict with production sniffer | ||
managerport = 5030 | managerport = 5030 | ||
# | # 2. DISABLE packet capture (comment out all interface lines) | ||
# interface = eth0 | |||
# interface = eth0 | |||
# | # 3. Destination Database (NEW server - local) | ||
mysqlhost = 127.0.0.1 | |||
mysqlhost | mysqldb = voipmonitor | ||
mysqldb | mysqlusername = root | ||
mysqlusername | mysqlpassword = new_password | ||
mysqlpassword | |||
# | # 4. Source Database (OLD server - remote) | ||
database_backup_from_mysqlhost = 192.168.0.1 | database_backup_from_mysqlhost = 192.168.0.1 | ||
database_backup_from_mysqldb = voipmonitor | database_backup_from_mysqldb = voipmonitor | ||
database_backup_from_mysqlusername = root | database_backup_from_mysqlusername = root | ||
database_backup_from_mysqlpassword = | database_backup_from_mysqlpassword = old_password | ||
# | # 5. Start date for replication | ||
database_backup_from_date = 2024-01-01 | |||
# | # 6. Performance tuning | ||
# | database_backup_insert_threads = 3 # Higher = faster but more load | ||
# | database_backup_pause = 3 # Higher = less load on source DB | ||
</syntaxhighlight> | </syntaxhighlight> | ||
'''Parameter Reference:''' | |||
{| class="wikitable" | {| class="wikitable" | ||
| Line 185: | Line 107: | ||
! Parameter !! Description | ! Parameter !! Description | ||
|- | |- | ||
| <code> | | <code>database_backup_from_date</code> || Start date for sync (YYYY-MM-DD) | ||
|- | |- | ||
| <code> | | <code>database_backup_insert_threads</code> || Parallel write threads (higher = faster, more load) | ||
|- | |- | ||
| <code> | | <code>database_backup_pause</code> || Seconds between batches (higher = gentler on source DB) | ||
|- | |- | ||
| <code> | | <code>database_backup_desc_dir</code> || Set <code>yes</code> to also write new incoming data to destination | ||
|} | |} | ||
= | === Running the Migration === | ||
== Running the | |||
'''Test manually first:''' | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
voipmonitor --config-file /etc/voipmonitor-migrate.conf -k -v 1 | voipmonitor --config-file /etc/voipmonitor-migrate.conf -k -v 1 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
'''Run as systemd service:''' | |||
Create <code>/etc/systemd/system/voipmonitor-migrate.service</code>: | |||
<syntaxhighlight lang="ini"> | <syntaxhighlight lang="ini"> | ||
[Unit] | [Unit] | ||
Description=VoIPmonitor Database Migration | Description=VoIPmonitor Database Migration | ||
After=network.target mysql.service | After=network.target mysql.service | ||
| Line 253: | Line 140: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
systemctl daemon-reload | systemctl daemon-reload | ||
systemctl enable | systemctl enable --now voipmonitor-migrate | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Dual Write Method | == Dual Write Method == | ||
Configure the sniffer to write each CDR to both local and remote databases simultaneously. | |||
=== Configuration === | === Configuration === | ||
Add secondary database parameters to <code>/etc/voipmonitor.conf</code>: | |||
<syntaxhighlight lang="ini"> | <syntaxhighlight lang="ini"> | ||
# Primary Database | # Primary Database (local) | ||
mysqlhost = 127.0.0.1 | mysqlhost = 127.0.0.1 | ||
mysqldb = voipmonitor | mysqldb = voipmonitor | ||
| Line 289: | Line 160: | ||
mysqlpassword = primary_password | mysqlpassword = primary_password | ||
# Secondary Database | # Secondary Database (remote) - enables dual write | ||
mysql2host = 192.168.1.100 | mysql2host = 192.168.1.100 | ||
mysql2db = voipmonitor | mysql2db = voipmonitor | ||
| Line 296: | Line 167: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
= | {{Warning|1=If the secondary database becomes unreachable, CDRs are written only to primary. Missed CDRs are NOT retroactively synced.}} | ||
=== Comparison: Dual Write vs Master-Master | === Comparison: Dual Write vs Master-Master === | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
! Aspect !! Dual Write | ! Aspect !! Dual Write !! Master-Master | ||
|- | |- | ||
| ''' | | '''Complexity''' || Low (add mysql2* params) || Medium (MySQL replication setup) | ||
|- | |- | ||
| ''' | | '''Bidirectional''' || No || Yes | ||
|- | |- | ||
| ''' | | '''GUI Settings Sync''' || No || Yes | ||
|- | |- | ||
| '''Best For''' || Simple one-way backup || Full | | '''Best For''' || Simple one-way backup || Full HA setup | ||
|} | |} | ||
== Migrating PCAP | == Migrating PCAP Files == | ||
Database migration does NOT include PCAP files. Migrate separately using rsync: | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
rsync -avz root@old-server:/var/spool/voipmonitor/ /var/spool/voipmonitor/ | rsync -avz root@old-server:/var/spool/voipmonitor/ /var/spool/voipmonitor/ | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{Warning|1='''Timezone must match between servers.''' PCAP paths use local timezone (<code>spooldir/YYYY-MM-DD/HH/MM/</code>). Mismatched timezones cause GUI to fail finding historical PCAPs.}} | |||
= | <syntaxhighlight lang="bash"> | ||
# Check timezone | |||
timedatectl | |||
# Set timezone | |||
timedatectl set-timezone Europe/Prague | |||
</syntaxhighlight> | |||
== Schema Compatibility == | |||
The database | The migration instance automatically handles database schema upgrades. This is useful when: | ||
* Migrating to different MySQL/MariaDB versions | |||
* Upgrading VoIPmonitor versions during migration | |||
* Moving from local MySQL to remote Percona | |||
To | '''To identify schema changes manually:''' | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
systemctl restart voipmonitor | |||
tail -f /var/log/voipmonitor/voipmonitor.log | grep -E "CLI|ALTER|CREATE TABLE" | |||
</syntaxhighlight> | </syntaxhighlight> | ||
= | {{Warning|1=For cross-version migration (e.g., MySQL 5.7 to 8.0), use the migration instance method instead of mysqldump. It handles schema differences automatically.}} | ||
== See Also == | |||
* [[Mysql_master-master_replication_hints|Master-Master Replication]] | |||
* [[Backing_Up_GUI_Configuration|Backing Up GUI Configuration]] | |||
* [[Multiple_sniffer_instancies|Multiple Sniffer Instances]] | |||
== AI Summary for RAG == | == AI Summary for RAG == | ||
''' | '''Summary:''' VoIPmonitor offers three CDR synchronization methods: (1) Database Backup Mode - a dedicated sensor reads from source DB and writes to destination DB for online migration or read-only replicas, configured with <code>database_backup_from_*</code> parameters; (2) Master-Master Replication - bidirectional MySQL replication for full HA (see separate article); (3) Dual Write - sniffer writes CDRs to both local and remote DB using <code>mysql2*</code> parameters. Key configuration: <code>database_backup_from_date</code> sets sync start date, <code>database_backup_pause</code> controls load on source DB (higher = less load), <code>database_backup_insert_threads</code> controls write parallelism. Migration instance must disable packet capture (comment out <code>interface</code>) and use different <code>managerport</code>. PCAP files must be migrated separately with rsync, ensuring timezone matches between servers. The migration instance automatically handles database schema upgrades when moving between MySQL/MariaDB versions. | ||
'''Keywords:''' database replication, mysql backup, database migration, online migration, zero downtime, database_backup_from_date, database_backup_from_mysqlhost, database_backup_pause, database_backup_insert_threads, dual write, mysql2host, PCAP migration, rsync, timezone, schema upgrade, voipmonitor-migrate.conf, read-only replica, disaster recovery, high availability | |||
'''Key Questions:''' | '''Key Questions:''' | ||
* How can I | * How can I migrate VoIPmonitor database with zero downtime? | ||
* What methods are available for database replication in VoIPmonitor? | * What methods are available for database replication in VoIPmonitor? | ||
* What is the difference between database backup mode, dual write, and master-master replication? | * What is the difference between database backup mode, dual write, and master-master replication? | ||
* How | * How do I configure the migration instance (voipmonitor-migrate.conf)? | ||
* How can I control database load during replication (database_backup_pause)? | |||
* How can I | * How do I configure dual write mode (mysql2* parameters)? | ||
* How do I configure dual write mode (mysql2*) | |||
* How do I migrate PCAP files to a new server? | * How do I migrate PCAP files to a new server? | ||
* Why is timezone matching important when migrating PCAP files? | * Why is timezone matching important when migrating PCAP files? | ||
* | * Does the migration instance handle database schema upgrades automatically? | ||
* What configuration parameters are needed for database backup mode? | |||
* What | |||
Latest revision as of 16:48, 8 January 2026
This guide covers methods for replicating, synchronizing, and migrating the VoIPmonitor CDR database between instances.
Overview
VoIPmonitor offers three methods for CDR synchronization:
| Method | Description | Use Case |
|---|---|---|
| Database Backup Mode | Dedicated sniffer reads from source DB, writes to destination DB | Online migration, read-only replicas, hot-standby |
| Master-Master Replication | Bidirectional MySQL/MariaDB replication | Full HA with automatic failover (see Master-Master Replication) |
| Dual Write | Sniffer writes CDRs to two databases simultaneously | Real-time backup, centralized reporting |
ℹ️ Note: All methods synchronize CDR data only. GUI settings (users, alerts, capture rules) must be migrated separately via Tools → Backup & Restore.
Database Backup Mode
A dedicated VoIPmonitor instance reads CDRs from a source database and writes them to a destination database. This is the recommended method for online GUI migration.
Architecture
Online GUI Migration Workflow
- Install VoIPmonitor GUI on the new server with a fresh database
- Backup configuration: On old GUI → Tools → Backup & Restore → backup configuration tables
- Restore configuration: On new GUI → upload the backup file (do this BEFORE starting migration)
- Create migration config file (see below)
- Start migration instance
- Once replication catches up, switch users to the new GUI
- Stop migration instance and decommission old server
Configuration
Copy the original config and modify for migration mode:
scp root@old-server:/etc/voipmonitor.conf /etc/voipmonitor-migrate.conf
Required modifications in /etc/voipmonitor-migrate.conf:
# 1. Avoid port conflict with production sniffer
managerport = 5030
# 2. DISABLE packet capture (comment out all interface lines)
# interface = eth0
# 3. Destination Database (NEW server - local)
mysqlhost = 127.0.0.1
mysqldb = voipmonitor
mysqlusername = root
mysqlpassword = new_password
# 4. Source Database (OLD server - remote)
database_backup_from_mysqlhost = 192.168.0.1
database_backup_from_mysqldb = voipmonitor
database_backup_from_mysqlusername = root
database_backup_from_mysqlpassword = old_password
# 5. Start date for replication
database_backup_from_date = 2024-01-01
# 6. Performance tuning
database_backup_insert_threads = 3 # Higher = faster but more load
database_backup_pause = 3 # Higher = less load on source DB
Parameter Reference:
| Parameter | Description |
|---|---|
database_backup_from_date |
Start date for sync (YYYY-MM-DD) |
database_backup_insert_threads |
Parallel write threads (higher = faster, more load) |
database_backup_pause |
Seconds between batches (higher = gentler on source DB) |
database_backup_desc_dir |
Set yes to also write new incoming data to destination
|
Running the Migration
Test manually first:
voipmonitor --config-file /etc/voipmonitor-migrate.conf -k -v 1
Run as systemd service:
Create /etc/systemd/system/voipmonitor-migrate.service:
[Unit]
Description=VoIPmonitor Database Migration
After=network.target mysql.service
[Service]
Type=simple
ExecStart=/usr/local/sbin/voipmonitor -c /etc/voipmonitor-migrate.conf
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable --now voipmonitor-migrate
Dual Write Method
Configure the sniffer to write each CDR to both local and remote databases simultaneously.
Configuration
Add secondary database parameters to /etc/voipmonitor.conf:
# Primary Database (local)
mysqlhost = 127.0.0.1
mysqldb = voipmonitor
mysqlusername = root
mysqlpassword = primary_password
# Secondary Database (remote) - enables dual write
mysql2host = 192.168.1.100
mysql2db = voipmonitor
mysql2username = root
mysql2password = secondary_password
⚠️ Warning: If the secondary database becomes unreachable, CDRs are written only to primary. Missed CDRs are NOT retroactively synced.
Comparison: Dual Write vs Master-Master
| Aspect | Dual Write | Master-Master |
|---|---|---|
| Complexity | Low (add mysql2* params) | Medium (MySQL replication setup) |
| Bidirectional | No | Yes |
| GUI Settings Sync | No | Yes |
| Best For | Simple one-way backup | Full HA setup |
Migrating PCAP Files
Database migration does NOT include PCAP files. Migrate separately using rsync:
rsync -avz root@old-server:/var/spool/voipmonitor/ /var/spool/voipmonitor/
⚠️ Warning: Timezone must match between servers. PCAP paths use local timezone (spooldir/YYYY-MM-DD/HH/MM/). Mismatched timezones cause GUI to fail finding historical PCAPs.
# Check timezone
timedatectl
# Set timezone
timedatectl set-timezone Europe/Prague
Schema Compatibility
The migration instance automatically handles database schema upgrades. This is useful when:
- Migrating to different MySQL/MariaDB versions
- Upgrading VoIPmonitor versions during migration
- Moving from local MySQL to remote Percona
To identify schema changes manually:
systemctl restart voipmonitor
tail -f /var/log/voipmonitor/voipmonitor.log | grep -E "CLI|ALTER|CREATE TABLE"
⚠️ Warning: For cross-version migration (e.g., MySQL 5.7 to 8.0), use the migration instance method instead of mysqldump. It handles schema differences automatically.
See Also
AI Summary for RAG
Summary: VoIPmonitor offers three CDR synchronization methods: (1) Database Backup Mode - a dedicated sensor reads from source DB and writes to destination DB for online migration or read-only replicas, configured with database_backup_from_* parameters; (2) Master-Master Replication - bidirectional MySQL replication for full HA (see separate article); (3) Dual Write - sniffer writes CDRs to both local and remote DB using mysql2* parameters. Key configuration: database_backup_from_date sets sync start date, database_backup_pause controls load on source DB (higher = less load), database_backup_insert_threads controls write parallelism. Migration instance must disable packet capture (comment out interface) and use different managerport. PCAP files must be migrated separately with rsync, ensuring timezone matches between servers. The migration instance automatically handles database schema upgrades when moving between MySQL/MariaDB versions.
Keywords: database replication, mysql backup, database migration, online migration, zero downtime, database_backup_from_date, database_backup_from_mysqlhost, database_backup_pause, database_backup_insert_threads, dual write, mysql2host, PCAP migration, rsync, timezone, schema upgrade, voipmonitor-migrate.conf, read-only replica, disaster recovery, high availability
Key Questions:
- How can I migrate VoIPmonitor database with zero downtime?
- What methods are available for database replication in VoIPmonitor?
- What is the difference between database backup mode, dual write, and master-master replication?
- How do I configure the migration instance (voipmonitor-migrate.conf)?
- How can I control database load during replication (database_backup_pause)?
- How do I configure dual write mode (mysql2* parameters)?
- How do I migrate PCAP files to a new server?
- Why is timezone matching important when migrating PCAP files?
- Does the migration instance handle database schema upgrades automatically?
- What configuration parameters are needed for database backup mode?