While setting up backups in cPanel, it is important to exclude certain files from Backups. For instance, if the user’s home directory stores backups generated by WordPress plugins, then, they need to be removed from the cPanel backup routine.
As a part of Server Management Services, we help our customers with almost every task using WHM or cPanel interface.
Let us today see how to exclude certain files or folders from cPanel backup.
Why do we need to Exclude Files from Backups in cPanel?
Recently, we received a support request where the customer was complaining that the cPanel backups. Our Support Engineers noticed that customer had configured a WordPress plugin to generate a backup of the site. These backups were stored within user’s home directory.
Packaging these already compressed backups within another backup will not compress them further. However, it just inflates the size of the cPanel backup. Moreover, it consumes more disk space.
It is also important to exclude some files due to security reasons. Furthermore, error logs and other files not necessary for site restoration can also be excluded from the backup.
How to Exclude Files from Backups in cPanel ?
The exclude files can be set up in two different methods. We could either set up excludes for all users’ backups or for an individual user’s backups.
The global and local exclude files apply to the account backups that we manage in WHM’s Backup section (WHM >> Home >> Backup) and the “Download a Full Website Backup” feature in cPanel’s Backup interface (cPanel >> Home >> Files >> Backup).
If we initiate a Home Directory Backup in cPanel’s Backup interface (cPanel >> Home >> Files >> Backup), the global and local exclude files do not affect the contents of the backup file.
If we perform a backup with the /scripts/pkgacct script, the global and local exclude files do not affect the contents of the backup file.
The backup-exclude.conf files only apply to files or directories in a user’s home directory. They do not apply to files or directories outside of a user’s home directory.
Global exclude file
To exclude files or directories from backups for all user accounts, add those files or directories to the /etc/cpbackup-exclude.conf file. The /etc/cpbackup-exclude.conf file excludes the files that we specify relative to any location from which the backup script runs.
The backup system excludes the following files and directories for all users’ backups by default:
Local exclude file
To exclude files or directories from an individual user’s backups, add the desired paths (relative to the user’s home directory) to the cpbackup-exclude.conf file in the user’s home directory, with one entry per line.
If the file does not already exist, we must create it. To do this, run the following command:
# touch /home/username/cpbackup-exclude.conf
In this example, username represents the name of the user who owns the files or directories.
If we enter a directory name, the backup system excludes all of the files that exist in the directory.
When we specify files, do not include leading or trailing characters of any kind, such as slashes (/) or periods (.).
For example, to exclude the /home/username/example/ directory and the /home/username/dir/example.php file from the username user’s backups, create the following /home/username/cpbackup-exclude.conf file:
example/
dir/example.php
[Need any further assistance with cPanel backups? – We’re available 24*7]
Conclusion
In short, we would require to exclude certain files from backups in cPanel either for security purposes or to reduce the size of the backup file. Today we saw how our Support Engineers set up both global and local exclude files.
0 Comments