This script is based off of "Convert yesterdays wavs to mp3" thread in this same section.
The reason behind doing this way rather than changing the recording DIR to NFS share is that there's a probability the NFS share might go down. And when you have Lawyers and Financial people as your customers, you and even them can be in deep trouble if there are missing recordings.
This gives you a buffer to restore the NFS, move the recordings without much of hassle.
What this script does:
* Check if there are call recordings
* If there are, use rsync to copy the files to NFS share folder.
* Checks if the NFS folder has the correct DIR structure and if not creates them.
* Sets correct folder/file permissions.
* Updates the recording DB with the new path.
There maybe more efficient and elegant ways to do this and if someone can improve on this, that would be awesome.
Step 1:
Mount the NFS DIR to /var/lib/freeswitch/storage/NFS/
Step 2:
Add the following code to file, make it executable and run it via crontab
Step 3:
Modify the /etc/cron.daily/fusionpbx-housekeeping.sh file so that call recordings are deleted every 2 or 3 days time from the main disk.
Step 4:
Either from the NFS Server or from the FusionPBX server setup a cronjob delete call recordings.
Ex:
/etc/cron.daily/recording_del
The reason behind doing this way rather than changing the recording DIR to NFS share is that there's a probability the NFS share might go down. And when you have Lawyers and Financial people as your customers, you and even them can be in deep trouble if there are missing recordings.
This gives you a buffer to restore the NFS, move the recordings without much of hassle.
What this script does:
* Check if there are call recordings
* If there are, use rsync to copy the files to NFS share folder.
* Checks if the NFS folder has the correct DIR structure and if not creates them.
* Sets correct folder/file permissions.
* Updates the recording DB with the new path.
There maybe more efficient and elegant ways to do this and if someone can improve on this, that would be awesome.
Step 1:
Mount the NFS DIR to /var/lib/freeswitch/storage/NFS/
Step 2:
Add the following code to file, make it executable and run it via crontab
Code:
0 2 * * * /usr/share/freeswitch/custom/nfstransfer.sh > /dev/null
Bash:
#!/bin/sh
YESTDAY=`date -d "yesterday" +%d`
for DIRECTORY in /var/lib/freeswitch/recordings/*/; do
DIRYESTERDAY=/var/lib/freeswitch/recordings/`basename "$DIRECTORY"`/archive/`date -d "yesterday" +%Y/%b/%d`
DIRNFS=/var/lib/freeswitch/storage/NFS/`basename "$DIRECTORY"`/archive/`date -d "yesterday" +%Y/%b/%d`
if [ -d "$DIRYESTERDAY" ]; then
if [ -d "$DIRNFS" ]; then
rsync -ar --no-owner --no-group $DIRYESTERDAY $DIRNFS
psql --host=127.0.0.2 --username=fusionpbx -t -c "UPDATE v_call_recordings SET call_recording_path = REPLACE(call_recording_path,'recordings','storage/NFS') WHERE call_recording_path = '$DIRYESTERDAY'"
if [ $YESTDAY = "01" ]; then
chown -R www-data:www-data /var/lib/freeswitch/storage/NFS/`basename "$DIRECTORY"`/archive/`date -d "yesterday" +%Y/%b`
else
chown -R www-data:www-data $DIRNFS
fi
else
mkdir -p $DIRNFS
rsync -ar --no-owner --no-group $DIRYESTERDAY $DIRNFS
psql --host=127.0.0.2 --username=fusionpbx -t -c "UPDATE v_call_recordings SET call_recording_path = REPLACE(call_recording_path,'recordings','storage/NFS') WHERE call_recording_path = '$DIRYESTERDAY'"
if [ $YESTDAY = "01" ]; then
chown -R www-data:www-data /var/lib/freeswitch/storage/NFS/`basename "$DIRECTORY"`/archive/`date -d "yesterday" +%Y/%b`
else
chown -R www-data:www-data $DIRNFS
fi
fi
fi
done
Step 3:
Modify the /etc/cron.daily/fusionpbx-housekeeping.sh file so that call recordings are deleted every 2 or 3 days time from the main disk.
Step 4:
Either from the NFS Server or from the FusionPBX server setup a cronjob delete call recordings.
Ex:
/etc/cron.daily/recording_del
Bash:
#!/bin/bash
#delete mp3 and wav recordings older then 90 days
find /path/to/NFS/*/archive/ -type f \( -name \*.mp3 -o -name \*.wav \) -mtime +90 -exec rm {} \;