Magento Server Automated snapshots Backup for EC2

How to take automated backups for Magento.

Magento Server Automated snapshots Backup for EC2

August 8, 2018 / Nirav Shah

Magento on EC2

Magento itself provides inbuilt backup facility for its entire backup of application and database. You can setup a cron job for interval so it takes regular backup.

This blog is about what if you want to take a backup of your EC2 instance which is responsible to run you Magento core, so when you want to upgrade your server or want to take entire Ec2 backup regular interval to make your environment safe, this step by step process is very much helpful.

Mechanism

Amazon has not yet presented managed automated backups in EC2 service. It is only available in RDS service. But using CloudWatch Events we can configure automated snapshots for our EC2 volumes using Lamda functions or by calling EC2 CreateSnapshot API on our behalf. If you have database server on RDS you do not have to worry about databse backup as RDS has its own setup for backup.

  • AWS CloudWatch is monitoring service and we will use its sub service – Events.
  • We will configure rules in CloudWatch Events to take snapshots by calling EC2 CreateSnaphot API with IAM role.
  • Events will take Snapshot for desired volume id and then the Snapshot will be stored into S3.
  • After the Snapshot process ends Events will trigger SNS topic to send notification about operation to SNS topic subscribers.

Cloudwatch

Amazon CloudWatch is a monitoring service for AWS cloud resources and the applications running on it. CloudWatch helps you to collect and track metrics for your AWS resources.

You can configure alarm to help you react when changes happen to your resources. For example, you can create a alarm when your Magento EC2 instance is utilizing more CPU than the normal usage limit.

You can do more than creating alarm by leveraging the CloudWatch Events feature. In this tutorial, we are going to see the one such use case of CloudWatch Events where you can automate the EBS (Elastic Block Storage) snapshots creation.

Create a SNS Topic

A topic is a communication channel to send messages and subscribe to notifications. It provides an access point for publishers and subscribers to communicate with each other. In this section you create a topic named MyTopic.

To create a topic

  1. In the Amazon SNS console, click Create topic.
  2. The Create topic dialog box appears.
  3. In the Topic name box, type a topic name.
  4. Click Create topic.
  5. The new topic appears in the Topics page.
  6. Select the new topic and then click the topic ARN.
  7. Copy the topic ARN for the next task.

Topic Subscription

To receive messages published to a topic, you have to subscribe an endpoint to that topic. An endpoint is a mobile app, web server, email address, or an Amazon SQS queue that can receive notification messages from Amazon SNS. Once you subscribe an endpoint to a topic and the subscription is confirmed, the endpoint will receive all messages published to that topic.

To subscribe to a topic

  1. Open the Amazon SNS console at https://console.aws.amazon.com/sns/v2/home.
  2. Click Create subscription.
  3. The Create Subscription dialog box appears.
  4. In the Topic ARN field, paste the topic ARN you created in the previous task, for example:arn:aws:sns:us-west-2:111122223333:MyTopic.
  5. In the Protocol drop-down box, select Email.
  6. In the Endpoint box, type an email address you can use to receive the notification.
  7. Click Create subscription.
  8. Go to your email application and open the message from AWS Notifications, and then click the link to confirm your subscription.
  9. Your web browser displays a confirmation response from Amazon SNS.

Now you have created a SNS topic and confirmed email address of end point. You will need this SNS topic to get alerts on automated backup status. In next steps you will learn how to take automated backups for Magento EC2 volumes.

Schedule Automated Snapshots for Magento EC2

  1. Open the Cloudwatch console at https://eu-central-1.console.aws.amazon.com/cloudwatch.
  2. Click on Events.
  3. Click on Create rule to create a rule into events.
  4. Select Event Pattern in Event Source section.
  5. In Service Name parameter select EC2 using drop down menu.
  6. In Event Type parameter, select EBS Snapshot Notification from drop down menu.
  7. Leave everything as default in rest of settings in Event Source section.
  8. Click on Add Target in Targets section.
  9. Select SNS topic from drop down menu.
  10. In Topic parameter select the topic you have created for notifications.
  11. Click Configure Details at the bottom of the page.
  12. Give a name of rule.
  13. Write description about the rule.
  14. Check to enable.
  15. Finally click on Create rule to finish.

You have created an notification alert whenever any snapshot will be created. This will help us to know the status of the snapshot into subscriber’s email.

Now create new rule into events to create snapshots automatically in every fix rate of time (Example – Minute, Hours, Days)

  1. Open the Cloudwatch console at https://eu-central-1.console.aws.amazon.com/cloudwatch
  2. Click on Events.
  3. Click on Create rule to create a rule into events.
  4. Select Schedule in Event Source section.
  5. In Fix rate of parameter select Days using drop down menu and enter desired period of days.
  6. Click on Add Target in Targets section.
  7. Select EC2 CreateSnapshot API Call from drop down menu.
  8. In Volume ID parameter, enter the volume id for which you want to schedule automated snapshots.
  9. Select Create a new role for this specific resource.
  10. Click Configure Details at the bottom of the page.
  11. Give a name of rule.
  12. Write description about the rule.
  13. Check to enable.

Congratulations now you have successfully set up automated snapshots for your Magento EC2 EBS volumes with SNS Notifications using CloudWatch Events.

Talk to AWS Certified Consultant

    Spread Love By Sharing:

    Let’s Talk About Your Needed AWS Infrastructure Management Services

    Have queries about your project idea or concept? Please drop in your project details to discuss with our AWS Global Cloud Infrastructure service specialists and consultants.

    • Swift Hiring and Onboarding
    • Experienced and Trained AWS Team
    • Quality Consulting and Programming
    Let’s Connect and Discuss Your Project