Question
The following are the same questions, just phrased differently:
Why won't cPanel delete ( prune ) old backups?
Why is my backup retention setting not enforced?
Answer
If the newest backup is incomplete, defective, or in some other manner unreliable, the backups will not be pruned. Additionally, the backup system does not check to see if the backup is acceptable for pruning until after the newest backup job has been completed.
In a situation where automatic removal of older backups occur, it would be possible for the automated system to remove an older, but reliable backup. The newer, but unreliable backup would then be the only backup available for use. In the event that a backup is needed, this could result in disaster due to the fact that no reliable backup exists.
To mitigate this risk, cPanel analyzes the outcome of each backup session to determine if a problem occurred during the generation of the backup. At the time of writing this article, cPanel's backup system specifically looks for the following errors in the backup log to determine if a significant problem has occurred that would qualify the suspension of backup pruning:
# awk -F'/' '/ERROR_PATTERNS =/,/]/ { if ($2) print $2; }' /usr/local/cpanel/bin/backup
Unable to get user id
Unable to load cPanel user data
You cannot copy the root user
pkgacct failed to copy daily backup
Could not use daily backup
Bailing out
The REMOTE_PASSWORD variable is missing
Unable to find domain name
Exiting with error code
Could not remove directory
Hook denied execution of pkgacct
Could not open
Could not chmod
Could not rename
failed to create the working dir
Unable to fork
Unable to waitpid
Unable to open
Failure dumping
Unable to read
does not appear to be valid XML
Could not create directory
mysqldump: Got error
mysqldump: Error
mysqldump: Couldn't
mysqldump failed
“Mysql” failed with an error
Failed to generate backup metadata
If one of those errors has been found within the backup log, and Forced Pruning has not been enabled in the backup configuration, cPanel will not prune any of the older backups. This is an all-or-nothing condition. In other words, even if there is a problem with only a single account's backup, none of the older backups for any account will be removed.
The following one-line script can be run as the root user via Terminal or SSH to search the backup logs in the same manner that the backup system does. If no output is produced by the script, it means that no errors occurred that would prevent backup pruning. If the script does produce output, it means that those are the specific errors within the backup log that are preventing the old backups from being removed. You must fix the problems that are causing those errors in order to resume pruning.
awk -F'/' '/ERROR_PATTERNS =/,/]/ { if ($2) print $2; }' /usr/local/cpanel/bin/backup | while read ERROR;do grep --with-filename "$ERROR" /usr/local/cpanel/logs/cpbackup/*;done
The most typical cause for backup pruning to be skipped is a problem with crashed database tables. We have a guide that explains how to address this commonly occurring issue:
Database table is marked as crashed and should be repaired
If the errors that you are seeing are not specifically caused by crashed database tables, you'll need to consult with a systems administrator to determine the best course of action required to resolve those errors.