Need help?

Our experts have had an average response time of 13.52 minutes in October 2021 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

AWS Backup: How to create AWS Backup plan with AWS CLI

by | Aug 20, 2021

Wondering how to create an AWS Backup plan with AWS CLI? We can help you with this!

As a part of our AWS Support Services, we often receive similar requests from our AWS customers.

Today, let’s see the steps followed by our Support Techs to help our customers to create an AWS Backup plan with AWS CLI.
 

Create AWS Backup plan with AWS CLI

 
A backup plan is a document that contains information that Backup uses to schedule tasks that create recovery points for resources.
Here, the AWS Backup plan is set up with a copy job configuration in the backup rule.

At first, we need to create a primary backup vault in the source AWS Region and the primary vault stores the source recovery points.

Then we need to create a secondary vault in the destination Region. The secondary vault stores the recovery points that AWS Backup creates as part of the copy configuration in the backup plan.

Now let’s see the steps to create an AWS Backup plan with AWS CLI:

  1. Firstly, we need to create a primary vault in the source region by running the create-backup-vault command.
aws backup create-backup-vault --backup-vault-name primary --region eu-west-1

2. Then we need to create a secondary vault in the destination region by running the command again.

aws backup create-backup-vault --backup-vault-name secondary --region eu-east-2

3. After that, we can create a JSON file with the options and parameters for the backup plan.

{
"BackupPlanName": "sampleplan",
"Rules": [{
"RuleName": "HalfDayBackups",
"TargetBackupVaultName": "primary",
"ScheduleExpression": "cron(0 5/12 ? * * *)",
"StartWindowMinutes": 480,
"CompletionWindowMinutes": 10080,
"Lifecycle": {
"DeleteAfterDays": 20
},
"CopyActions": [{
"DestinationBackupVaultArn": "arn:aws:backup:eu-west-2:987654321:backup-vault:secondary",
"Lifecycle": {
"DeleteAfterDays": 20
}
}]
}]
}

Here for the ScheduleExpression field, we need to set the value according to the recovery point objective of the organization and for the Lifecycle field, we can enter a value based on the retention policy of your backup.

4. Run the create-backup-plan command and then we need to pass the JSON file as an input parameter and note the value for BackupPlanId from the output of the command.

aws backup create-backup-plan --backup-plan file://

5. Then we need to create a JSON file that sets the parameters to assign the resources to the backup plan. To specify resources for a backup plan., we can use ARNs, tags, or both.

{
"SelectionName": "Myselection",
"IamRoleArn": "arn:aws:iam::987654321:role/service-role/AWSBackupDefaultServiceRole",
"Resources": ["arn:aws:ec2:eu-west-1:987654321:volume/vol-0abcdef9876"],
"ListOfTags": [{
"ConditionType": "STRINGEQUALS",
"ConditionKey": "backup",
"ConditionValue": "yes"
}]
}

6. Then run the create-backup-selection command and pass the JSON file as an input parameter:

aws backup create-backup-selection --backup-plan-id abcd-efgh-ijkl-mnop --backup-selection file://

Here for backup-plan-id, enter the value of BackupPlanId.
 

On-demand job on AWS Backup

 
We need to run the start-backup-job command to run an on-demand backup job.

aws backup start-backup-job --backup-vault-name primary --resource-arn arn:aws:ec2:eu-west-1:987654321:volume/vol-0abcdef1234 --iam-role-arn arn:aws:iam::987654321:role/service-role/AWSBackupDefaultServiceRole --idempotency-token 623f13d2-78d2-11ea-bc58-0252ac130009 --start-window-minutes 60 --complete-window-minutes 10080 --lifecycle DeleteAfterDays=30 --region eu-west-1

Here the value idempotency-token is a unique string that we provide to distinguish between StartBackupJob calls. We can generate a unique identifier by running the uuid command on Linux OS.

We need to run the start-copy-job command to run an on-demand copy job

aws backup start-copy-job --recovery-point-arn arn:aws:ec2:eu-west-1::snapshot/snap-0abcdaf2247b33dbc --source-backup-vault-name primary --destination-backup-vault-arn arn:aws:backup:eu-west-2:987654321:backup-vault:secondary --iam-role-arn arn:aws:iam::987654321:role/service-role/AWSBackupDefaultServiceRole --idempotency-token 5aac8974-78d2-11ea-bc55-0242ac130009 --lifecycle DeleteAfterDays=30 --region eu-west-1

Here the command runs a job that copies the recovery point from the source vault (primary) to a destination vault (secondary).

Run the start-restore-job command to start a restore job. We can use the following steps to start a restore job for an Amazon EBS volume.

 

  1. First, run the get-recovery-point-restore-metadata command on the recovery point and note the values for volume ID and encryption from the output of the command.
aws backup get-recovery-point-restore-metadata --backup-vault-name primary --recovery-point-arn arn:aws:ec2:eu-west-1::snapshot/snap-0abcdaf2247b33dbc

2. Then create a JSON file that sets the parameters for the required –metadata option of the start-restore-job command. For encrypted and volumeId, enter the values that we noted in step

{
"availabilityZone":"eu-west-1a",
"encrypted":"false",
"volumeId":"vol-0ck270d4c0b2e44c9",
"volumeSize":"100",
"volumeType":"gp2"
}

4. Then run the start-restore-job command and pass the JSON file as an input parameter:

aws backup start-restore-job --recovery-point-arn arn:aws:ec2:eu-west-1::snapshot/snap-0abcdaf2247b33dbc --metadata file:// --iam-role-arn arn:aws:iam::987654321:role/service-role/AWSBackupDefaultServiceRole --idempotency-token 52e602ce-78d2-11ea-bc55-0242ac130003 --resource-type EBS --region eu-west-1

[Need help with more AWS queries? We’d be happy to assist]
 

Conclusion

 
To conclude, today we discussed the steps followed by our Support Engineers to help our customers to create an AWS Backup plan with AWS CLI.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Reviews

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF