Scheduling an job to move the .bak file from AWS EC2 box to S3 using an simple script and Task Scheduler
Prerequisite: The EC2 Instance and the S3 bucket should have the same IAM role where it have access to S3 bucket and EC2 Instance.
On windows EC2 instance first want to configure the AWS CLI so that all the AWS command can be executed.
To download the AWS CLI package use this link
Based on your EC2 instance select the MSI package
One after the package downloads execute it with administrator privileges.
Click Next>
Accept the License Agreement
Click Next>
Provide the installation path
Click Next >
Click on Install>
It will ask UAC click yes>
Once the wizards completes, click Finish
Now we will create a batch file using AWS CLI commands
E: will be the backup path location, it will be considering as an directory
The backup will be copied to S3 with the current date folder name.
Give the region name properly, based on below
Region Name | Region |
US East (Ohio) | us-east-2 |
US East (N. Virginia) | us-east-1 |
US West (N. California) | us-west-1 |
US West (Oregon) | us-west-2 |
Asia Pacific (Mumbai) | ap-south-1 |
Asia Pacific (Osaka-Local) | ap-northeast-3 |
Asia Pacific (Seoul) | ap-northeast-2 |
Asia Pacific (Singapore) | ap-southeast-1 |
Asia Pacific (Sydney) | ap-southeast-2 |
Asia Pacific (Tokyo) | ap-northeast-1 |
Canada (Central) | ca-central-1 |
China (Beijing) | cn-north-1 |
China (Ningxia) | cn-northwest-1 |
EU (Frankfurt) | eu-central-1 |
EU (Ireland) | eu-west-1 |
EU (London) | eu-west-2 |
EU (Paris) | eu-west-3 |
EU (Stockholm) | eu-north-1 |
South America (São Paulo) | sa-east-1 |
AWS GovCloud (US-East) | us-gov-east-1 |
AWS GovCloud (US) | us-gov-west-1 |
Save the file with .bat extension
Go to start and type “Task Scheduler”
Select Task Scheduler
Right click and Select “Create New Task”
Give the Name of the task > Select the “Run whether user is logged on or not” and check the check box of “Run with highest privileges”
Go to Triggers Tab>click on New
Schedule the task as per your requirement
Click on Actions Tab> Click on New>
Select the Action As “Start a Program”
Give the Batch File path which is created Earlier > Click Ok
Select the Conditions Tab > Select the options as per your requirements
Select the Settings Tab > Select the options as per your requirements
Provide the User credentials who have access to that batch file and the log on as batch user permission
Just run the task to check if the .bak files are moving to S3 bucket or not.