2017-03-29 23:03:24 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
2017-03-29 23:08:53 +02:00
|
|
|
#settings
|
2018-12-11 09:20:09 +01:00
|
|
|
export PGPASSWORD="zzz"
|
2017-03-29 23:03:24 +02:00
|
|
|
db_host=127.0.0.1
|
|
|
|
|
db_port=5432
|
2017-03-29 23:08:53 +02:00
|
|
|
switch_package=true # true or false
|
2017-03-29 23:03:24 +02:00
|
|
|
|
2021-09-18 20:39:13 +02:00
|
|
|
purge_voicemail=false
|
|
|
|
|
purge_call_recordings=false
|
|
|
|
|
purge_cdrs=false
|
|
|
|
|
purge_fax=false
|
|
|
|
|
purge_switch_logs=true
|
|
|
|
|
|
|
|
|
|
days_keep_voicemail=90
|
|
|
|
|
days_keep_call_recordings=90
|
|
|
|
|
days_keep_cdrs=90
|
|
|
|
|
days_keep_fax=90
|
|
|
|
|
days_keep_switch_logs=7
|
2017-03-29 23:08:53 +02:00
|
|
|
#set the date
|
2017-03-29 23:03:24 +02:00
|
|
|
now=$(date +%Y-%m-%d)
|
2017-03-29 23:08:53 +02:00
|
|
|
|
|
|
|
|
#make sure the directory exists
|
2021-09-18 20:39:13 +02:00
|
|
|
if [ -e /var/backups/fusionpbx/postgresql ]; then
|
|
|
|
|
echo "postgres backup directory exists"
|
|
|
|
|
else
|
|
|
|
|
mkdir -p /var/backups/fusionpbx/postgresql
|
|
|
|
|
fi
|
2017-03-29 23:03:24 +02:00
|
|
|
|
|
|
|
|
#show message to the console
|
|
|
|
|
echo "Maintenance Started"
|
|
|
|
|
|
2021-09-18 20:39:13 +02:00
|
|
|
if [ .$purge_switch_logs = .true ]; then
|
|
|
|
|
#delete freeswitch logs older 7 days
|
|
|
|
|
if [ .$switch_package = .true ]; then
|
|
|
|
|
find /var/log/freeswitch/freeswitch.log.* -mtime +$days_keep_switch_logs -exec rm {} \;
|
|
|
|
|
else
|
|
|
|
|
find /usr/local/freeswitch/log/freeswitch.log.* -mtime +$days_keep_switch_logs -exec rm {} \;
|
|
|
|
|
fi
|
2017-03-29 23:08:53 +02:00
|
|
|
else
|
2021-09-18 20:39:13 +02:00
|
|
|
echo "not purging Freeswitch logs"
|
2017-03-29 23:08:53 +02:00
|
|
|
fi
|
2017-03-29 23:03:24 +02:00
|
|
|
|
2021-09-18 20:39:13 +02:00
|
|
|
if [ .$purge_fax = .true]; then
|
|
|
|
|
#delete fax older than 90 days
|
|
|
|
|
if [ .$switch_package = .true ]; then
|
|
|
|
|
echo ".";
|
|
|
|
|
find /var/lib/freeswitch/storage/fax/* -name '*.tif' -mtime +$days_keep_fax -exec rm {} \;
|
|
|
|
|
find /var/lib/freeswitch/storage/fax/* -name '*.pdf' -mtime +$days_keep_fax -exec rm {} \;
|
|
|
|
|
else
|
|
|
|
|
echo ".";
|
|
|
|
|
find /usr/local/freeswitch/storage/fax/* -name '*.tif' -mtime +$days_keep_fax -exec rm {} \;
|
|
|
|
|
find /usr/local/freeswitch/storage/fax/* -name '*.pdf' -mtime +$days_keep_fax -exec rm {} \;
|
|
|
|
|
fi
|
|
|
|
|
#delete from the database
|
|
|
|
|
psql --host=127.0.0.1 --username=fusionpbx -c "delete from v_fax_files WHERE fax_date < NOW() - INTERVAL '$days_keep_fax days'"
|
|
|
|
|
psql --host=127.0.0.1 --username=fusionpbx -c "delete from v_fax_logs WHERE fax_date < NOW() - INTERVAL '$days_keep_fax days'"
|
2017-03-29 23:08:53 +02:00
|
|
|
else
|
2021-09-18 20:39:13 +02:00
|
|
|
echo "not purging Faxes"
|
2017-03-29 23:08:53 +02:00
|
|
|
fi
|
2017-03-29 23:03:24 +02:00
|
|
|
|
2021-09-18 20:39:13 +02:00
|
|
|
if [ .$purge_call_recordings = .true ]; then
|
|
|
|
|
#delete call recordings older than 90 days
|
|
|
|
|
if [ .$switch_package = .true ]; then
|
|
|
|
|
find /var/lib/freeswitch/recordings/*/archive/* -name '*.wav' -mtime +$days_keep_call_recordings -exec rm {} \;
|
|
|
|
|
find /var/lib/freeswitch/recordings/*/archive/* -name '*.mp3' -mtime +$days_keep_call_recordings -exec rm {} \;
|
|
|
|
|
else
|
|
|
|
|
find /usr/local/freeswitch/recordings/*/archive/* -name '*.wav' -mtime +$days_keep_call_recordings -exec rm {} \;
|
|
|
|
|
find /usr/local/freeswitch/recordings/*/archive/* -name '*.mp3' -mtime +$days_keep_call_recordings -exec rm {} \;
|
|
|
|
|
fi
|
|
|
|
|
psql --host=127.0.0.1 --username=fusionpbx -c "delete from v_call_recordings WHERE call_recording_date < NOW() - INTERVAL '90 days'"
|
2017-08-18 19:21:06 +02:00
|
|
|
else
|
2021-09-18 20:39:13 +02:00
|
|
|
echo "not purging Recordings."
|
2017-08-18 19:21:06 +02:00
|
|
|
fi
|
2018-08-30 21:19:38 +02:00
|
|
|
|
2021-09-18 20:39:13 +02:00
|
|
|
if [ .$purge_voicemail = .true ]; then
|
|
|
|
|
#delete voicemail older than 90 days
|
|
|
|
|
if [ .$switch_package = .true ]; then
|
|
|
|
|
echo ".";
|
|
|
|
|
find /var/lib/freeswitch/storage/voicemail/default/* -name 'msg_*.wav' -mtime +$days_keep_voicemail -exec rm {} \;
|
|
|
|
|
find /var/lib/freeswitch/storage/voicemail/default/* -name 'msg_*.mp3' -mtime +$days_keep_voicemail -exec rm {} \;
|
|
|
|
|
else
|
|
|
|
|
echo ".";
|
|
|
|
|
find /usr/local/freeswitch/storage/voicemail/* -name 'msg_*.wav' -mtime +$days_keep_voicemail -exec rm {} \;
|
|
|
|
|
find /usr/local/freeswitch/storage/voicemail/* -name 'msg_*.mp3' -mtime +$days_keep_voicemail -exec rm {} \;
|
|
|
|
|
fi
|
|
|
|
|
psql --host=127.0.0.1 --username=fusionpbx -c "delete from v_voicemail_messages WHERE to_timestamp(created_epoch) < NOW() - INTERVAL '$days_keep_voicemail days'"
|
2017-03-29 23:08:53 +02:00
|
|
|
else
|
2021-09-18 20:39:13 +02:00
|
|
|
echo "not purging voicemails."
|
2017-03-29 23:08:53 +02:00
|
|
|
fi
|
2021-04-26 19:57:23 +02:00
|
|
|
|
2021-09-18 20:39:13 +02:00
|
|
|
if [ .$purge_cdrs = .true ]; then
|
|
|
|
|
#delete call detail records older 90 days
|
|
|
|
|
psql --host=127.0.0.1 --username=fusionpbx -c "delete from v_xml_cdr WHERE start_stamp < NOW() - INTERVAL '$days_keep_cdrs days'"
|
|
|
|
|
else
|
|
|
|
|
echo "not purging CDRs."
|
|
|
|
|
fi
|
2021-04-26 19:57:23 +02:00
|
|
|
|
2017-04-11 04:06:57 +02:00
|
|
|
#completed message
|
|
|
|
|
echo "Maintenance Completed";
|