Skip to content

Upload DB dump to AWS S3

Maksym Zaporozhets edited this page Jun 19, 2023 · 3 revisions

docker:mysql:upload-to-aws

Upload database dump and metadata file to AWS S3.

Description

This command requires a Docker container name to create a MySQL metadata file. A metadata file is later used to run similar DB container, import dump, commit and push the image to the registry.

Usage

Simple usage:

php bin/dockerizer docker:mysql:upload-to-aws -c <container>

Extended example:

php bin/dockerizer d:m:upload -c awesome-project-com-prod_mysql_1 \
  -t registry.gitlab.com/acme/awesome-project/database-dev \
  -b custom-amce-owned-bucket

Dump DB from container awesome-project-com-prod_mysql_1 and push it to the bucket custom-amce-owned-bucket:

  • Dump S3 URI s3://custom-amce-owned-bucket/acme/awesome-project/database-dev.sql.gz
  • Metadata S3 URI s3://custom-amce-owned-bucket/acme/awesome-project/database-dev.json

Command arguments and options

  • -c (--container, required): Container name or ID.
  • -d (--dump, optional): Path to the existing dump. It must be a .gz archive. Leave empty to create a dump from a running Docker container.
  • -t (--target-image, optional): Docker image name including registry domain (if needed) and excluding tags. If not specified, the command will ask for it interactively.
  • -b (--bucket, optional): AWS S3 Bucket to upload data. Ignores environment variable DOCKERIZER_AWS_S3_BUCKET_PREFIX.

@TODO: add the ability to pass the AWS S3 region. Currently, it is ony taken from the DOCKERIZER_AWS_S3_REGION env variable.

Required and optional environment variables

  • AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY (required): upload files to the S3 bucket
  • DOCKERIZER_AWS_S3_REGION (required): AWS S3 region to upload files to.
  • DOCKERIZER_AWS_S3_BUCKET_PREFIX (optional): AWS S3 bucket prefix.

There are two ways to supply AWS S3 bucket name:

  • Explicitly pass it via the --bucket option
  • Implicitly: DOCKERIZER_AWS_S3_BUCKET_PREFIX + Docker image namespace.

For example, if your target image name is my-docker-registry.com:5000/namespace/repository/database-dev then the bucket name will be: DOCKERIZER_AWS_S3_BUCKET_PREFIX + namespace. This is convenient in case all your team buckets are prefixed similarly. In this case, a convention prefix + project namespace works great, and developers don't need to ask for the bucket name every time.

In the extended example above, we can set DOCKERIZER_AWS_S3_BUCKET_PREFIX=default-value-php-dept- and skip passing the -b option. In such a case, the bucket name will be default-value-php-dept-acme by the convention described above.

Executes other commands

Called from other commands

Clone this wiki locally