For the complete documentation index, see llms.txt. This page is also available as Markdown.

Uploading Backups to AWS S3

This tutorial shows how to use the AWS Command Line Interface (CLI) to access Amazon S3, so that you can build your own scripts to back up your database backup files to the cloud and retrieve them as needed.

Use it together with Scheduled Database Backup: configure the tbdbbackup script first, then add a cron job that pushes the generated files to your S3 bucket.

Create an AWS IAM User

In this step, you create a user account that the AWS CLI uses to access AWS services.

Security note: the steps below attach the AdministratorAccess policy, as in the original procedure. For a backup uploader, attach a least-privilege policy scoped to your bucket instead (s3:PutObject and s3:ListBucket, plus s3:GetObject if you also restore from the CLI).

  1. Log in to the AWS Management Console, type IAM in the search bar and select IAM to open the Identity and Access Management dashboard.

  1. From the AWS Identity and Access Management dashboard, click Users on the left side.

  1. Click the Add user button.

  1. Enter a user name in the textbox next to User name (this example uses AWS_Admin) and select Programmatic access in the Select AWS Access Type section. Click Next: Permissions.

  1. Click Attach existing policies directly, select the policy to grant, then click Next: Review.

  1. Click Create user.

  1. Click the Download Credentials button and save the credentials.csv file in a safe location - you need it in the next section - then click Close.

Install and Configure the AWS CLI

Now that the IAM user exists, install the AWS Command Line Interface (CLI).

  1. Install the latest version of the AWS CLI:

  1. Confirm the installation:

  1. Type aws configure and press enter. Enter the following when prompted:

Using the AWS CLI with Amazon S3

In this step, you 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 one you want to use. To create a new bucket named my-first-backup-bucket:

Note: bucket names must be globally unique across all AWS accounts, so the command above returns a BucketAlreadyExists error as-is. Choose your own bucket name.

  1. To upload a backup file to the bucket, use the following command. Quote the path if the file name contains spaces:

  1. To download a file from S3 to the local directory, reverse the order of the arguments:

  1. To delete a file from the bucket:

Automating the Upload

Add a cron job that runs after tbdbbackup and copies the newly generated files to your bucket. For a script example of automatic and scheduled uploads, see Uploading to S3 in 18 lines of Shell.

Was this helpful?