Fork of FusionPBX but with LDAP kinda working
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
4.9 KiB

  1. #!/bin/sh
  2. #settings
  3. export PGPASSWORD="zzz"
  4. db_host=127.0.0.1
  5. db_port=5432
  6. switch_package=true # true or false
  7. purge_voicemail=false
  8. purge_call_recordings=false
  9. purge_cdrs=false
  10. purge_fax=false
  11. purge_switch_logs=true
  12. purge_php_sessions=true
  13. purge_database_transactions=true
  14. purge_email_queue=false
  15. purge_fax_queue=true
  16. days_keep_voicemail=90
  17. days_keep_call_recordings=90
  18. days_keep_cdrs=90
  19. days_keep_fax=90
  20. days_keep_switch_logs=7
  21. days_keep_php_sessions=8
  22. days_keep_database_transactions=30
  23. days_keep_email_queue=30
  24. days_keep_fax_queue=30
  25. #set the date
  26. now=$(date +%Y-%m-%d)
  27. #make sure the directory exists
  28. if [ -e /var/backups/fusionpbx/postgresql ]; then
  29. echo "postgres backup directory exists"
  30. else
  31. mkdir -p /var/backups/fusionpbx/postgresql
  32. fi
  33. #show message to the console
  34. echo "Maintenance Started"
  35. if [ .$purge_switch_logs = .true ]; then
  36. #delete freeswitch logs older 7 days
  37. if [ .$switch_package = .true ]; then
  38. find /var/log/freeswitch/freeswitch.log.* -mtime +$days_keep_switch_logs -exec rm {} \;
  39. else
  40. find /usr/local/freeswitch/log/freeswitch.log.* -mtime +$days_keep_switch_logs -exec rm {} \;
  41. fi
  42. else
  43. echo "not purging Freeswitch logs"
  44. fi
  45. if [ .$purge_fax = .true ]; then
  46. #delete fax older than 90 days
  47. if [ .$switch_package = .true ]; then
  48. echo ".";
  49. find /var/lib/freeswitch/storage/fax/* -name '*.tif' -mtime +$days_keep_fax -exec rm {} \;
  50. find /var/lib/freeswitch/storage/fax/* -name '*.pdf' -mtime +$days_keep_fax -exec rm {} \;
  51. else
  52. echo ".";
  53. find /usr/local/freeswitch/storage/fax/* -name '*.tif' -mtime +$days_keep_fax -exec rm {} \;
  54. find /usr/local/freeswitch/storage/fax/* -name '*.pdf' -mtime +$days_keep_fax -exec rm {} \;
  55. fi
  56. #delete from the database
  57. psql --host=127.0.0.1 --username=fusionpbx -c "delete from v_fax_files WHERE fax_date < NOW() - INTERVAL '$days_keep_fax days'"
  58. psql --host=127.0.0.1 --username=fusionpbx -c "delete from v_fax_logs WHERE fax_date < NOW() - INTERVAL '$days_keep_fax days'"
  59. else
  60. echo "not purging Faxes"
  61. fi
  62. if [ .$purge_call_recordings = .true ]; then
  63. #delete call recordings older than 90 days
  64. if [ .$switch_package = .true ]; then
  65. find /var/lib/freeswitch/recordings/*/archive/* -name '*.wav' -mtime +$days_keep_call_recordings -exec rm {} \;
  66. find /var/lib/freeswitch/recordings/*/archive/* -name '*.mp3' -mtime +$days_keep_call_recordings -exec rm {} \;
  67. else
  68. find /usr/local/freeswitch/recordings/*/archive/* -name '*.wav' -mtime +$days_keep_call_recordings -exec rm {} \;
  69. find /usr/local/freeswitch/recordings/*/archive/* -name '*.mp3' -mtime +$days_keep_call_recordings -exec rm {} \;
  70. fi
  71. psql --host=127.0.0.1 --username=fusionpbx -c "delete from v_call_recordings WHERE call_recording_date < NOW() - INTERVAL '90 days'"
  72. else
  73. echo "not purging Recordings."
  74. fi
  75. if [ .$purge_voicemail = .true ]; then
  76. #delete voicemail older than 90 days
  77. if [ .$switch_package = .true ]; then
  78. echo ".";
  79. find /var/lib/freeswitch/storage/voicemail/default/* -name 'msg_*.wav' -mtime +$days_keep_voicemail -exec rm {} \;
  80. find /var/lib/freeswitch/storage/voicemail/default/* -name 'msg_*.mp3' -mtime +$days_keep_voicemail -exec rm {} \;
  81. else
  82. echo ".";
  83. find /usr/local/freeswitch/storage/voicemail/* -name 'msg_*.wav' -mtime +$days_keep_voicemail -exec rm {} \;
  84. find /usr/local/freeswitch/storage/voicemail/* -name 'msg_*.mp3' -mtime +$days_keep_voicemail -exec rm {} \;
  85. fi
  86. 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'"
  87. else
  88. echo "not purging voicemails."
  89. fi
  90. if [ .$purge_cdrs = .true ]; then
  91. #delete call detail records older 90 days
  92. psql --host=127.0.0.1 --username=fusionpbx -c "delete from v_xml_cdr WHERE start_stamp < NOW() - INTERVAL '$days_keep_cdrs days'"
  93. else
  94. echo "not purging CDRs."
  95. fi
  96. #delete php sessions
  97. if [ .$purge_php_sessions = .true ]; then
  98. find /var/lib/php/sessions/* -name 'sess_*' -mtime +$days_keep_php_sessions -exec rm {} \;
  99. else
  100. echo "not purging PHP Sessions."
  101. fi
  102. #delete database_transactions older 90 days
  103. if [ .$purge_database_transactions = .true ]; then
  104. psql --host=127.0.0.1 --username=fusionpbx -c "delete from v_database_transactions where transaction_date < NOW() - INTERVAL '$days_keep_database_transactions days'"
  105. else
  106. echo "not purging database_transactions."
  107. fi
  108. #delete email_queue older 30 days
  109. if [ .$purge_email_queue = .true ]; then
  110. psql --host=127.0.0.1 --username=fusionpbx -c "delete from v_email_queue where email_status = 'sent' and email_date < NOW() - INTERVAL '$days_keep_email_queue days'"
  111. else
  112. echo "not purging email_queue."
  113. fi
  114. #delete fax_queue older 30 days
  115. if [ .$purge_fax_queue = .true ]; then
  116. psql --host=127.0.0.1 --username=fusionpbx -c "delete from v_fax_queue where fax_status = 'sent' and fax_date < NOW() - INTERVAL '$days_keep_fax_queue days'"
  117. else
  118. echo "not purging fax_queue."
  119. fi
  120. #completed message
  121. echo "Maintenance Completed";