Splitting cPanel Backups Across Days With a Rotation Script
Managing backups on a busy cPanel server can get tricky, especially when account sizes vary widely. Running full backups of all accounts every day can push disk usage to the limit,slow down the server, or even fail if temporary archives eat up available space. therefor splitting cpanel backups into groups fixes this.
We faced exactly this scenario and solved it by splitting our cPanel users into two groups, then rotating which group is included in backups on different days. The result: lighter nightly loads, no disk exhaustion, and still complete coverage within the week.
The Problem
Our server hosts several very large accounts alongside dozens of smaller ones. A single run of compressed backups risked filling the main partition to 100%. Incremental backups helped locally, but since we also push to remote destinations, temporary archives were unavoidable.
The solution was to rotate users:
- Group A → backed up on Wednesdays
- Group B → backed up on Saturdays
This keeps backup windows smaller and avoids simultaneous archiving of every account.
The Script
We wrote a small Bash script to flip the BACKUP=
flag in each cPanel user file under /var/cpanel/users
. The script checks the current weekday, enables the correct group, and disables the other. On non-backup days, it makes no changes.
Here’s the final version (with dummy usernames):
Splitting cPanel Backups By Rotation !
#!/bin/bash
# =============================================================================
# cPanel Backup Rotator
#
# Enables/disables cPanel account backups depending on day of week.
# Group A runs Wednesdays, Group B runs Saturdays.
# =============================================================================
WEDNESDAY_USERS="userA userB userC userD userE"
SATURDAY_USERS="userF userG userH userI userJ userK userL userM"
CPANEL_USERS_DIR="/var/cpanel/users"
CURRENT_DAY=$(LC_TIME=C date +%a)
echo "--- Starting Backup Rotation Script ---"
echo "Today is: $CURRENT_DAY"
if [ "$CURRENT_DAY" = "Wed" ]; then
echo "It's Wednesday. Enabling Group A and disabling Group B."
for user in $WEDNESDAY_USERS; do
user_file="$CPANEL_USERS_DIR/$user"
[ -f "$user_file" ] && grep -q '^BACKUP=' "$user_file" \
&& sed -i 's/^BACKUP=.*/BACKUP=1/' "$user_file" \
|| echo "BACKUP=1" >> "$user_file"
echo " [ENABLED] $user"
done
for user in $SATURDAY_USERS; do
user_file="$CPANEL_USERS_DIR/$user"
[ -f "$user_file" ] && grep -q '^BACKUP=' "$user_file" \
&& sed -i 's/^BACKUP=.*/BACKUP=0/' "$user_file" \
|| echo "BACKUP=0" >> "$user_file"
echo " [DISABLED] $user"
done
elif [ "$CURRENT_DAY" = "Sat" ]; then
echo "It's Saturday. Enabling Group B and disabling Group A."
for user in $SATURDAY_USERS; do
user_file="$CPANEL_USERS_DIR/$user"
[ -f "$user_file" ] && grep -q '^BACKUP=' "$user_file" \
&& sed -i 's/^BACKUP=.*/BACKUP=1/' "$user_file" \
|| echo "BACKUP=1" >> "$user_file"
echo " [ENABLED] $user"
done
for user in $WEDNESDAY_USERS; do
user_file="$CPANEL_USERS_DIR/$user"
[ -f "$user_file" ] && grep -q '^BACKUP=' "$user_file" \
&& sed -i 's/^BACKUP=.*/BACKUP=0/' "$user_file" \
|| echo "BACKUP=0" >> "$user_file"
echo " [DISABLED] $user"
done
else
echo "Not a designated backup day. No changes will be made."
fi
echo "--- Backup Rotation Script Finished ---"
Setting Up the Cron Job
With the script saved at /root/backup_rotation.sh
, we added two cron entries so the rotation happens before cPanel’s scheduled backups:
# Run rotation every Wednesday at 01:00
0 1 * * 3 /root/backup_rotation.sh > /dev/null 2>&1
# Run rotation every Saturday at 01:00
0 1 * * 6 /root/backup_rotation.sh > /dev/null 2>&1
And the default cPanel backup runs daily at 02:00:
0 2 * * * /usr/local/cpanel/bin/backup
This ensures the correct group is enabled about an hour before the backup starts.
The Result
Now backups run smoothly:
- The server isn’t overloaded.
- Backup windows are shorter.
- Every account is backed up twice per week, split across days.
By using nothing more than a Bash script and cron, we solved what could have required third-party backup software.
✅ If you run into similar disk pressure issues with cPanel backups, splitting accounts into rotating groups is a simple, effective solution.