dynamodump

repository·master·Indexed 21 days ago

https://github.com/bchew/dynamodump

A backup and restore utility for Amazon DynamoDB and local DynamoDB instances, designed to function similarly to mysqldump. It supports backing up, restoring, and emptying tables using wildcards, AWS tags, or specific table names. Features include S3 integration, compressed archives (zip/tar), schema-only or data-only operations, and support for local development via Docker.

Tokens
1.6K
Snippets
6
Records
6
Agent score
25%

What's inside dynamodump

  1. Backup and restore DynamoDB tables in AWS

    master

    Use the following patterns for common AWS DynamoDB tasks.

    Single table backup/restore:

    dynamodump -m backup -r us-west-1 -s testTable
    dynamodump -m restore -r us-west-1 -s testTable

    Multiple tables using wildcards (e.g., prefix 'production-'):

    dynamodump -m backup -r us-west-1 -s production*
    dynamodump -m restore -r us-west-1 -s production*

    Transferring between environments (e.g., production to development):

    dynamodump -m backup -r us-west-1 -s production*
    dynamodump -m restore -r us-west-1 -s production* -d development*

    Backup all tables and restore data only (preserving schema):

    dynamodump -m backup -r us-west-1 -s "*"
    dynamodump -m restore -r us-west-1 -s "*" --dataOnly

    Schema-only operations (e.g., creating blank tables in a new account):

    dynamodump -m backup -r us-west-1 -p source_credentials -s "*" --schemaOnly
    dynamodump -m restore -r us-west-1 -p destination_credentials -s "*" --schemaOnly

    Backup based on AWS tags:

    dynamodump -p profile -r us-east-1 -m backup -t KEY=VALUE

    Compress and store backups in S3:

    dynamodump -p profile -r us-east-1 -m backup -a tar -b some_s3_bucket -t TAG_KEY=TAG_VALUE

    Restore a specific archive from S3: Note: The -s flag identifies the specific archive file name within the S3 bucket.

    dynamodump -a tar -b some_s3_bucket -m restore -r us-east-1 -p profile -d destination_table -s source_table
    # See individual examples in the content section
  2. Use dynamodump via Docker

    master

    You can run dynamodump using Docker containers. The images are available on Docker Hub, Amazon ECR Public, and GitHub Packages.

    To view the help menu via Docker:

    docker run --rm -it bchew/dynamodump -h

    Container Registries:

    • Docker Hub: bchew/dynamodump
    • Amazon ECR Public: public.ecr.aws/bchew/dynamodump
    • GitHub Packages: ghcr.io/bchew/dynamodump
  3. Install dynamodump

    master

    Install dynamodump using pip to use it as a Python CLI tool for backing up, restoring, or emptying DynamoDB tables.

    pip install dynamodump
  4. Backup and restore with local DynamoDB

    master

    To use dynamodump with a local DynamoDB instance (e.g., running on localhost:8000), you must provide the --host, --port, --accessKey, and --secretKey parameters.

    Single table backup/restore (local):

    dynamodump -m backup -r local -s testTable --host localhost --port 8000 --accessKey a --secretKey a
    dynamodump -m restore -r local -s testTable --host localhost --port 8000 --accessKey a --secretKey a
    dynamodump -m backup -r local -s testTable --host localhost --port 8000 --accessKey a --secretKey a
  5. Run DynamoDB Local via Docker Compose

    master

    You can use the provided docker-compose.yml to spin up a local instance of DynamoDB for development or testing. This configuration uses the amazon/dynamodb-local:latest image and exposes the service on port 8000.

    version: '3.8'
    services:
      dynamodb-local:
        command: "-jar DynamoDBLocal.jar -sharedDb -inMemory"
        image: "amazon/dynamodb-local:latest"
        container_name: dynamodb-local
        ports:
          - "8000:8000"
  6. Configure dynamodump CLI options

    master

    The dynamodump CLI supports several modes and configuration options for managing DynamoDB backups and restores.

    Core Modes (-m, --mode):

    • backup: Back up tables.
    • restore: Restore tables.
    • empty: Empty tables.

    Table Selection:

    • -s SRCTABLE, --srcTable: Source table name. Supports wildcards (e.g., tablename*) or * for all tables. Mutually exclusive with --tag.
    • -d DESTTABLE, --destTable: Destination table name. Defaults to the source name. Supports wildcards.
    • -t TAG, --tag: Use an AWS tag to identify tables (format KEY=VALUE). Mutually exclusive with --srcTable.
    • --prefixSeparator: Specify a custom prefix separator (e.g., .).
    • --noSeparator: Disable prefix separator for wildcard searches.

    AWS & Connectivity:

    • -r REGION, --region: AWS region (e.g., us-west-1).
    • -p PROFILE, --profile: AWS credentials profile.
    • --accessKey / --secretKey: Required for local DynamoDB testing.
    • --host / --port: Required for local DynamoDB testing.

    Backup/Restore Behavior:

    • -a {zip,tar}, --archive: Create a compressed archive (zip or tar). If unset, no archive is created.
    • -b BUCKET, --bucket: S3 bucket for storage/retrieval (must already exist).
    • --schemaOnly: Backup/restore schema only, no data.
    • --dataOnly: Restore data only (does not delete/recreate schema).
    • --noConfirm: Required for unattended restores involving deletions.
    • --dumpPath: Directory for backups (defaults to dump).
    • --billingMode: Set to PROVISIONED or PAY_PER_REQUEST.
    • --readCapacity / --writeCapacity: Temporarily change throughput during operations.
    • --limit: Stop backup after a specific number of items.
    • -f FILTEROPTION: JSON file containing FilterExpression, ExpressionAttributeNames, and ExpressionAttributeValues for filtered backups.
    usage: dynamodump.py [-h] [-a {zip,tar}] [-b BUCKET] [-m {backup,restore,empty}] [-r REGION] [--host HOST] [--port PORT] [--accessKey ACCESSKEY] [--secretKey SECRETKEY] [-p PROFILE] [-s SRCTABLE] [-d DESTTABLE]
                         [--prefixSeparator PREFIXSEPARATOR] [--noSeparator] [--readCapacity READCAPACITY] [-t TAG] [--writeCapacity WRITECAPACITY] [--schemaOnly] [--dataOnly] [--noConfirm] [--skipThroughputUpdate]
                         [--dumpPath DUMPPATH] [--billingMode {PROVISIONED,PAY_PER_REQUEST}] [--log LOG] [--limit LIMIT] [-f FILTEROPTION]