Hi folks,
Thought I would share this in case anyone was interested. This is just a daily script for backing up the PBX data directory.
We have a file "vodiapbx-backup" in the /etc/cron.daily folder with no extension, just named "vodiapbx-backup", so that it will run dailly.
You can see when your cron jobs are scheduled by running the following command:
grep run-parts /etc/crontab
and you will see results similar to:
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
Based on the results above, you can see our daily will run at 6:25 daily.
https://crontab.guru/#25_6_*_*_*
In that "vodiapbx-backup" file, we have the following script:
#!/bin/sh
# Set the variables
source_dir="/usr/local/pbx"
backup_dir="/data/backups"
now=$(date +%Y%m%d)
filename="VodiaPBX_Backup_$now.tgz"
# Delete backups older than 7 days
echo "Deleting older backups"
find "$backup_dir/*.tgz" -mtime +7 exec rm {} \;
# Start Backups
echo "Starting Backup"
tar -zvcf "$backup_dir/$filename" "$source_dir"
This script will perform the following:
Define the following variables:
source_dir: This is the source directory we want to backup
backup_dir: This is the path where we want to store our backup (in our case, we have a mounted volume)
now: This is the current datetime stamp with YYYY/MM/DD format.
filename: This is the filename to use for the backup file, example: VodiaPBX_Backup_20230912.tgz"
Deletes any tgz files older than 7 days from the backup_dir path
compresses the source_dir path into $backup_dir/$filename