On some occasions, the amount of recordings that we have in a VitalPBX makes it impossible to make a backup to transfer it to another server. Even though we can do the backup from the console, there might not be enough space on the hard drive to back it up. Due to that the best option is to directly copy all the recordings from one server to another. This can be done manually with scp, however we run the risk that for some reason the copy is aborted and we have to start over.
That said, the best option is to use Sync to make the copy, and here we will give you the steps to do it.
Before executing this script it is necessary that you make a backup without recordings from your server and restore it on the new server.
We install Lsync on the server where we have the recordings
VitalPBX 3 (Centos 7.9)
yum install lsyncd
VitalPBX 4 (Debian 11)
apt-get install lsyncd
Create the following for Centos or Debian:
mkdir /etc/lsyncd mkdir /var/log/lsyncd touch /var/log/lsyncd/lsyncd.log touch /var/log/lsyncd/lsyncd.status
ssh-keygen -f /root/.ssh/id_rsa -t rsa -N '' >/dev/null
ssh-copy-id root@remoteserverip
password: (remote server root’s password)
Now copy and run the following script
wget https://raw.githubusercontent.com/VitalPBX/vitalpbx_copy_recording_cdr_stats/main/recording3.sh
chmod +x recording3.sh
./recording3.sh
wget https://raw.githubusercontent.com/VitalPBX/vitalpbx_copy_recording_cdr_stats/main/recording4.sh
chmod +x recording4.sh
./recording4.sh
************************************************************ * Welcome to the VitalPBX Recording Replica installation * * All options are mandatory * ************************************************************ IP New Server................ > IPNEWSERVER ************************************************************ * Check Information * * Make sure both servers see each other * ************************************************************ Are you sure to continue with this settings? (yes,no) > yes
This process can take a long time depending on the amount of recordings, you can monitor the process by running the following command:
cat /var/log/lsyncd/lsyncd.status
VitalPBX 3 (Centos 7.9)
If you also want to copy Voicemail, you must add the following script to the end of the /etc/lsyncd.conf file.
nano /etc/lsyncd.conf
sync { default.rsync, source = "/var/spool/asterisk/voicemail", target="IPNEWSERVER:/var/spool/asterisk/voicemail", rsync = { owner = true, group = true } }
Change $ip_newserver to the IP of the new server
VitalPBX 4 (Debian 11)
If you also want to copy Voicemail, you must add the following script to the end of the /etc/lsyncd/lsyncd.conf.lua file.
nano /etc/lsyncd/lsyncd.conf.lua
sync { default.rsyncssh, source = "/var/spool/asterisk/voicemail", host = "IPNEWSERVER", targetdir = "/var/spool/asterisk/voicemail", rsync = { owner = true, group = true } }
Change IPNEWSERVER to the IP of the new server
And we restart the service
systemctl restart lsyncd
To see the number of GB to copy:
du -sh /var/spool/asterisk/monitor
To see what's copied:
ssh root@ip_newserver "du -sh /var/spool/asterisk/monitor"
To see the progress of the copy, use the following command
rsync -ah --progress /var/spool/asterisk/monitor root@IPNEWSERVER:/var/spool/asterisk/monitor
Sometimes the CDR volume is quite large and it is not possible to include it in the backup done through the GUI. In these cases it is recommended to copy the databases from the console as shown below.
First we enter the server where the information is:
mysqldump -u root asterisk > asterisk.sql mysqldump -u root sonata_stats > sonata_stats.sql
Now we proceed to copy to a temporary directory on the new server.
scp asterisk.sql root@IPNEWSERVER:/tmp/asterisk.sql scp sonata_stats.sql root@IPNEWSERVER:/tmp/sonata_stats.sql
Change IPNEWSERVER to the IP of the new server
We connect to the new server and go to the folder where we copied the database backup (/tmp/).
And we proceed to perform the restore
mysql -u root asterisk < /tmp/asterisk.sql mysql -u root sonata_stats < /tmp/sonata_stats.sql