Automated external backups

Status
Not open for further replies.

Jeff.H

New Member
Oct 5, 2018
11
2
3
One thing I love about FreePBX and 3cx is the ability to run automated daily backups of my PBXs to an offsite FTP server.

I haven't yet been able to find that functionality with Fusion. Does it exist?

I have been running my PBXs on Digital Ocean for several years without incident (no jinx), but there have been times where something just happens and I have to restore from a backup, so I would really like to be able to continue to do that. I already have space on another provider where the backups reside that is already part of some hosting I have, so I would like to avoid having to pay DO for backups if I can do it myself. It also means that if something does happen at DO I have daily copies to restore from on another provider if needed.
 

Jeff.H

New Member
Oct 5, 2018
11
2
3
Yeah I saw that, but it seems like it still only does it locally and I have to manually download the file. I would prefer it to be able to send directly to my other server automatically. Unless I missed something.
 

ElecBoy

New Member
Sep 10, 2017
15
2
3
39
Well after the backup you can a a Crontab with SCP, and move it to another server.
 

DigitalDaz

Administrator
Staff member
Sep 29, 2016
3,070
577
113
Or you just map a directory to an NFS mountpoint. There are tons of ways to achieve this.
 

Jeff.H

New Member
Oct 5, 2018
11
2
3
Ok well this is where my limited linux knowledge rears its ugly head. I know "just enough" and have been spoiled by Ward's tutorials over the years. I'll go poke around and figure something out.
 

Jeff.H

New Member
Oct 5, 2018
11
2
3
Ok so I got my password from /etc/fusionpbx/config.php and went to setup the backup but when I went into ./fusionpbx-backup.sh it already had this info in it, but with a different password, which I have obscured to post here. Do I need to change anything or just keep this as is and set a cron to scp it? I ask because it looks different than the instructions linked above.

#!/bin/sh

#export PGPASSWORD="xxxxxxxxxxx"
db_host=127.0.0.1
db_port=5432

now=$(date +%Y-%m-%d)
mkdir -p /var/backups/fusionpbx/postgresql

echo "Backup Started"

#delete postgres backups
find /var/backups/fusionpbx/postgresql/fusionpbx_pgsql* -mtime +4 -exec rm {} \;

