Backup Restore Hooks not working

Hello everyone,

Using latest freepbx distro (Sangoma Linux release 7.8.2003).
FreePBX 15.0.16.75, Back & Restore module 15.0.10.38.

I’ve followed instructions on https://wiki.freepbx.org/pages/viewpage.action?pageId=185631299 to setup a Warm Spare PBX.

I’ve also followed instructions on https://wiki.freepbx.org/display/FDT/Backup+fop2+using+FreePBX+15+Backup+Module by @Fraser to configure backup/restore of fop2 files, database dump and astdb.sqlite3.

But unfortunately, it looks like the scripts I configure pre-backup and post-restore are not executed (even though the logfile says they are).

In all my shell scripts (owned by asterisk and chmod 751), the first line of the script is
#!/bin/bash
echo “$(date) user $(id) executed $0” >> /tmp/hooks.log

I trigger the backup-restore job on my primary server, but there is no /tmp/hoohs.log file in either the primary of the warm spare server …

Moreover, I would expect the post-restore script that @Fraser mentions in the fop2 restore wikipage, to be executed on the destination server, not the origin server…

How can I debug this ?
How can I make sure that the scripts are executed, and they are executed on the correct server (pre-backup on the primary, post-restore on the destination) ?

Did you make your scripts executable with:

chmod +x scriptname.sh

What happens if you run the script from the CLI? Is /tmp/hooks.log created?

Fraser.

Yes, scripts are executable, and when run from the command line, they create the /tmp/hooks.log file …

[[email protected] ~]$ ls -l /usr/local/fop2/asterisk-post-backup-hook.sh
-rwxr-x--x 1 asterisk asterisk 68 Sep 29 11:16 /usr/local/fop2/asterisk-post-backup-hook.sh
[[email protected] ~]$ /usr/local/fop2/asterisk-post-backup-hook.sh
[[email protected] ~]$ cat /tmp/hooks.log
Tue Oct  6 22:04:38 EEST 2020 user uid=995(asterisk) gid=995(asterisk) groups=995(asterisk) executed /usr/local/fop2/asterisk-post-backup-hook.sh

The logfile from the backup/restore job…
It shows that the hook scripts are executed…

Running with: /usr/sbin/fwconsole backup --backup='01924511-50a3-46f9-90bc-a3395cb34939' --warmspare --transaction='7118cfce-c68e-4202-a9b3-6ac78a553be9' >> /var/log/asterisk/backup_7118cfce-c68e-4202-a9b3-6ac78a553be9_out.log 2> /var/log/asterisk/backup_7118cfce-c68e-4202-a9b3-6ac78a553be9_err.log & echo $!
Executing Pre Backup Hook: /usr/local/fop2/asterisk-pre-backup-hook.sh
Running Backup ID: 01924511-50a3-46f9-90bc-a3395cb34939
Transaction: 7118cfce-c68e-4202-a9b3-6ac78a553be9
Starting backup ath-pbx-01-warm-spare-backup
This backup will be stored locally and is subject to maintenance settings
Backup File Name: 20201006-160039-1601989239-15.0.16.75-1823298203.tar.gz
Working with amd module
Exporting KVStore from Amd
	Adding module manifest for amd
Working with announcement module
	Adding module manifest for announcement
Working with arimanager module
	Adding module manifest for arimanager
Working with blacklist module
Exporting Feature Codes from blacklist
	Adding module manifest for blacklist
Working with calendar module
	Adding module manifest for calendar
Working with callback module
	The module callback returned no data, No backup created
Working with callforward module
Exporting Feature Codes from callforward
	Adding module manifest for callforward
Working with callrecording module
Exporting Advanced settings from callrecording
	Adding module manifest for callrecording
Working with callwaiting module
Exporting Feature Codes from callwaiting
	Adding module manifest for callwaiting
Working with cdr module
	Adding directory to tar: /tmp/dbdump
	Adding file to tar: files/tmp/dbdump/cdr.sql
	Adding module manifest for cdr
Working with cel module
Exporting Advanced settings from cel
	Adding directory to tar: /tmp/dbdump
	Adding file to tar: files/tmp/dbdump/cel.sql
	Adding module manifest for cel
