Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ RUN apk update \
&& apk add --update \
postgresql-client \
mysql-client \
redis \
gnupg \
vim \
zip \
Expand Down
47 changes: 24 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ Simple docker image to facilitate backup creation, encryption & upload.

| Env var | default | possible values | description |
|---------------------------| --------------------| ----------------| ----------------------|
| BACKUP_COMPRESS | true | | compress backup files |
| BACKUP_COMPRESS_FORMAT | gz | gz, bz2, zip | compression format |
| BACKUP_ENCRYPT | false | | encrypt the backup files |
| BACKUP_ENCRYPT_KEY | | | valid pgp public key |
| BACKUP_ENCRYPT_RECIPIENT | | | email address associated with the public key |
| BACKUP_DB | false | | export and backup a database |
| BACKUP_DB_DRIVER | | mysql, postgres | database engine |
| BACKUP_DB_HOST | | | db hostname |
| BACKUP_DB_USER | | | db user |
| BACKUP_DB_PASSWORD | | | db password |
| BACKUP_DB_DATABASE | | | db name |
| BACKUP_DB_EXTRA_ARGS | | | extra args to provide to pg_dump/mysqldump |
| BACKUP_DATE_FORMAT | +%Y-%m-%d-%H:%M:%S" | `date` format | format to use for dates |
| BACKUP_PREFIX | {{DATE}}-" | | prefix to use for backup files |
| BACKUP_UPLOAD | false | | upload the backups somewhere |
| BACKUP_UPLOAD_METHOD | | gs, s3 | type of destination |
| BACKUP_UPLOAD_GS_KEY_FILE | | | path to gcloud key | |
| BACKUP_UPLOAD_GS_PATH | | | destination path (gs://bucket/subfolder/) |
| BACKUP_UPLOAD_S3_SECRET_ACCESS_KEY | | | secret key for S3 |
| BACKUP_UPLOAD_S3_ACCESS_KEY_ID | | | access key for S3 |
| BACKUP_UPLOAD_S3_REGION | | | AWS region for S3 |
| BACKUP_UPLOAD_S3_PATH | | | S3 path to store the backup into |
| BACKUP_UPLOAD_S3_ENDPOINT | "" | | S3 endpoint, __ONLY__ for not AWS |
| BACKUP_COMPRESS | true | | compress backup files |
| BACKUP_COMPRESS_FORMAT | gz | gz, bz2, zip | compression format |
| BACKUP_ENCRYPT | false | | encrypt the backup files |
| BACKUP_ENCRYPT_KEY | | | valid pgp public key |
| BACKUP_ENCRYPT_RECIPIENT | | | email address associated with the public key |
| BACKUP_DB | false | | export and backup a database |
| BACKUP_DB_DRIVER | | mysql, postgres, redis | database engine |
| BACKUP_DB_HOST | | | db hostname |
| BACKUP_DB_USER | | | db user; TODO for redis |
| BACKUP_DB_PASSWORD | | | db password; TODO for redis |
| BACKUP_DB_DATABASE | | | db name; TODO for redis |
| BACKUP_DB_EXTRA_ARGS | | | extra args to provide to pg_dump/mysqldump/redis-cli |
| BACKUP_DATE_FORMAT | +%Y-%m-%d-%H:%M:%S" | `date` format | format to use for dates |
| BACKUP_PREFIX | {{DATE}}-" | | prefix to use for backup files |
| BACKUP_UPLOAD | false | | upload the backups somewhere |
| BACKUP_UPLOAD_METHOD | | gs, s3 | type of destination |
| BACKUP_UPLOAD_GS_KEY_FILE | | | path to gcloud key | |
| BACKUP_UPLOAD_GS_PATH | | | destination path (gs://bucket/subfolder/) |
| BACKUP_UPLOAD_S3_SECRET_ACCESS_KEY | | | secret key for S3 |
| BACKUP_UPLOAD_S3_ACCESS_KEY_ID | | | access key for S3 |
| BACKUP_UPLOAD_S3_REGION | | | AWS region for S3 |
| BACKUP_UPLOAD_S3_PATH | | | S3 path to store the backup into |
| BACKUP_UPLOAD_S3_ENDPOINT | "" | | S3 endpoint, __ONLY__ for not AWS |

## Examples

Expand All @@ -39,3 +39,4 @@ See the [example folder](https://github.com/Quadrabee/k8s-backup/tree/master/exa
- add support for ftp, sftp
- add support for prometheus metrics publication
- add support for simple files/folders backup
- add support for redis-cli URI enabling authentication, DB selection and custom port as described in [Redis doc](https://redis.io/docs/connect/cli/#host-port-password-and-database)
13 changes: 13 additions & 0 deletions files/backup_scripts/db_backups_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ backup_db(){
backup_postgres
elif [ "$BACKUP_DB_DRIVER" == "mysql" ]; then
backup_mysql
elif [ "$BACKUP_DB_DRIVER" == "redis" ]; then
backup_redis
else
die "BACKUP_DB_DRIVER not set"
fi
}

backup_postgres(){
echo "Backuping postgres: $BACKUP_DB_USER@$BACKUP_DB_HOST/$BACKUP_DB_DATABASE"
check_db_params
export PGPASSWORD="$BACKUP_DB_PASSWORD"
pg_dump -U "$BACKUP_DB_USER" \
Expand All @@ -51,3 +54,13 @@ backup_mysql(){

handle_backup_file /tmp/db-backup.sql
}

backup_redis(){
echo "Backuping redis: $BACKUP_DB_HOST"
redis-cli \
-h "$BACKUP_DB_HOST" \
$BACKUP_DB_EXTRA_ARGS \
--rdb /tmp/redis.rdb

handle_backup_file /tmp/redis.rdb
}