This headline doesn’t fully encompass the broad nature of this article. In fact, this article will address much more than just restoring S3 backups to a new server. We will delve into the cPanel backup process, go through a typical S3 restoration onto the same server, and conclude with a simple way to restore S3 cPanel backups to a new server.
Disclaimer: we assume no responsibility for any issues/damage. We have no affiliation with cPanel/WHM or Amazon Web Services. We’re just passionate about cloud computing and want to share our findings!
How to Configure AWS S3 Backups from WHM
Without further ado, here’s what you need to do to setup an automated backup from your cPanel/WHM server to Amazon S3. cPanel makes this process super simple, but before we do anything on the server side, we need to log in or sign up for Amazon Web Services.
After you’re logged in to AWS, navigate to S3 and click, “Create Bucket.” Give the bucket a unique name and select a region for the
files to be stored. S3 pricing information for various regions is available here (side note, if you’re new to AWS, you’ll likely be able to utilize the AWS Free Usage Tier and pay nothing for the first year!).
Once your Amazon S3 Bucket has finished being configured, head over to IAM, now we’re going to generate an access and secret key so WHM can access your bucket. Once in IAM, click on, “Users” and click, “Add User.” Enter a username for the account (we would recommend you set the username as something that would identify it as your WHM-AWS link). Once a username is defined, check the box for, “Programmatic Access” under, “Access Type.” Selecting Programmatic Access important as this selection will generate the needed keys to make the connection. Next, you’ll be prompted to set permissions for your new user account. Click, “Create Group” and give it a name that correlates with S3 full access. Then, search for, “S3” and select, “AmazonS3FullAccess” from the policy list. Finish by hitting, “Create Group” followed by, “Next: Review.”
The next page you will be brought to will prompt you to review the user account you’re about to create. If this information is correct, click, “Create User.” Now, copy your Access Key ID and Secret Access Key in a safe place. We will need to use this in a moment (Note: treat this as a username and password, if someone gets ahold of this, they will have full access to your S3 account… not good!).
Once your Access Key ID and Secret Access Key are in a safe place, navigate over to your cPanel/WHM Server and log into WHM. Once logged in, navigate to the “Backup Configuration” page located on the left-hand menu bar. This page will help you get set with S3 backups. First, set, “Backup Status” to, “Enable” and our recommendation is that the Backup Type is, “Compressed.” Our max destination timeout is 7200 seconds, and maximum restore timeout is 21600 seconds. Next, set the frequency of backups under, “Scheduling and Retention.” Then, under, “Files” select what information you would like to back up. At the bottom of the page, under, “Additional Destinations” select Amazon S3 as a Destination Type and hit, “Create New Destination.” Enter a name for the destination as well as the name of your bucket as well as your Access Key ID and Secret Access Key. Now hit, “Save Destination” and you’re ready to go!
How to Restore cPanel Backups
Let’s say a client had a rogue developer who deleted all their files, here’s your time to be a superhero. To restore individual user accounts from WHM’s backup restoration tool, navigate to, “Backup Restoration” within WHM and select the cPanel account under, “Restore by Account.” Then, select a restore date, hit, “Add Account to Queue,” and click, “Restore” at the bottom of the page. Within minutes, the cPanel account will restore to the selected date.
How to Restore cPanel Backups from AWS to a Fresh Server
Why may you need to restore your cPanel backups to a new server? Well, let’s say your server totally crashed and all data was inaccessible. While this is highly unlikely, unfortunately, there’s always a possibility it’ll happen. Here’s what to do after you’ve reconfigured a new cPanel server (by the way, if you’re reconfiguring your cPanel/WHM server in AWS EC2, check out this article on the step-by-step how-to):
First, you’re going to want to SSH into your cPanel/WHM server as the root user; then you’re going to want to access the home directory, you can do this by executing the following command:
Now that you are in the servers home directory you’ll want to navigate to AWS and open the S3 bucket for your S3 backups. Now, select the date you’d wish to restore from, and select the backup folder (or compressed folder) you want to restore (unfortunately, you’ll need to restore one account at a time). Once you have located the folder, right-click on it and select, “Make Public.” You’re going to want to hustle here as you probably don’t want these files public for too long.
Your folders’ permissions are now public. Click on, “Properties” and copy the link located under, “Name” in the S3 Object Properties. Now, navigate back to your SSH connection and execute the following command:
Hit enter and your S3 backup file will transfer from S3 to your WHM server! Once transferred, navigate back to your backup file and select its properties. Now, drop down the menu for, “Permissions” and hit the x next to “Everyone.” Now hit save. Your backup file access will be restricted again.
With your backup file back on the cPanel/WHM server, it’s time actually to restore the data. Navigate back to WHM and select, “Restore a Full Backup/cpmove File.” Under Security, uncheck, “Restricted Restore” and ensure the, “Restore with Username radio button is selected. Now, drop down the box for, “Username for the account that your wish to restore” and your backup account should be listed in the drop down. Once selected, click, “Restore” and let WHM do its magic. Once complete, if there are no errors, you have successfully restored an S3 backup from another cPanel/WHM server!
Two Quick Troubleshooting Items
If the restored account does not function properly after a restore, you may need to transfer the files again from S3. Make sure you remove the original backup from your server before moving the backup again. Also, when you’re in WHM restoring the backup for the second time, make sure you select, “Overwrite the existing user.”
If you try a second time and things still aren’t right, try a backup from another day, the backup in S3 could be corrupt.
If you have any questions/comments, feel free to leave them below! If you found this article useful, please share it with your friends/professional connections!