Working with certman module
	Adding directory to tar: /etc/asterisk/keys
	Adding directory to tar: /etc/asterisk/keys/integration
	Adding file to tar: files/etc/asterisk/keys/.rnd
	Adding file to tar: files/etc/asterisk/keys/default.crt
	Adding file to tar: files/etc/asterisk/keys/default.csr
	Adding file to tar: files/etc/asterisk/keys/default.key
	Adding file to tar: files/etc/asterisk/keys/default.pem
	Adding file to tar: files/etc/asterisk/keys/integration/certificate.pem
	Adding file to tar: files/etc/asterisk/keys/integration/webserver.crt
	Adding file to tar: files/etc/asterisk/keys/integration/webserver.key
	Adding file to tar: files/etc/asterisk/keys/ca.cfg
	Adding file to tar: files/etc/asterisk/keys/ca.key
	Adding file to tar: files/etc/asterisk/keys/ca.crt
	Adding file to tar: files/etc/asterisk/keys/mydomgr2021.key
	Adding file to tar: files/etc/asterisk/keys/mydomgr2021.crt
	Adding file to tar: files/etc/asterisk/keys/mydomgr2021-ca-bundle.crt
	Adding file to tar: files/etc/asterisk/keys/mydomgr2021.pem
	Adding file to tar: files/etc/asterisk/keys/sysadmin.crt
	Adding file to tar: files/etc/asterisk/keys/sysadmin.key
	Adding file to tar: files/etc/asterisk/keys/sysadmin.pem
	Adding file to tar: files/etc/asterisk/keys/api_oauth.key
	Adding file to tar: files/etc/asterisk/keys/api_oauth_public.key
	Adding module manifest for certman
Working with cidlookup module
	Adding module manifest for cidlookup
Working with conferences module
Exporting KVStore from Conferences
Exporting Feature Codes from conferences
Exporting Advanced settings from conferences
	Adding module manifest for conferences
Working with contactmanager module
Exporting KVStore from Contactmanager
Exporting Feature Codes from contactmanager
Exporting Advanced settings from contactmanager
	Adding module manifest for contactmanager
Working with core module
Exporting Feature Codes from core
Exporting Advanced settings from core
Exporting KVStore from Core
	Adding module manifest for core
Working with customappsreg module
Exporting KVStore from Customappsreg
	Adding module manifest for customappsreg
Working with dahdiconfig module
Exporting Advanced settings from dahdiconfig
	Adding module manifest for dahdiconfig
Working with dashboard module
Exporting Advanced settings from dashboard
	Adding module manifest for dashboard
Working with daynight module
Exporting Databases from daynight
Exporting Feature Codes from daynight
Exporting Advanced settings from daynight
	Adding module manifest for daynight
Working with dictate module
Exporting Feature Codes from dictate
	Adding module manifest for dictate
Working with directory module
	Adding module manifest for directory
Working with disa module
	Adding module manifest for disa
Working with donotdisturb module
Exporting Feature Codes from donotdisturb
	Adding module manifest for donotdisturb
Working with fax module
Exporting KVStore from Fax
Exporting Feature Codes from fax
	Adding module manifest for fax
Working with filestore module
Exporting KVStore from Filestore
	Adding module manifest for filestore
Working with findmefollow module
Exporting Databases from findmefollow
Exporting Feature Codes from findmefollow
	Adding module manifest for findmefollow
Working with framework module
	Adding module manifest for framework
Working with hotelwakeup module
Exporting Feature Codes from hotelwakeup
	Adding module manifest for hotelwakeup
Working with iaxsettings module
	Adding module manifest for iaxsettings
Working with infoservices module
Exporting Feature Codes from infoservices
Exporting Advanced settings from infoservices
	Adding module manifest for infoservices
Working with ivr module
	Adding module manifest for ivr
Working with languages module
	Adding module manifest for languages
Working with logfiles module
Exporting Databases from logfiles
	Adding module manifest for logfiles
Working with manager module
	Adding module manifest for manager
Working with miscapps module
Exporting Feature Codes from miscapps
	Adding module manifest for miscapps
Working with miscdests module
	Adding module manifest for miscdests
