Quinntin Comer Posted September 12 Report Share Posted September 12 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 Quote Link to comment Share on other sites More sharing options...
Scott1234 Posted September 13 Report Share Posted September 13 Noice. thanks for sharing! I use this to replicate every hour to another datacentre for a worst-case scenario. It only does the changes with a bandwidth limit. @hourly rsync --bwlimit=2048 --delete-before -av /usr/local/pbx ******@****.***:/usr/local/ Quote Link to comment Share on other sites More sharing options...
Quinntin Comer Posted September 14 Author Report Share Posted September 14 On 9/12/2023 at 5:17 PM, Scott1234 said: Noice. thanks for sharing! I use this to replicate every hour to another datacentre for a worst-case scenario. It only does the changes with a bandwidth limit. @hourly rsync --bwlimit=2048 --delete-before -av /usr/local/pbx ******@****.***:/usr/local/ Absolutely could add that as a step! Quote Link to comment Share on other sites More sharing options...
RichardDCG Posted Wednesday at 11:38 PM Report Share Posted Wednesday at 11:38 PM On 9/13/2023 at 7:37 AM, Quinntin Comer said: find "$backup_dir/*.tgz" -mtime +7 exec rm {} \; I had to modify this line to ... (remove "'s and add - to exec) find $backup_dir/*.tgz -mtime +7 -exec rm {} \; Other than that everything else works perfectly, very helpful, thanks! Quote Link to comment Share on other sites More sharing options...
Quinntin Comer Posted Thursday at 03:47 AM Author Report Share Posted Thursday at 03:47 AM 4 hours ago, RichardDCG said: I had to modify this line to ... (remove "'s and add - to exec) find $backup_dir/*.tgz -mtime +7 -exec rm {} \; Other than that everything else works perfectly, very helpful, thanks! Glad that was useful for you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.