cPanel Multiple Daily, Weekly, Monthly Backup Rotation with IONICE and NICE

cpanel

If you’ve ever been the unfortunate person to need a weekly backup when the daily, weekly, and monthly backups for cPanel are all the same, you have probably found out that you end up being SOL one day every month.  This was unacceptable in my opinion as it defeats the purpose of having all of those backups, and luckily there is already a solution that has been around for a while now.

UPDATE 6/21/2014: This has only been confirmed to work with the legacy backup system.  You can now specify these settings in Tweak Settings area of WHM for the new backup system.

I originally started out with the postcpbackup script I found on the whmscripts.net website. This was a great script that worked out perfectly for what I was looking for…you can use this script to create multiple backups which will make sure you are never SOL when those backups would normally be in sync. You can choose how many copies of each backup to store, it works perfect without any need to modify. That was … until backups started causing excessive loads on a couple of our shared servers.

To alleviate the load on the shared servers, I decided to add IONICE and NICE support to the script.  This will allow you to set the IO priority for backups (to prevent IO bottlenecks) and NICE priority to prevent server overload as well.

WHM New Backup System

WHM New Backup System

UPDATE: I am aware that cPanel has recently addressed this problem in newer releases to now allow multiple copies of backups.  The difference is that you can NOT backup incrementally (only what has changed) and you must create full backups if you use the new cPanel backup.  Using this script will allow you to still use incremental backups through the legacy backup system and create multiple backups. Once I have time to do some testing I will test to see the IO and load compared between the two.

Installation

First you will need to download the script to the /scripts/ directory under the cPanel shared server:

Configuration

Now it’s time to configure the backups.  Open the script in your favorite editor:

nano /scripts/postcpbackup

There are a couple setting you need to modify to your preference, first will be the backups:

This will determine how many copies of each you will want to keep. Most of the time I set these at (1 or 2) monthly, 2 weekly, and 2 daily. This will determine how many copies will be saved of each backup before rotating to the new ones. So for instance, 2 weekly backups means you will have the normal weekly backup PLUS one additional backup from the prior week. Rotation will be automatic.

Next you will need to configure the IONICE and NICE settings.

nicecd will be the class data for nice, accepted values are -20 through 19, with 19 being the lowest priority.
ionicesc will be the scheduling class, accepted values are 1 (realtime), 2 (best-effort), or 3 (idle).
ionicecd will be the class data, accepted values are 0-7, with 7 being the lowest priority.

If you do not want to use NICE or IONICE you can comment out line #51

Set Permissions

chmod 755 /scripts/postcpbackup

Testing The Script

There is a built-in test for this script which you can use to see the output.  All you need to do is run this command:

Configuring in WHM

WHM postcpbackup

WHM postcpbackup

Once you have configured and tested everything you are ready to set it up in WHM. Open up WHM interface, navigate to “Configure Backups”, at the bottom it will say “Execute Pre/Post Backup Script”, check the “postcpbackup” checkbox.

Profit!

You can view the project repo on GitHub here:
https://github.com/tripflex/postcpbackup

Myles

Orlando, FL

Did this post help you?

Give back and rate it for me!

Related Posts

  • You will need to extract the backup file (if it was compressed) or look inside the backup directory of that user account and you should find the .sql file

  • Reza

    can you please tell me, How I should use this backed up file!?

    • Depends, this only works for legacy backup system, but you can restore through WHM. Just type in restore in the left hand search box.