Working with music module
Exporting Advanced settings from music
	Adding directory to tar: /var/lib/asterisk/moh
	Adding directory to tar: /var/lib/asterisk/moh/.nomusic_reserved
	Adding file to tar: files/var/lib/asterisk/moh/.asterisk-moh-opsound-sln
	Adding file to tar: files/var/lib/asterisk/moh/.asterisk-moh-opsound-sln16
	Adding file to tar: files/var/lib/asterisk/moh/CHANGES-asterisk-moh-opsound-sln16
	Adding file to tar: files/var/lib/asterisk/moh/CHANGES-asterisk-moh-opsound-wav
	Adding file to tar: files/var/lib/asterisk/moh/CREDITS-asterisk-moh-opsound-sln16
	Adding file to tar: files/var/lib/asterisk/moh/CREDITS-asterisk-moh-opsound-wav
	Adding file to tar: files/var/lib/asterisk/moh/LICENSE-asterisk-moh-opsound-sln16
	Adding file to tar: files/var/lib/asterisk/moh/LICENSE-asterisk-moh-opsound-wav
	Adding file to tar: files/var/lib/asterisk/moh/.nomusic_reserved/silence.wav
	Adding file to tar: files/var/lib/asterisk/moh/.asterisk-moh-opsound-alaw
	Adding file to tar: files/var/lib/asterisk/moh/CHANGES-asterisk-moh-opsound-alaw
	Adding file to tar: files/var/lib/asterisk/moh/CREDITS-asterisk-moh-opsound-alaw
	Adding file to tar: files/var/lib/asterisk/moh/LICENSE-asterisk-moh-opsound-alaw
	Adding file to tar: files/var/lib/asterisk/moh/8881.wav
	Adding file to tar: files/var/lib/asterisk/moh/8882.wav
	Adding file to tar: files/var/lib/asterisk/moh/8883.wav
	Adding file to tar: files/var/lib/asterisk/moh/8884.wav
	Adding file to tar: files/var/lib/asterisk/moh/8885.wav
	Adding file to tar: files/var/lib/asterisk/moh/8886.wav
	Adding file to tar: files/var/lib/asterisk/moh/8887.wav
	Adding module manifest for music
Working with outroutemsg module
	Adding module manifest for outroutemsg
Working with paging module
Exporting KVStore from Paging
Exporting Feature Codes from paging
	Adding module manifest for paging
Working with parking module
	Adding module manifest for parking
Working with phonebook module
	The module phonebook returned no data, No backup created
Working with pinsets module
	Adding module manifest for pinsets
Working with pm2 module
Exporting Advanced settings from pm2
	Adding module manifest for pm2
Working with presencestate module
	Adding module manifest for presencestate
Working with queueprio module
Exporting Feature Codes from queueprio
Exporting Advanced settings from queueprio
	Adding module manifest for queueprio
Working with queues module
Exporting Advanced settings from queues
Exporting Feature Codes from queues
Exporting Databases from queues
Exporting KVStore from Queues
	Adding module manifest for queues
Working with queuestats module
Exporting Advanced settings from queuestats
Exporting KVStore from Queuestats
Exporting KVStore based on ids  widgets,servers
	Adding module manifest for queuestats
Working with recordings module
Exporting Feature Codes from recordings
	Adding directory to tar: /var/lib/asterisk/sounds/en/custom
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/5555007.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/5555010.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/5555015.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/6666007.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/6666010.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/6666015.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/busy_phone_tone.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/1001.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/1039_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/1042.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/1042c.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/1042d.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/1042e.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/1043.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/1044.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/1046_-_-_-_-_-_-_---_9-_-_5_-_-_-_-_-_-_-_-_-_-_-_.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/1048.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/1056.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/1057.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/2042.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/2042c.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/2042d.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/2043.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/2044.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/2046.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/2048.wav
	Adding file to tar: files/var/lib/asterisk/sounds/en/custom/2057.wav
	Adding module manifest for recordings
Working with ringgroups module
Exporting Advanced settings from ringgroups
	Adding module manifest for ringgroups
Working with setcid module
	The module setcid returned no data, No backup created
Working with sipsettings module
Exporting KVStore from Sipsettings
	Adding module manifest for sipsettings
Working with soundlang module
	Adding module manifest for soundlang
Working with superfecta module
Exporting Databases from superfecta
Exporting KVStore from Superfecta
	Adding module manifest for superfecta
Working with sysadmin module
Exporting Databases from sysadmin
Exporting KVStore from Sysadmin
Exporting Advanced settings from sysadmin
	Adding module manifest for sysadmin
	Skpping sysadmin which depends on framework because framework is a system requirement. Framework should be removed as a dependency
