diff --git a/README.md b/README.md index 1735c35..94c18c9 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Docker image to backup Postgres database(s) to S3 using pg_dump and compress usi - [x] PGP encryption - [x] Available `COMPRESS=` methods: pigz, xz, bzip2, lrzip, brotli, zstd - [x] Ping database before backup +- [x] Github Actions CI/CD - [ ] TODO: Add other dbs (e.g. postgres, mysql) - [ ] TODO: Separate definition of HOST, PORT, USERNAME, PASSWORD environment variables as an alternative to PG_URI @@ -31,6 +32,29 @@ COMPRESS_LEVEL=7 # Compression level of desired compression program Or see `docker-compose.yml` file to run this container with Docker. +## Github Actions +```yaml +name: Backup database +on: + schedule: + - cron: '0 15 * * *' + workflow_dispatch: {} + +jobs: + backup-prod: + runs-on: ubuntu-latest + steps: + - name: Create backup + uses: BackupTools/postgres-backup-s3@master + with: + s3_buck: 'backups' # s3 bucket name + s3_name: 'service-name/db-name' # optionally nested path to store backups + s3_uri: '${{ secrets.BACKUP_S3_URI }}' # https://s3-key:s3-secret@s3.host.tld + pg_uri: '${{ secrets.BACKUP_READONLY_URI }}' # postgres://readonly:super-secret@db:5432/postgres + compress: pigz # Available: pigz, xz, bzip2, lrzip, brotli, zstd + +``` + ## Cron backup with kubernetes See `kubernetes-cronjob.yml` file. diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..ba22362 --- /dev/null +++ b/action.yml @@ -0,0 +1,36 @@ +name: "Backup postgres to S3" +description: "Backup postgres to S3 bucket with encryption and compression" +author: JargeZ +branding: + icon: "save" + color: "orange" +runs: + using: "docker" + image: "Dockerfile" +inputs: + gpg_keyserver: + description: "your hpks keyserver" + default: "keyserver.ubuntu.com" + gpg_keyid: + description: "recipient key, backup will be encrypted if added" + compress: + description: "Available: pigz, xz, bzip2, lrzip, brotli, zstd" + default: "pigz" + compress_level: + description: "Compression level of desired compression program" + default: "9" + maintenance_db: + description: + default: "postgres" + s3_uri: + description: "URI of S3 bucket. eg: https://s3-key:s3-secret@s3.host.tld" + required: true + s3_buck: + description: "S3 bucket name. eg: postgres1-backups" + required: true + s3_name: + description: "S3 path to store backups. eg: backups/db1" + required: true + pg_uri: + description: "Postgres URI. eg: postgres://readonly:super-secret@db:5432/postgres" + required: true \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index ffbdb52..16d816b 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -8,11 +8,15 @@ get_date () { } # Script -: ${GPG_KEYSERVER:='keyserver.ubuntu.com'} -: ${GPG_KEYID:=''} -: ${COMPRESS:='pigz'} -: ${COMPRESS_LEVEL:='9'} -: ${MAINTENANCE_DB:='postgres'} +: ${GPG_KEYSERVER:=${INPUT_GPG_KEYSERVER:='keyserver.ubuntu.com'}} +: ${GPG_KEYID:=${INPUT_GPG_KEYID:=''}} +: ${COMPRESS:=${INPUT_COMPRESS:='pigz'}} +: ${COMPRESS_LEVEL:=${INPUT_COMPRESS_LEVEL:='9'}} +: ${MAINTENANCE_DB:=${INPUT_MAINTENANCE_DB:='postgres'}} +: ${S3_URI:=${INPUT_S3_URI:=''}} +: ${S3_BUCK:=${INPUT_S3_BUCK:=''}} +: ${S3_NAME:=${INPUT_S3_NAME:=''}} +: ${PG_URI:=${INPUT_PG_URI:=''}} START_DATE=`date +%Y-%m-%d_%H-%M-%S` if [ -z "$GPG_KEYID" ]