diff --git a/README.md b/README.md index aec0c61..b3ec5d1 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ GitHub Action to take a database dump from a platform.sh site and copy the dump platformsh_app: 'api' # optional. specify if the project has multiple apps. aws_s3_bucket: 'bucket-name' # required. db_dump_filename_base: 'sitename-db-dump' + dump_only_these_tables: 'table_name another_table_name' # optional. limit the tables being dumped, separate the table names with spaces. env: PLATFORMSH_CLI_TOKEN: ${{ secrets.PLATFORMSH_CLI_TOKEN }} # required. AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} # required. diff --git a/action.yml b/action.yml index 0ea5fcf..0f35ab0 100644 --- a/action.yml +++ b/action.yml @@ -22,6 +22,9 @@ inputs: description: 'Filename for the database dump. A timestamp will be appended after it.' required: false default: 'db-dump' + dump_only_these_tables: + description: 'Limit the dumped tables to this list, separated by spaces.' + required: false runs: using: 'docker' image: 'Dockerfile' diff --git a/entrypoint.sh b/entrypoint.sh index 4d8b12f..46f68ec 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -7,6 +7,15 @@ platform --version sed -i 's/# StrictHostKeyChecking ask.*/StrictHostKeyChecking accept-new/' /etc/ssh/ssh_config FILENAME="${INPUT_DB_DUMP_FILENAME_BASE}-$(date +%F-%T)" +# If we are not limiting the tables with INPUT_ONLY_INCLUDE_THESE_TABLES, then +# this will pass harmlessly as an empty string in the platform db:dump command. +DUMP_ONLY_THESE_TABLES="" +for table in ${INPUT_DUMP_ONLY_THESE_TABLES} +do + # Concatenate table options into string. + DUMP_ONLY_THESE_TABLES="${DUMP_ONLY_THESE_TABLES} --table=${table}" +done + # Check if neither optional relationship nor optional app value exists. if [ -z "${INPUT_PLATFORMSH_RELATIONSHIP}" ] && [ -z "${INPUT_PLATFORMSH_APP}" ] then @@ -26,7 +35,8 @@ else else # To get here we must have both --relationship and --app values available. # Run command with --relationship and --app parameters. - platform db:dump -v --yes --project "$INPUT_PLATFORMSH_PROJECT" --environment "$INPUT_PLATFORMSH_ENVIRONMENT" --relationship "$INPUT_PLATFORMSH_RELATIONSHIP" --app "$INPUT_PLATFORMSH_APP" --gzip -f "$FILENAME".sql.gz + # Also the optional DUMP_ONLY_THESE_TABLES argument limits to a subset of tables, but it may be empty. + platform db:dump -v --yes --project "$INPUT_PLATFORMSH_PROJECT" --environment "$INPUT_PLATFORMSH_ENVIRONMENT" --relationship "$INPUT_PLATFORMSH_RELATIONSHIP" --app "$INPUT_PLATFORMSH_APP" ${DUMP_ONLY_THESE_TABLES} --gzip -f "$FILENAME".sql.gz fi fi