Working with timeconditions module
Exporting Databases from timeconditions
Exporting Feature Codes from timeconditions
Exporting Advanced settings from timeconditions
	Adding module manifest for timeconditions
Working with tts module
Exporting Databases from tts
	Adding module manifest for tts
Working with ttsengines module
	The module ttsengines returned no data, No backup created
Working with ucp module
Exporting Databases from ucp
Exporting Advanced settings from ucp
	Adding module manifest for ucp
Working with userman module
Exporting Databases from userman
Exporting KVStore from Userman
Exporting Advanced settings from userman
Exporting Module XML userman
	Adding module manifest for userman
	Depend field was blank for userman. Skipping because not sure what to do
Working with vmblast module
Exporting Databases from vmblast
	Adding module manifest for vmblast
Working with voicemail module
Exporting Feature Codes from voicemail
Exporting Advanced settings from voicemail
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3002
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3002/tmp
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3002/INBOX
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3002/Urgent
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3001
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3001/tmp
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3001/INBOX
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3004
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3004/tmp
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3004/INBOX
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3005
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3005/tmp
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3005/INBOX
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3000
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3000/tmp
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3000/INBOX
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3006
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3006/tmp
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3006/INBOX
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3008
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3008/tmp
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3008/INBOX
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3007
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3007/tmp
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3007/INBOX
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3009
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3009/tmp
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3009/INBOX
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3010
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3010/tmp
	Adding directory to tar: /var/spool/asterisk/voicemail/default/3010/INBOX
	Adding file to tar: files/var/spool/asterisk/voicemail/default/3005/INBOX/msg0000.wav
	Adding file to tar: files/var/spool/asterisk/voicemail/default/3005/INBOX/msg0000.txt
	Adding file to tar: files/etc/asterisk/voicemail.conf
	Adding module manifest for voicemail
Working with webrtc module
Exporting Databases from webrtc
Exporting KVStore from Webrtc
	Adding module manifest for webrtc
	Adding custom directory to tar: customdir/etc/asterisk
	Adding custom directory to tar: customdir/usr/local/fop2
	Adding custom directory to tar: customdir/var/www/html/fop2
	Adding custom file to tar: customfiles/var/lib/asterisk/astdb.sqlite3
Starting Cleaning up
Cleaning up data generated by Cdr
	Removing /tmp/dbdump
Cleaning up data generated by Cel
	Removing /tmp/dbdump
Finished Cleaning up
Finished created backup file: 20201006-160039-1601989239-15.0.16.75-1823298203.tar.gz
Performing Local Maintenance
Finished Local Maintenance
Performing Remote Maintenance
Finished Remote Maintenance
Saving to selected Filestore locations
	Saving to: SSH:'ath-pbx-02' instance ,File location: /var/spool/asterisk/backup//20201006-160039-1601989239-15.0.16.75-1823298203.tar.gz 
	Saving to: S3:'hdgr-asterisk' instance ,File location: ath-pbx-01/20201006-160039-1601989239-15.0.16.75-1823298203.tar.gz 
Finished Saving to selected Filestore locations
There were warnings during the backup process
	The module callback returned no data, No backup created
	The module phonebook returned no data, No backup created
	The module setcid returned no data, No backup created
	The module ttsengines returned no data, No backup created
Generated Backup process result email to [email protected] Status: Success
Executing Post Backup Hook: /usr/local/fop2/asterisk-post-backup-hook.sh
Warmspare enabled for this backup
We Have triggered an API to restore the backup on Spare Server
Response from Warmspare backup Server API
clientMutationId :7118cfce-c68e-4202-a9b3-6ac78a553be9
Restorestatus :Restore Done

You are running that script as root using root’s shell, how about

su asterisk -c /usr/local/fop2/asterisk-post-backup-hook.sh
1 Like

I was running the scripts using asterisk’s shell, but here’s another run like you suggested

[[email protected] ~]# su asterisk -c /usr/local/fop2/asterisk-post-backup-hook.sh
[[email protected] ~]#
[[email protected] ~]# cat /tmp/hooks.log
Wed Oct  7 08:24:45 EEST 2020 user uid=995(asterisk) gid=995(asterisk) groups=995(asterisk) executed /usr/local/fop2/asterisk-post-backup-hook.sh
[[email protected] ~]#

