Skip to content

Retrieve database backup from S3

In any restore scenario, you will need to retrieve the database backup file from S3 and load it to the database instance.

This can be accomplished either using AWS CLI directly on the database instance or manually downloading the file via the Amazon AWS Web portal and uploading it to the server via SCP protocol.

Option 1. Copy database backup from S3 to the Database instance using AWS CLI

Info

This will require AWS CLI, if the database instance has been replaced, this will need to be reinstalled. Those steps are listed earlier in this document.

Set AWS credentials

Using environmental variables, these values will be set for this session, but not be retained after the session is ended.

export AWS_ACCESS_KEY_ID=<AWS_ACCESS_KEY_ID>

export AWS_SECRET_ACCESS_KEY=<AWS_AC_KEY_ID>

Execute a copy command

aws s3 cp s3://{s3-bucket-name}/{filename} /path/to/destination

Let's break down those options.

  • aws s3 cp calls the aws cli utility and instructs it to copy a file from s3 bucket to local file path

  • s3://{s3-bucket-name} sets a source of the database backup file on S3 bucket.

  • /path/to/source - a destination path and file name of the restored database dump

Example

aws s3 cp
s3://miarec-db-backup/miarecdb-db.example.com-2022.08.17-21.05.24.backup/tmp/miarecdb.backup

Verification

The object will be moved to the defined path.

[centos@ip-172-31-63-218 ~]$ ls -l /tmp
total 28
...
-rw-rw-r--. 1 centos   centos    2142 Aug 24 17:59 miarecdb.backup

Option 2. Download a backup file from the Amazon AWS portal

The backup can be downloaded from the AWS S3 console and then transferred to the database instance using a utility like scp.

From Amazon S3 console at https://console.aws.amazon.com/s3/.

  1. Click the name of the Amazon S3 bucket where DB backups are stored.

    Select Bucket

  2. In the Object section, locate the corresponding backup file by looking at the timestamp.

    Locate Backup File

  3. Select Download from the item menu.

    Select Download

  4. The file will be downloaded to your current machine. Use an utility like scp to transfer the file to the server:

scp ~/miarecdb-db.example.com-2022.08.17-21.05.24.backup centos@x.x.x.x:/tmp/miarecdb.backup