FreeSBC:Uploading backups to AWS S3
In this tutorial, we are going to help you use the AWS Command Line Interface (CLI) to access Amazon S3. We will do this so you can easily build your own scripts for backing up your files to the cloud and easily retrieve them as needed.
Create an AWS IAM User
In this step, using the IAM service you will create a user account with administrative permission. In later steps, you will use this user account to securely access AWS services using the AWS CLI.
1. Please login to the AWS management console with your user name and password. Then type IAM in the search bar and select IAM to open the Identity and Access Management dashboard.
2. From the AWS Identity and Access Management dashboard, click on Users on the left side.
3. Click the Add user button.
4. Enter a user name in the textbox next to User name: (we’ll use AWS_Admin for this example) and select Programmatic access in the Select AWS Access Type section. Click the Next: Permissions button.
5. Click on Attach existing policies directly option. Select AdministratorAccess then click Next: Review.
6. Click on Create user.
7. Click the Download Credentials button and save the credentials.csv file in a safe location (you’ll need this later) and then click the Close button.
Install and Configure the AWS CLI
Now that you have your IAM user, you need to install the AWS Command Line Interface (CLI).
1. For the latest version of the AWS CLI, use the following command block:
$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
2. Confirm the installation.
aws --version aws-cli/2.1.12 Python/3.7.3 Linux/3.10.0-1127.18.2.el7.tb.x86_64 exe/x86_64.centos.7 prompt/off
3. Type aws configure and press enter. Enter the following when prompted:
AWS Access Key ID [None]: enter the Access Key Id from the credentials.csv file you downloaded in the Create an AWS IAM User part Note: this should look something like AKIAPWINCOKAO3U4FWTN AWS Secret Access Key [None]: enter the Secret Access Key from the credentials.csv file you downloaded in the Create an AWS IAM User part Note: this should look something like 5dqQFBaGuPNf5z7NhFrgou4V5JJNaWPy1XFzBfX3 Default region name [None]: enter us-east-1 Default output format [None]: enter json
Using the AWS CLI with Amazon S3
In this step, you will use the AWS CLI to create a bucket in S3 and copy a file to the bucket.
1. Creating a bucket is optional if you already have a bucket created that you want to use. To create a new bucket named my-first-backup-bucket type:
aws s3 mb s3://my-first-backup-bucket
Note: bucket naming has some restrictions; one of those restrictions is that bucket names must be globally unique (e.g. two different AWS users can not have the same bucket name); because of this, if you try the command above you will get a BucketAlreadyExists error.
2. To upload the file my first backup.bak located in the local directory (C:\users) to the S3 bucket my-first-backup-bucket, you would use the following command:
aws s3 cp “C:\users\my first backup.bak” s3://my-first-backup-bucket/
Or, use the original syntax if the filename contains no spaces.
3. To download my-first-backup.bak from S3 to the local directory we would reverse the order of the commands as follows:
aws s3 cp s3://my-first-backup-bucket/my-first-backup.bak ./
4. To delete my-first-backup.bak from your my-first-backup-bucket bucket, use the following command:
aws s3 rm s3://my-first-backup-bucket/my-first-backup.bak
5. You can find script examples for automatic and scheduling uploads. Please check the following link;