How to Backup AWS EC2 Instance to S3 Bucket in 3 Ways?

AWS EC2 instances can host your important business systems so you can backup the instances to S3 bucket to protect the data and ensure business continuity. See how to do that with command lines or GUI.

download-icon
Free Download
for VM, OS, DB, File, NAS, etc.
nick-zhao

Updated by Nick Zhao on 2024/05/30

Table of contents
  • Why backup EC2 instance to S3?

  • How to backup the EC2 instance to S3 bucket with bash script?

  • How to backup the snapshot of EC2 instance to S3 bucket?

  • How to backup EC2 instance to S3 via an easier way?

  • EC2 backup FAQs

  • Sum Up

Are you looking for a robust EC2 instance backup solution? Try Vinchin Backup & Recovery!↘ Download Free Trial

AWS is one of the leading cloud computing platforms in the world, providing scalable environments to all kinds of businesses. One of the major services provided by AWS is creating EC2 instances to host business systems. These instances can work like independent machines and are easier to create and manage.

Meanwhile, AWS also provides cloud storage, S3, for companies to conveniently store all kinds of dta. EC2 instances might store important production data so you can backup the EC2 instances to S3 to protect data.

Why backup EC2 instance to S3?

Better Protection: Many companies often lack dedicated IT admins for server maintenance. In such cases, cloud storage will be an excellent solution because AWS S3 is maintained by professional engineers, providing reliable data security assurance.

Less Cost: Compared with building an on-premise data center, using cloud storage like S3 will save much money in the early stage of a companies but as companies grow, on-premise data centers and cloud servers are often used together for evolving needs.

Easy Scalability: Unlike using local physical storage, AWS cloud can offer you nearly unlimited storage space so even if you haven’t invested in building storage infrastructure in advance, you still don’t have to worry about running out of storage due to business expansion in the future. Such flexible storage scalability is very friendly to all kinds of companies.

Unified Platform: Since EC2 instances and S3 buckets are in the same AWS platform and management console and AWS provides the internal backup solution the instance backup process and later management job will be very comfortable. In addition, the cost tracking is also simple, usually charging only storage fee.

How to backup the EC2 instance to S3 bucket with bash script?

You can configure the access of EC2 instance to S3 and then backup it to S3.

1. You need to configure the AWS CLI in the environment where the script will be executed. This includes creating user, installing AWS CLI, creating a role for EC2 instance to access S3.

2. Create S3 Bucket with the command below:

root@ip-172-31-47-132:~# aws s3 mb s3://myweb-backup
make_bucket: myweb-backup

3. Upload the file to /etc/passwd file to S3 bucket with the command below:

root@ip-172-31-47-132:~# aws s3 cp /etc/passwd s3://myweb-backup/
upload: ../../etc/passwd to s3://myweb-backup/passwd

If you need to download the password file to local server, you can use the command below:

root@ip-172-31-47-132:~# aws s3 cp s3://myweb-backup/passwd .
download: s3://myweb-backup/passwd to ./passwd

if you need to delete the password file, you can use the command below:

root@ip-172-31-47-132:~# aws s3 rm s3://myweb-backup/passwd
delete: s3://myweb-backup/passwd

4. Here is a practice to backup data in /ect

#!/bin/bash
export HOME="/home/ubuntu"
cd /tmp/;
tar -zcPf etc$(date +%Y%m%d).tar.gz /etc;
aws s3 cp etc$(date +%Y%m%d).tar.gz s3://myweb-backup/;
rm -f etc$(date +%Y%m%d).tar.gz;

To backup EC2 instance automatically, you can add a scheduled task for that.

How to backup the snapshot of EC2 instance to S3 bucket?

Snapshot is a solution to backup EC2 instance and you can also write a script of backing up EC2 snapshots to an S3 bucket.

1. Also, you need to preconfigure the environment to interact with AWS later

2. Get the EC2 instance list by ng AWS CLI or SDK, you can retrieve the list all current EC2 instances with the command below,

aws ec2 describe-instances

3. Create EC2 instance snapshot by using AWS CLI or SDK with the command below,

aws ec2 create-snapshot --volume-id <volume-id> --description "Backup"

<volume-id> is the ID of EC2 instance volume.

4. Copy the snapshot to S3 bucket by using AWS CLI or SDK with the command below,

aws s3 cp <snapshot-file> s3://<bucket-name>/<snapshot-file>

<snapshot-file> is the directory of the snapshot and <bucket-name> is the name of the target S3 bucket.

To run the backup job automatically, you can use AWS Lambda to add a scheduled task for it.

How to backup EC2 instance to S3 via an easier way?

The process of backing up EC2 instance to S3 with command is complicated. To make the procedures clear and easy, you can use a professional backup solution to protect EC2 instance.

Vinchin Backup & Recovery can let you backup EC2 instance to S3 bucket without complicated commands. In the user-friendly web console, you can add all instances in all regions under an account with its access key ID and add S3 storage with the related credentials. Then you can easily select the EC2 instances and configure the backup job with a wizard.

Except for scheduled backup, you can configure more backup strategies when creating the backup job, like incremental backup, throttling policy, data compression and deduplication, data encryption, etc.

You just need 4 steps to create the backup job.

1. Select the EC2 instance

Select EC2 instance

2. Select the S3 bucket as the backup storage

Select S3 as backup storage

3. Select the backup strategies

Select backup strategies

4. Submit the job

Submit the job

Vinchin Backup & Recovery has helped thousands of companies protect their production systems and it also supports mainstream virtualization platforms like VMware, Hyper-V, Proxmox, XenServer, XCP-ng, oVirt, OpenStack, etc. You can also start a 60-day full-featured free trial to protect your critical infrastructure. For any questions, you can contact our sales.

EC2 backup FAQs

1. How often should you backup your EC2 instance?

The frequency of backups depends on how important the instance is and companies often create full backups once a week and weekly backup once a day. If the instances are very important, you can use CDP to protect them in real-time.

2. Can you use snapshot to backup EC2 instance?

Of course, you can use snapshot like what did on VMware virtual machine to backup EC2 instance. Here is the guide to create EC2 snapshot.

3. Can you use AWS Backup to backup EC2 instance?

Yes, you can do that. AWS Backup can help you backup EC2 instance but the procedures will be more complicated than using Vinchin. Here is the guide to backup and restore EC2 instance with AWS Backup.

Sum Up

Both EC2 instance and S3 storage are the premium services provided by AWS. To protect critical business systems, you can backup EC2 instance to S3 with command lines or a professional backup software like Vinchin Backup & Recovery. Don’t miss the free trial.

Share on:

Categories: VM Backup