#delete the main backup
find /var/backups/fusionpbx/*.tgz -mtime +2 -exec rm {} \;

#backup the database
pg_dump --verbose -Fc --host=$db_host --port=$db_port -U fusionpbx fusionpbx --schema=public -f /var/backups/fusionpbx/postgresql/fusionpbx_pgsql_$now.sql

#package
tar -zvcf /var/backups/fusionpbx/backup_$now.tgz /var/backups/fusionpbx/postgresql/fusionpbx_pgsql_$now.sql /var/www/fusionpbx /usr/share/freeswitch/scripts /var/lib/freeswitch/storage /var/lib/freeswitch/recordings /etc/fusionpbx /etc/freeswitch

#source
#tar -zvcf /var/backups/fusionpbx/backup_$now.tgz /var/backups/fusionpbx/postgresql/fusionpbx_pgsql_$now.sql /var/www/fusionpbx /usr/local/freeswitch/scripts /usr/local/freeswitch/storage /usr/local/freeswitch/recordings /etc/fusionpbx /usr/local/freeswitc$

echo "Backup Completed"
 

Jeff.H

New Member
Oct 5, 2018
11
2
3
Found a few issues with the backup directions from the link above.

#delete postgres logs older than 7 days
find /var/log/postgresql/postgresql-9.4-main* -mtime +7 -exec rm {} \;

This needs to be changed from 9.4 to 10

#delete freeswitch logs older 3 days
find /usr/local/freeswitch/log/freeswitch.log.* -mtime +2 -exec rm {} \;

This doesn't seem to exist anywhere on the server that I can find

pg_dump --verbose -Fc --host=$database_host --port=$database_port -U fusionpbx fusionpbx --schema=public -f /var/backups/fusionpbx/postgresql/fusionpbx_pgsql_$now.sql
This results in this error, whether I use the existing password or the one I got from /etc/fusionpbx/config.php (pg_dump: [archiver (db)] connection to database "fusionpbx" failed: FATAL: Peer authentication failed for user "fusionpbx")

So, this is what I ended up with....

#!/bin/sh

export PGPASSWORD="xxxxxxxxxxx"
db_host=127.0.0.1
db_port=5432

now=$(date +%Y-%m-%d)
mkdir -p /var/backups/fusionpbx/postgresql

echo "Backup Started"

#delete postgres backups older than 7 days
find /var/backups/fusionpbx/postgresql/fusionpbx_pgsql* -mtime +7 -exec rm {} \;

#delete the main backup older than 7 days
find /var/backups/fusionpbx/*.tgz -mtime +7 -exec rm {} \;

#delete postgres logs older than 7 days
find /var/log/postgresql/postgresql-10-main* -mtime +7 -exec rm {} \;

#backup the database
pg_dump --verbose -Fc --host=$db_host --port=$db_port -U fusionpbx fusionpbx --schema=public -f /var/backups/fusionpbx/postgresql/fusionpbx_pgsql_$now.sql

#package
tar -zvcf /var/backups/fusionpbx/backup_$now.tgz /var/backups/fusionpbx/postgresql/fusionpbx_pgsql_$now.sql /var/www/fusionpbx /usr/share/freeswitch/scripts /var/lib/freeswitch/storage /var/lib/freeswitch/recordings /etc/fusionpbx /etc/freeswitch

#source
#tar -zvcf /var/backups/fusionpbx/backup_$now.tgz /var/backups/fusionpbx/postgresql/fusionpbx_pgsql_$now.sql /var/www/fusionpbx /usr/local/freeswitch/scripts /usr/local/freeswitch/storage /usr/local/freeswitch/recordings /etc/fusionpbx /usr/local/freeswitch/conf

echo "Backup Completed"
 

Kenny Riley

Active Member
Nov 1, 2017
243
39
28
37
Hi Jeff

I just configured this on my system today and it's working like a charm..

Make sure ftp is installed on your server first..
sudo apt-get install ftp

Then just add the following lines to your fusionpbx-backup.sh script after the database backup portion of it.

cd /var/backups/fusionpbx/postgresql/
ftp -n <<EOF
open YOUR-FTP-SERVER
user USERNAME PASSWORD
passive
prompt
mput fusionpbx_pgsql_$now.sql
quit
EOF

You'll want to obviously replace the variables above for your FTP server, username, and password.

You can use this same concept to transfer package files offsite as well if you wish.

Good luck.
 
  • Like
Reactions: Jeff.H

Jeff.H

New Member
Oct 5, 2018
11
2
3
@Kenny Riley Thank you so much for that!!!

I did have to make a few small changes to get the actual backup.tgz moved over.

This is what I ended up with and it works perfectly.

cd /var/backups/fusionpbx/
ftp -n <<EOF
open YOUR-FTP-SERVER
user USERNAME PASSWORD
passive
prompt
mput backup_$now.tgz
quit
EOF
 

Kenny Riley

Active Member
Nov 1, 2017
243
39
28
37
@Kenny Riley Thank you so much for that!!!

I did have to make a few small changes to get the actual backup.tgz moved over.

This is what I ended up with and it works perfectly.

cd /var/backups/fusionpbx/
ftp -n <<EOF
open YOUR-FTP-SERVER
user USERNAME PASSWORD
passive
prompt
mput backup_$now.tgz
quit
EOF


Ahh yes, it looks like you are moving your package directories over. I'd strongly recommend backing up your database as well. Call recordings and such are great but without a database backup in the event of a disaster, you're screwed :)
 
  • Like
Reactions: Jeff.H

Jeff.H

New Member
Oct 5, 2018
11
2
3
Ok yeah, good catch. I've changed it to look like this. One thing that seems to be a mystery though is that the .sql backup is a 0 byte file and if I open it in text edit its blank.

cd /var/backups/fusionpbx/
ftp -n <<EOF
open YOUR-FTP-SERVER
user USERNAME PASSWORD
passive
prompt
cd /Fusion/fusionpbx
mput backup_$now.tgz
quit
EOF

cd /var/backups/fusionpbx/postgresql/
ftp -n <<EOF
open YOUR-FTP-SERVER
user USERNAME PASSWORD
passive
prompt
cd /Fusion/fusionpbx/postgresql/
mput fusionpbx_pgsql_$now.sql
quit
EOF

echo "Backup Completed"
 

markjcrane

Active Member
Staff member
Jul 22, 2018
499
177
43
49
Sorry I'm not going to be popular for saying this but plain FTP is not secure and so it is not recommended to use.

You are far better off using something that is secure like one of the following sftp (ftp over ssh), rsync or scp.
 
Status
Not open for further replies.