Enhanced Backup Retention & Rotation for Backups on Remote FTP Servers

Status
Not open for further replies.

AaronWJM360

Registered
Dec 30, 2012
1
0
1
cPanel Access Level
Root Administrator
Hi Guys!

I have created a script which enhances the backups retention and rotation for any backups stored on remote FTP servers. It is very useful to me so would like to share it with the cPanel community.

With the standard cPanel backups at the time of writing this, you can only have one copy of the daily backups, one copy of the weekly backups and one copy of the monthly backups. This can be an issue if you had a problem with a site 2 or 3 days ago, as you will not have the backup for this, apart from a possible weekly backup which you could have made many changes since then.

The script I have created will connect to the remote FTP server and check for any folders named 'daily', which is the default naming scheme for cPanel backups. It will then rename it with the current date, making it 'daily.301212'. It will also do the same for weekly and monthly backups too.

The script will also check any folders with a date set to a certain age. For example, I currently have the daily backups rotation set to 7, which means any daily backups older than 7 days will be automatically deleted. This will stop any FTP drives from filling up with backups.

To run the scripts, I would recommend placing them in a non-public accessible folder within your home directory in cPanel, and running a daily cron job on each PHP file. Here are the cron jobs I have set up for myself (you will need to alter them to suit your environment):

0 9 * * * php -q /home/awjmho/backup-controller/daily.php
0 9 * * * php -q /home/awjmho/backup-controller/weekly.php
0 9 * * * php -q /home/awjmho/backup-controller/monthly.php

For the script to work successfully, you will need to edit the FTP host, username and password within the 'configuration.php' file and set the rotation value on line 3 in every other file (daily.php/weekly.php/monthly.php). It is self explanatory once you open the file.

I hope this is useful to someone.

I will not be held liable for any damage caused by this script, use and implementation of this script is entirely at your own risk.
 
Last edited by a moderator:
Status
Not open for further replies.