How did you get on with this - I’m at the same point - backup scripts say they are running; but they don’t have permissions to anything…

In my case; as a test, I am trying to do this:

https://wiki.freepbx.org/display/FDT/Backup+fop2+using+FreePBX+15+Backup+Module

However, these lines, both return /etc/freepbx.conf: Permission denied

DBUSER= cat /etc/freepbx.conf | sed 's/ //g' | grep AMPDBUSER | tail -n 1 | cut -d\" -f4
DBPASS= cat /etc/freepbx.conf | sed 's/ //g' | grep AMPDBPASS | tail -n 1 | cut -d\" -f4

If I look at that file, the asterisk user is the owner…

ls -lh /etc/freepbx.conf
-rw-rw----. 1 asterisk asterisk 337 Jun 21 16:13 /etc/freepbx.conf

Thanks

Unfortunately, I still have this problem and I’m looking for ways to understand why the hooks are not working …

We have the hooks working just fine. I recall having trouble setting it up, IIRC, I had to set permissions on the entire path leading to the script. Not sure for which user tho, Asterisk or Apache.

I will check tomorrow and keep you posted.

Just tested this on V15

I created a folder ‘container’ owned by asterisk

[[email protected] ~]# ll / | grep container
drwxr-xr-x    2 asterisk asterisk  4096 Nov  1 14:58 container

Then created 3 files:

[[email protected] ~]# ll /container/
total 8
-rw-r--r-- 1 asterisk asterisk  0 Nov  1 15:07 log.txt
-rwxr-xr-x 1 asterisk asterisk 74 Nov  1 15:04 post-hook.sh
-rwxr-xr-x 1 asterisk asterisk 72 Nov  1 15:05 pre-hook.sh

Here’s what the pre and post script contains

[[email protected] ~]# cat /container/pre-hook.sh
#!/bin/bash
echo -e "[$(date)] BACKUP STARTED..." >> /container/log.txt
[[email protected] ~]# cat /container/post-hook.sh
#!/bin/bash
echo -e "[$(date)] BACKUP COMPLETED..." >> /container/log.txt

Running Backup:

[[email protected] ~]# fwconsole bu --backup 2327d0f8-5ca4-4f94-ba89-e07fdb974559
Transaction ID is: e8e71547-fab7-4876-a985-c4bd5b674ab3
Executing Pre Backup Hook: /container/pre-hook.sh
Running Backup ID: 2327d0f8-5ca4-4f94-ba89-e07fdb974559
Transaction: e8e71547-fab7-4876-a985-c4bd5b674ab3
Starting backup Backup-With-Hooks
This backup will be stored locally and is subject to maintenance settings
Backup File Name: 20201101-151032-1604261432-15.0.16.76-1781097228.tar.gz
Working with voicemail module
Exporting Feature Codes from voicemail
Exporting Advanced settings from voicemail
        Adding file to tar: files/etc/asterisk/voicemail.conf
        Adding module manifest for voicemail
        Adding module core to queue because voicemail depends on it
Working with core module
Exporting Feature Codes from core
Exporting Advanced settings from core
Exporting KVStore from Core
        Adding module manifest for core
        Adding custom directory to tar: customdir/etc/asterisk
Starting Cleaning up
Finished Cleaning up
Finished created backup file: 20201101-151032-1604261432-15.0.16.76-1781097228.tar.gz
Performing Local Maintenance
Finished Local Maintenance
Performing Remote Maintenance
Finished Remote Maintenance
Saving to selected Filestore locations
        Saving to: Local:'Local Storage' instance ,File location: /var/spool/asterisk/20201101-151032-1604261432-15.0.16.76-1781097228.tar.gz
Finished Saving to selected Filestore locations
Backup completed successfully
Executing Post Backup Hook: /container/post-hook.sh

Let’s see our log:

[[email protected] ~]# cat /container/log.txt
[Sun Nov  1 15:10:32 EST 2020] BACKUP STARTED...
[Sun Nov  1 15:10:32 EST 2020] BACKUP COMPLETED...

Thanks. its works, 100% - so yes, Asterisk needs to own everything in the path.

In previous version (13 for example) - there wasnt this requirement.

However, this works - Thanks for you help!

1 Like

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