(Last Updated On: November 30, 2018)

Data backup is the most important part of running a business, especially in the Cloud space. With Cpanel, you have the option to backup your website data and databases locally, or to a cloud storage like Amazon S3.  In this guide, we will configure a Cpanel automated backup policy – locally and to S3 Object storage.

How to Configure a Backup Policy in Cpanel

To configure Cpanel policy, login to WHM and search for “Backup” the open linkBackup Configuration.

By default Cpanel Backup is disabled, enable it by clicking the “Disable” button under Backup Status:

Under Backup Type, choose “Compressed

When you select incremental backups, the system will not change or alter the state of your existing non-incremental backup destinations. Rsync transport is used for incremental backups.

Set minimum free Disk Space check before the system performs the backups. I recommend setting `10%`

Under Scheduling and Retention, set backup times that fit your setup

You can also choose a weekly and monthly backups with a retention policy

Configure Backup Directory

My Cpanel server has a dedicated disk for Backups /dev/xvdf:

# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  160G  0 disk
└─xvda1 202:1    0  160G  0 part /
xvdf    202:80   0  100G  0 disk

I’ll partition and mount this disk to /backup directory.

sudo parted -s -a optimal -- /dev/xvdf mklabel gpt
sudo parted -s -a optimal -- /dev/xvdf mkpart primary 0% 100%
sudo parted -s -- /dev/xvdf align-check optimal 1

Install LVM Tools

sudo yum -y install lvm2

Configure LVM and mount the partition to /backup

sudo pvcreate /dev/xvdf1
sudo vgcreate vg0 /dev/xvdf1
sudo lvcreate -n backups -l+100%FREE vg0
sudo mkfs.xfs /dev/mapper/vg0-backups

Confirm configurations

# lsblk -f /dev/xvdf
NAME            FSTYPE      LABEL UUID                                   MOUNTPOINT
xvdf
└─xvdf1         LVM2_member       zaDr75-WB07-dVsB-4Mtk-CUS9-fcq1-9KXQoO
  └─vg0-backups xfs               d0fb587e-3bd4-4084-81e7-5c2b209635e7

Create the /backupdirectory if doesn’t exist:

[ -d /backup ] || sudo mkdir /backup

Set mount on boot for the Logical Volume:

echo "/dev/mapper/vg0-backups /backup xfs defaults 0 0" | sudo tee -a /etc/fstab

Mount the partition:

$ sudo mount -a
$ df -h | grep backups
/dev/mapper/vg0-backups  100G   33M  100G   1% /backup

Confirm Default Backup Directory and save your Configurations

Create S3 Bucket for Cpanel

Login to your AWS dashboard and navigate to S3 > Create bucket

Give the bucket a name and configure options and permissions then click “Create bucket“.

Go back to WHM Backup Configuration section, then click on Additional Destinations

Choose Amazon S3 and hit Create new destination. On the next page, provide Destination Name:

Provide system Backups folder, AWS S3 bucket name, Access Key ID and Secret Access Key:

When done, Save Destination. Good work!. Your Cpanel backup policy for both locally and to S3 Object Store has been configured. You can also read:

How to Install PHP Composer on Cpanel

How to add PHPZIP Archive in cPanel

Configure Cpanel Firewalld on CentOS 7

Other AWS articles available in our blog are:

How to extend EBS boot disk on AWS without an instance reboot

Create AWS S3 Upload and List Objects Policy without Delete Action

How to Configure Cpanel Backups to S3 Object Store

How to Install and Use AWS CLI on Linux – Ubuntu / Debian / CentOS

How to Reset RDS Master User Password on AWS