Table of contents
Are you sick and tired of paying $70+ for a third party plugin like Updraft for WordPress backup?
Is there a way to do it yourself and to automate it too?
I decided that instead paying a fee, I will create my own scheduled backups by using AWS. Below, I have created a full guide on how to first manually create a WordPress backup and then how to create an automated WordPress backup.
Note** This guide is for those who have there WordPress on a EC2 instance (virtual machine) in AWS
Taking EBS Volume Snapshots
First of all, what is an EBS Volume?
An Amazon EBS volume is a block level storage device that you can attach to your EC2 instance in AWS. After you attach it , you can use it just like a physical hard drive. It provides storage for the drives of your EC2 instance. It will store your data in equally-sized blocks and organizes them into a hierarchy similarly like a traditional file system.
Some benefits of using them are:
- Processes your data faster without effecting network speed
- It can encrypt your data
- Take a snapshot of your data and place it into different AWS regions.
- Easily be backed up and restored to another EC2 instance
- Adaptable in size as you can scale it up or down.
How Can I use it for WordPress?
If you want to take a backup of WordPress data only, you should create snapshots of its EBS volume which will then be stored on Amazon’s S3 storage bucket. These snapshots can capture all your WordPress data within the EBS volume which can then be copied and transferred to another EC2 instance. This is a great disaster plan in case your WordPress becomes corrupt or if somebody hacked and deleted your files.
Prior to carrying out the backup, you should stop the EC2 instance or at least detach an EBS volume which is about to be backed up. This can prevent any failures or errors from occurring and affecting the newly created snapshots.
Creating a WordPress Backup AMI
What is an AMI?
An AMI image is a backup of your entire EC2 instance. Associated with an AMI image are EBS volume snapshots. These EBS snapshots are the backups of the individual EBS volumes attached to the EC2 at the time the AMI image was created.
So in other words, an AMI will contains all the information required for creating a new copy of your WordPress EC2 instance in the AWS. This will copy everything that you need for your environment, including configuration settings, the root volume template, launch permissions, and block device mapping.
Basically, creating an AMI will act as a template for launching a new WordPress AWS EC2 instance and replacing the corrupted one. Note that, before creating a new AMI, it is recommended that you stop the AWS EC2 instance which you want to back up.
Why should I choose AMI over EBS?
Creating a WordPress AMIs is a more effective backup strategy than taking EBS snapshots. This is because AMIs will often contain EBS snapshots as well as your WordPress software configuration which allows you to simply and easily launch it in just a few clicks, free of charge (you only pay for snapshot storage).
Going forward, for small WordPress sites this method would be fine. However, both of these methods require a lot of manual input and cannot be set to run automatically from the EC2 console. If you have a large scale environment of run your own fleet of WordPress EC2 instance, both the above methods can prove to be complicated and error-prone.
This is where AWS Backup comes into play.
Automating WordPress Backup With AWS Backups
Previously, the only way to automate EC2 instance WordPress backups was to run scripts or use API calls which would be intensive and take a lot of time to create. Plus, you had to be a techie in scripting and know what plugs into where. Even if you were highly proficient, there would be a high risk that you would still waste your time, effort and cash on resources but be still be left with failed or corrupt EC2 WordPress backups.
Luckily, AWS created a backup service called AWS Backup which was designed for you to rapidly create automated data backups across your entire environment. You can create policy based backups which will backup any of your resources. You can set up a backup schedule, backup frequency and timing of the backup window allowing minimum input.
Now that the boring stuff is over. I have prepared a walk-through for all three down below!
Taking EBS Snapshots Tutorial
1. Sign in to your AWS account and open the AWS console.
2. Select Services in the top bar and click EC2 to launch the EC2 Management.
3. Select Running Instances and choose the instance you would like to back up.
4. In the bottom panel, you can look up technical information about the instance. In the Storage tab, find the Root device name and the volume ID it is attached to. Then select the /dev/sda1 link.
You will be redirected to the volume console.
7. Go onto the actions tab and select Create Snapshot. You will then be given the option to add a description for the snapshot to make it distinct from other snapshots, as well as assign tags to easily monitor this snapshot. Click Create Snapshot.
8. The snapshot creation process should start and be completed in a short amount of time.
After it is complete, you can find your new snapshot by selecting the Snapshots section and search for your snapshot with either the name or the description.
As you can see, we have successfully created a point-in-time WordPress copy of the EBS volume, which can later be used to restore your WordPress EC2 instance.
To create a new volume from the snapshot, you’ll need to select the snapshot of the backed up volume, press the Actions button above, and click Create Volume. Following the prompts, you’ll have more options to configure the volume details like below.
when complete, click Create Volume for the new volume to be created, which can later be added to another AWS EC2 instance of your choice.
Creating a WordPress Backup AMI Tutorial
To create a new AMI and ensure a successful WordPress backup, you should do the following:
1. Sign in to your AWS account and open the AWS console.
2. Select Services at the top and click EC2 to launch the EC2 Management console.
3. Select Running Instances and choose the WordPress instance you want to back up.
4. Go to Actions > Image > Create Image.
5. You will see Create Image. After selecting it, you can specify the image name, add the image description, enable/disable reboot after the AMI creation, and configure instance volumes.
***Note that when creating an EBS image, an EBS snapshot should also be created for each of the above volumes. You can access these snapshots like before by going to the Snapshots section.
Click Create Image at the bottom.
7. The image creation should now start. You will see it pending and then receive a notification to show that it has been created.
8. It should take a few minutes or the new AMI to be created. You can starting using it when its status switches from pending to available.
After it has been successfully created, it can then be used to create a new copy of your WordPress EC2 instance, which will be an exact copy of the original one.
To go and create this, go to the Instances section, click Launch Instance, select My AMIs section, type in the description of it and follow the prompts to finish the instance creation.
Automating WordPress Backup With AWS Backups Tutorial
To create a scheduled WordPress backup plan, take the following steps:
1. Sign in to your AWS account and open your AWS Management Console.
2. Select the Services in the top and then type AWS Backup in the search bar. Click Backup plans in the left pane.
3. Press the Create Backup plan button.
4. Here, you have three start options: Start with a template, Build a new plan, and Define a plan using JSON.
As we don’t have any existing backup plans yet, let’s use start with a template provided by AWS. Enter the backup plan name you want and proceed further.
5. In the middle you have Backup rules. You can click into DailyBackups to configure your backup schedule.
6. Select Customize backup window and choose your time of when you want the backup to happen.
7. Choose when you would like your backups to expire. You should choose the default vault as this is where all of your backups will be stored. After this, click complete.
8. Create a tag for your backup plan so that you can identify it. The click create plan.
9. You will taken to your plan page where you can assign resources to your backup plan. You can setup your plan to create WordPress backup from the resource’s tags or from the resource IDs.
I created tags for all my WordPress EC2 instances so that any resources I create in the future, I can automatically create a backup for it without manually entering the resource ID.
10. Backup Complete
You will see a scheduled backup that will copy all of your assigned resources into your vault.