Contact module synchonization between several freepbx

Hello,

What is the easiest way to synchronyse automatically contacts between several freepbx?

I try to use the warm spare feature in the backup module with only contact module and apply config to yes but the backup was unable to restore the configuration.

A restore will override any data on the current system. If you are OK with that, then Backup/Restore for a single module will work: Sangoma Documentation

Backup example:

[root@freepbx ~]# fwconsole backup --backupsingle contactmanager --singlesaveto /var/spool/asterisk/backup
Transaction ID is: 1d5ef55d-c8c7-4d8d-9e06-ea151e0bc4b5
Processing contactmanager
Working with contactmanager module
Exporting KVStore from Contactmanager
Exporting Feature Codes from contactmanager
Exporting Advanced settings from contactmanager
        Adding module manifest for contactmanager
***In single restores mode dependencies are NOT processed***
There was nothing to cleanup
Finished created backup file: /var/spool/asterisk/backup/contactmanager-20220620-071106-1655723466-15.0.9.6-1878095278.tar.gz
Backup completed successfully

Restore example:

[root@freepbx ~]# fwconsole backup --restoresingle /var/spool/asterisk/backup/contactmanager-20220620-071106-1655723466-15.0.9.6-1878095278.tar.gz
Transaction ID is: 15ca37ea-f9c3-4cb5-b88d-f2446f71a06f
Extracting backup...
***In single restores mode dependencies are NOT processed***
Resetting contactmanager module data
Remove all contact manager tables
Dropping table contactmanager_groups...Done
Dropping table contactmanager_group_entries...Done
Dropping table contactmanager_entry_speeddials...Done
Dropping table contactmanager_entry_numbers...Done
Dropping table contactmanager_entry_images...Done
Dropping table contactmanager_entry_userman_images...Done
Dropping table contactmanager_entry_xmpps...Done
Dropping table contactmanager_entry_emails...Done
Dropping table contactmanager_entry_websites...Done
Dropping table contactmanager_general_favorites...Done
Dropping table contactmanager_user_favorites...Done
Updating tables contactmanager_groups, contactmanager_group_entries, contactmanager_entry_speeddials, contactmanager_entry_numbers, contactmanager_entry_images, contactmanager_entry_userman_images, contactmanager_entry_xmpps, contactmanager_entry_emails, contactmanager_entry_websites, contactmanager_general_favorites, contactmanager_user_favorites...Done
Generating CSS...Done
Restoring from contactmanager [FreePBX\modules\Contactmanager\Restore]
Importing KVStore from contactmanager
Importing Feature Codes from contactmanager
Importing Advanced Settings from contactmanager
Done
Finished
Restore completed successfully

If you do not want to overwrite the current data, then you can use Bulk Handler to export/import the data. (I am not sure if fwconsole bi has support for contacts, but if it does then you can automate it.)

Thanks for your answer.

fwconsole bi seems to support only extensions and dids not contacts.

I try to backup the contact module data on another freepbx server. On this server I run fwconsole backup --restoresingle but I got an error :

Declaration of FreePBXmodules\Backup\Handlers\Single::process() should be compatible with FreePBX\modules\Backup\Handlers\Restore::process($useinmemory)

Any idea?

Sorry I forgot to mention, this fwconsole command only works in FreePBX 15 and up, and it was recently fixed. So make sure you have the latest edge version of backup installed.

fwconsole ma upgrade backup --edge
fwconsole reload

… And try again.

The freepbx version is 16

Ok, so update the backup module as mentioned in the previous post.

I made the update.

The error message is now :

In single restores mode dependencies are NOT processed
Can’t find the module data for
Finished
There were warnings during the restore process
Can’t find the module data for

What’s the output of:

fwconsole ma list | grep backup

I just went ahead and tested on a 16 lab machine (non-distro, so things may be a bit different)

root@16lab:~# fwconsole ma list | grep 'backup\|contact'
| backup           | 16.0.59    | Enabled | GPLv3+  | Sangoma   |
| contactmanager   | 16.0.18.11 | Enabled | GPLv3+  | Sangoma   |

Backup:

root@16lab:~# fwconsole backup --backupsingle contactmanager --singlesaveto /var/spool/asterisk/backup
Transaction ID is: 45498008-46d9-4040-95ae-85c57b069d45
Processing contactmanager
Working with contactmanager module
Exporting KVStore from Contactmanager
Exporting Feature Codes from contactmanager
Exporting Advanced settings from contactmanager
        Adding module manifest for contactmanager
***In single restores mode dependencies are NOT processed***
There was nothing to cleanup
Finished created backup file: /var/spool/asterisk/backup/contactmanager-20220620-135558-1655747758-16.0.18.11-705302453.tar.gz
Backup completed successfully

Restore:

root@16lab:~# fwconsole backup --restoresingle /var/spool/asterisk/backup/contactmanager-20220620-135558-1655747758-16.0.18.11-705302453.tar.gz
Transaction ID is: f075b33e-24d7-4839-8681-e8a819589025
Extracting backup...
***In single restores mode dependencies are NOT processed***
Resetting contactmanager module data
Remove all contact manager tables
Dropping table contactmanager_groups...Done
Dropping table contactmanager_group_entries...Done
Dropping table contactmanager_entry_speeddials...Done
Dropping table contactmanager_entry_numbers...Done
Dropping table contactmanager_entry_images...Done
Dropping table contactmanager_entry_userman_images...Done
Dropping table contactmanager_entry_xmpps...Done
Dropping table contactmanager_entry_emails...Done
Dropping table contactmanager_entry_websites...Done
Dropping table contactmanager_general_favorites...Done
Dropping table contactmanager_user_favorites...Done
Updating tables contactmanager_groups, contactmanager_group_entries, contactmanager_entry_speeddials, contactmanager_entry_numbers, contactmanager_entry_images, contactmanager_entry_userman_images, contactmanager_entry_xmpps, contactmanager_entry_emails, contactmanager_entry_websites, contactmanager_general_favorites, contactmanager_user_favorites...Done
Generating CSS...Done
Restoring from contactmanager [FreePBX\modules\Contactmanager\Restore]
Importing KVStore from contactmanager
Importing Feature Codes from contactmanager
Importing Advanced Settings from contactmanager
Done
Finished
Restore completed successfully

So again, please share the module version of backup you currently have installed.

Also, please provide the full output.

Thanks

Thanks for your answer.

I check the versions. The are the same. I am not on a distro but on Debian 10 and FreePBX 16.

If I proceed the way you give to me it works.

What I want to do, it is to use the backup module of FreePBX to create the file on the secondary server and after to restore the backup file on it. In that case it does not work.

The restore module sees the file but when I make the restore I have an error message :

In Multiple.php line 131:

array_keys() expects parameter 1 to be array, null given

If I use fwconsole backup --externbackup I have an error message :

Error: Call to a member function process() on null in file /var/www/html/admin/modules/backup/Console/Backup.class.php on line 373

I tested on Debian 11, but it shouldn’t make a difference.

This is the issue, I assume that restoresingle only works if the backup was made with backupsingle. Running a backup from the GUI does not work with backupsingle

You’ll need to write a script that runs the backup, copies the file and then restores it.

Thanks for you answer.

UCP works with Debian 11? What version of nodejs do you install?

For the second point, you are right : the most simple solution is to write a script.
I will create an issue for the error when using restoresingle with a backup file.

It’s a lab VM, I don’t have UCP installed on that.

I’ll have to check and get back to you

I can probably share a partial script I wrote recently. I’ll post when time will allow.

Thanks for your answer. I’ll wait for your script. On my side I’ll begin to write a script.

I can’t share the entire script. But here’s a bit…

This is all done on the secondary server

First setup SSH keys:

ssh-copy-id -i /home/asterisk/.ssh/id_rsa.pub root@PrimaryServerIP

Test if you can login:

ssh -i /home/asterisk/.ssh/id_rsa root@PrimaryServerIP
#!/bin.bash

PrimaryServer=192.168.1.145

#make sure the dir exist on the local server
mkdir -p /var/spool/asterisk/backup/contactmanager

#Remove any old backups from the local and primary server in case there were some left by mistake
rm -f /var/spool/asterisk/backup/contactmanager/*
ssh -i /home/asterisk/.ssh/id_rsa root@$PrimaryServer "rm -f /var/spool/asterisk/backup/contactmanager/*"

#Run the backup on the primary (folder will auto create if there isn't one yet)
ssh -i /home/asterisk/.ssh/id_rsa root@$PrimaryServer "sudo /usr/sbin/fwconsole backup --backupsingle contactmanager --singlesaveto /var/spool/asterisk/backup/contactmanager"

#Copy the file from the remote to the local server
scp -i /home/asterisk/.ssh/id_rsa root@$PrimaryServer:/var/spool/asterisk/backup/contactmanager/* /var/spool/asterisk/backup/contactmanager

#Get the backup file name
backupfile=$(ls /var/spool/asterisk/backup/contactmanager/)

#Restore the backup
sudo /usr/sbin/fwconsole backup --restoresingle /var/spool/asterisk/backup/contactmanager/$backupfile

#Reload
sudo /usr/sbin/fwconsole reload

#Remove the files from both servers
rm -f /var/spool/asterisk/backup/contactmanager/$backupfile
ssh -i /home/asterisk/.ssh/id_rsa root@$PrimaryServer "rm -f /var/spool/asterisk/backup/contactmanager/$backupfile"

This script can definitely be improved, but it is a good start

It is a very good start. :slight_smile:

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.