From e6c8b0923d2063c97567547d82ce7909a4f553bb Mon Sep 17 00:00:00 2001 From: Jonas Kaninda Date: Sat, 10 Aug 2024 10:50:00 +0200 Subject: [PATCH 1/4] Add Docker entrypont, update docs --- Makefile | 20 +- README.md | 15 +- docker/Dockerfile | 3 +- docs/how-tos/backup-to-s3.md | 10 +- docs/how-tos/backup-to-ssh.md | 10 +- docs/how-tos/backup.md | 14 +- docs/how-tos/deploy-on-kubernetes.md | 240 +++++++++++++++++++ docs/how-tos/encrypt-backup.md | 5 +- docs/how-tos/restore-from-s3.md | 7 +- docs/how-tos/restore-from-ssh.md | 7 +- docs/how-tos/restore.md | 7 +- docs/index.md | 15 +- examples/docker-compose.s3.yaml | 5 +- examples/docker-compose.scheduled.local.yaml | 7 +- examples/docker-compose.scheduled.s3.yaml | 5 +- examples/docker-compose.yaml | 5 +- pkg/scripts.go | 2 +- 17 files changed, 290 insertions(+), 87 deletions(-) create mode 100644 docs/how-tos/deploy-on-kubernetes.md diff --git a/Makefile b/Makefile index ddabbf1..2433f0a 100644 --- a/Makefile +++ b/Makefile @@ -19,30 +19,30 @@ docker-build: docker build -f docker/Dockerfile -t jkaninda/mysql-bkup:latest . docker-run: docker-build - docker run --rm --network web --name mysql-bkup -v "./backup:/backup" -e "DB_HOST=${DB_HOST}" -e "DB_NAME=${DB_NAME}" -e "DB_USERNAME=${DB_USERNAME}" -e "DB_PASSWORD=${DB_PASSWORD}" -e "GPG_PASSPHRASE=${GPG_PASSPHRASE}" ${IMAGE_NAME} bkup backup --prune --keep-last 2 + docker run --rm --network web --name mysql-bkup -v "./backup:/backup" -e "DB_HOST=${DB_HOST}" -e "DB_NAME=${DB_NAME}" -e "DB_USERNAME=${DB_USERNAME}" -e "DB_PASSWORD=${DB_PASSWORD}" -e "GPG_PASSPHRASE=${GPG_PASSPHRASE}" ${IMAGE_NAME} backup --prune --keep-last 2 docker-restore: docker-build - docker run --rm --network web --name mysql-bkup -v "./backup:/backup" -e "DB_HOST=${DB_HOST}" -e "DB_NAME=${DB_NAME}" -e "DB_USERNAME=${DB_USERNAME}" -e "DB_PASSWORD=${DB_PASSWORD}" -e "GPG_PASSPHRASE=${GPG_PASSPHRASE}" ${IMAGE_NAME} bkup restore -f ${FILE_NAME} + docker run --rm --network web --name mysql-bkup -v "./backup:/backup" -e "DB_HOST=${DB_HOST}" -e "DB_NAME=${DB_NAME}" -e "DB_USERNAME=${DB_USERNAME}" -e "DB_PASSWORD=${DB_PASSWORD}" -e "GPG_PASSPHRASE=${GPG_PASSPHRASE}" ${IMAGE_NAME} restore -f ${FILE_NAME} docker-run-scheduled: #docker-build - docker run --rm --network web --name mysql-bkup -v "./backup:/backup" -e "DB_HOST=${DB_HOST}" -e "DB_NAME=${DB_NAME}" -e "DB_USERNAME=${DB_USERNAME}" -e "DB_PASSWORD=${DB_PASSWORD}" -e "GPG_PASSPHRASE=${GPG_PASSPHRASE}" ${IMAGE_NAME} bkup backup --mode scheduled --period "* * * * *" + docker run --rm --network web --name mysql-bkup -v "./backup:/backup" -e "DB_HOST=${DB_HOST}" -e "DB_NAME=${DB_NAME}" -e "DB_USERNAME=${DB_USERNAME}" -e "DB_PASSWORD=${DB_PASSWORD}" -e "GPG_PASSPHRASE=${GPG_PASSPHRASE}" ${IMAGE_NAME} backup --mode scheduled --period "* * * * *" -docker-run-scheduled-s3: #docker-build - docker run --rm --network web --name mysql-bkup -v "./backup:/backup" -e "DB_HOST=${DB_HOST}" -e "DB_NAME=${DB_NAME}" -e "DB_USERNAME=${DB_USERNAME}" -e "DB_PASSWORD=${DB_PASSWORD}" -e "ACCESS_KEY=${ACCESS_KEY}" -e "SECRET_KEY=${SECRET_KEY}" -e "BUCKET_NAME=${BUCKET_NAME}" -e "S3_ENDPOINT=${AWS_S3_ENDPOINT}" -e "GPG_PASSPHRASE=${GPG_PASSPHRASE}" ${IMAGE_NAME} bkup backup --storage s3 --mode scheduled --path /custom-path --period "* * * * *" +docker-run-scheduled-s3: docker-build + docker run --rm --network web --name mysql-bkup -v "./backup:/backup" -e "DB_HOST=${DB_HOST}" -e "DB_NAME=${DB_NAME}" -e "DB_USERNAME=${DB_USERNAME}" -e "DB_PASSWORD=${DB_PASSWORD}" -e "ACCESS_KEY=${ACCESS_KEY}" -e "SECRET_KEY=${SECRET_KEY}" -e "BUCKET_NAME=${BUCKET_NAME}" -e "S3_ENDPOINT=${AWS_S3_ENDPOINT}" -e "GPG_PASSPHRASE=${GPG_PASSPHRASE}" ${IMAGE_NAME} backup --storage s3 --mode scheduled --path /custom-path --period "* * * * *" docker-run-s3: docker-build - docker run --rm --network web --name mysql-bkup -e "DB_HOST=${DB_HOST}" -e "DB_NAME=${DB_NAME}" -e "DB_USERNAME=${DB_USERNAME}" -e "DB_PASSWORD=${DB_PASSWORD}" -e "ACCESS_KEY=${ACCESS_KEY}" -e "SECRET_KEY=${SECRET_KEY}" -e "AWS_S3_BUCKET_NAME=${AWS_S3_BUCKET_NAME}" -e "AWS_S3_ENDPOINT=${AWS_S3_ENDPOINT}" -e "AWS_REGION=eu2" -e "GPG_PASSPHRASE=${GPG_PASSPHRASE}" ${IMAGE_NAME} bkup backup --storage s3 --path /custom-path + docker run --rm --network web --name mysql-bkup -e "DB_HOST=${DB_HOST}" -e "DB_NAME=${DB_NAME}" -e "DB_USERNAME=${DB_USERNAME}" -e "DB_PASSWORD=${DB_PASSWORD}" -e "ACCESS_KEY=${ACCESS_KEY}" -e "SECRET_KEY=${SECRET_KEY}" -e "AWS_S3_BUCKET_NAME=${AWS_S3_BUCKET_NAME}" -e "AWS_S3_ENDPOINT=${AWS_S3_ENDPOINT}" -e "AWS_REGION=eu2" -e "GPG_PASSPHRASE=${GPG_PASSPHRASE}" ${IMAGE_NAME} backup --storage s3 --path /custom-path docker-restore-s3: docker-build - docker run --rm --network web --name mysql-bkup -e "DB_HOST=${DB_HOST}" -e "DB_NAME=${DB_NAME}" -e "DB_USERNAME=${DB_USERNAME}" -e "DB_PASSWORD=${DB_PASSWORD}" -e "ACCESS_KEY=${ACCESS_KEY}" -e "SECRET_KEY=${SECRET_KEY}" -e "BUCKET_NAME=${AWS_S3_BUCKET_NAME}" -e "S3_ENDPOINT=${AWS_S3_ENDPOINT}" -e "AWS_REGION=eu2" -e "GPG_PASSPHRASE=${GPG_PASSPHRASE}" ${IMAGE_NAME} bkup restore --storage s3 -f ${FILE_NAME} --path /custom-path + docker run --rm --network web --name mysql-bkup -e "DB_HOST=${DB_HOST}" -e "DB_NAME=${DB_NAME}" -e "DB_USERNAME=${DB_USERNAME}" -e "DB_PASSWORD=${DB_PASSWORD}" -e "ACCESS_KEY=${ACCESS_KEY}" -e "SECRET_KEY=${SECRET_KEY}" -e "BUCKET_NAME=${AWS_S3_BUCKET_NAME}" -e "S3_ENDPOINT=${AWS_S3_ENDPOINT}" -e "AWS_REGION=eu2" -e "GPG_PASSPHRASE=${GPG_PASSPHRASE}" ${IMAGE_NAME} restore --storage s3 -f ${FILE_NAME} --path /custom-path -docker-run-ssh: #docker-build - docker run --rm --network web --name mysql-bkup -e "DB_HOST=${DB_HOST}" -e "DB_NAME=${DB_NAME}" -e "DB_USERNAME=${DB_USERNAME}" -e "DB_PASSWORD=${DB_PASSWORD}" -e "SSH_USER=${SSH_USER}" -e "SSH_HOST_NAME=${SSH_HOST_NAME}" -e "SSH_REMOTE_PATH=${SSH_REMOTE_PATH}" -e "SSH_PASSWORD=${SSH_PASSWORD}" -e "SSH_PORT=${SSH_PORT}" -e "SSH_IDENTIFY_FILE=${SSH_IDENTIFY_FILE}" -e "GPG_PASSPHRASE=${GPG_PASSPHRASE}" ${IMAGE_NAME} bkup backup --storage ssh +docker-run-ssh: docker-build + docker run --rm --network web --name mysql-bkup -e "DB_HOST=${DB_HOST}" -e "DB_NAME=${DB_NAME}" -e "DB_USERNAME=${DB_USERNAME}" -e "DB_PASSWORD=${DB_PASSWORD}" -e "SSH_USER=${SSH_USER}" -e "SSH_HOST_NAME=${SSH_HOST_NAME}" -e "SSH_REMOTE_PATH=${SSH_REMOTE_PATH}" -e "SSH_PASSWORD=${SSH_PASSWORD}" -e "SSH_PORT=${SSH_PORT}" -e "SSH_IDENTIFY_FILE=${SSH_IDENTIFY_FILE}" -e "GPG_PASSPHRASE=${GPG_PASSPHRASE}" ${IMAGE_NAME} backup --storage ssh docker-restore-ssh: docker-build - docker run --rm --network web --name mysql-bkup -e "DB_HOST=${DB_HOST}" -e "DB_NAME=${DB_NAME}" -e "DB_USERNAME=${DB_USERNAME}" -e "DB_PASSWORD=${DB_PASSWORD}" -e "SSH_USER=${SSH_USER}" -e "SSH_HOST_NAME=${SSH_HOST_NAME}" -e "SSH_REMOTE_PATH=${SSH_REMOTE_PATH}" -e "SSH_PASSWORD=${SSH_PASSWORD}" -e "SSH_PORT=${SSH_PORT}" -e "GPG_PASSPHRASE=${GPG_PASSPHRASE}" -e "SSH_IDENTIFY_FILE=${SSH_IDENTIFY_FILE}" ${IMAGE_NAME} bkup restore --storage ssh -f ${FILE_NAME} + docker run --rm --network web --name mysql-bkup -e "DB_HOST=${DB_HOST}" -e "DB_NAME=${DB_NAME}" -e "DB_USERNAME=${DB_USERNAME}" -e "DB_PASSWORD=${DB_PASSWORD}" -e "SSH_USER=${SSH_USER}" -e "SSH_HOST_NAME=${SSH_HOST_NAME}" -e "SSH_REMOTE_PATH=${SSH_REMOTE_PATH}" -e "SSH_PASSWORD=${SSH_PASSWORD}" -e "SSH_PORT=${SSH_PORT}" -e "GPG_PASSPHRASE=${GPG_PASSPHRASE}" -e "SSH_IDENTIFY_FILE=${SSH_IDENTIFY_FILE}" ${IMAGE_NAME} restore --storage ssh -f ${FILE_NAME} run-docs: cd docs && bundle exec jekyll serve -H 0.0.0.0 -t \ No newline at end of file diff --git a/README.md b/README.md index 608897a..a1a6abf 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # MySQL Backup -mysql-bkup is a Docker container image that can be used to backup and restore Postgres database. It supports local storage, AWS S3 or any S3 Alternatives for Object Storage, and SSH compatible storage. +MySQL Backup is a Docker container image that can be used to backup and restore MySQL database. It supports local storage, AWS S3 or any S3 Alternatives for Object Storage, and SSH compatible storage. It also supports __encrypting__ your backups using GPG. The [jkaninda/mysql-bkup](https://hub.docker.com/r/jkaninda/mysql-bkup) Docker image can be deployed on Docker, Docker Swarm and Kubernetes. @@ -13,6 +13,7 @@ It also supports __encrypting__ your backups using GPG. ![Docker Pulls](https://img.shields.io/docker/pulls/jkaninda/mysql-bkup?style=flat-square) - Docker +- Docker Swarm - Kubernetes ## Documentation is found at @@ -36,7 +37,7 @@ It also supports __encrypting__ your backups using GPG. ### Simple backup using Docker CLI -To run a one time backup, bind your local volume to `/backup` in the container and run the `mysql-bkup backup` command: +To run a one time backup, bind your local volume to `/backup` in the container and run the `backup` command: ```shell docker run --rm --network your_network_name \ @@ -44,7 +45,7 @@ To run a one time backup, bind your local volume to `/backup` in the container a -e "DB_HOST=dbhost" \ -e "DB_USERNAME=username" \ -e "DB_PASSWORD=password" \ - jkaninda/mysql-bkup mysql-bkup backup -d database_name + jkaninda/mysql-bkup backup -d database_name ``` Alternatively, pass a `--env-file` in order to use a full config as described below. @@ -98,6 +99,10 @@ spec: spec: containers: - name: mysql-bkup + # In production, it is advised to lock your image tag to a proper + # release version instead of using `latest`. + # Check https://github.com/jkaninda/mysql-bkup/releases + # for a list of available releases. image: jkaninda/mysql-bkup command: - /bin/sh @@ -135,8 +140,8 @@ This Docker image is published to both Docker Hub and the GitHub container regis Depending on your preferences and needs, you can reference both `jkaninda/mysql-bkup` as well as `ghcr.io/jkaninda/mysql-bkup`: ``` -docker pull jkaninda/mysql-bkup:v1.2.0 -docker pull ghcr.io/jkaninda/mysql-bkup:v1.2.0 +docker pull jkaninda/mysql-bkup +docker pull ghcr.io/jkaninda/mysql-bkup ``` Documentation references Docker Hub, but all examples will work using ghcr.io just as well. diff --git a/docker/Dockerfile b/docker/Dockerfile index c34fa43..61743a7 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -64,4 +64,5 @@ RUN ln -s /usr/local/bin/mysql-bkup /usr/local/bin/bkup ADD docker/supervisord.conf /etc/supervisor/supervisord.conf -WORKDIR $WORKDIR \ No newline at end of file +WORKDIR $WORKDIR +ENTRYPOINT ["/usr/local/bin/mysql-bkup"] diff --git a/docs/how-tos/backup-to-s3.md b/docs/how-tos/backup-to-s3.md index 6208332..6b0b7b8 100644 --- a/docs/how-tos/backup-to-s3.md +++ b/docs/how-tos/backup-to-s3.md @@ -22,10 +22,7 @@ services: # for a list of available releases. image: jkaninda/mysql-bkup container_name: mysql-bkup - command: - - /bin/sh - - -c - - mysql-bkup backup --storage s3 -d database --path /my-custom-path + command: backup --storage s3 -d database --path /my-custom-path environment: - DB_PORT=3306 - DB_HOST=mysql @@ -62,10 +59,7 @@ services: # for a list of available releases. image: jkaninda/mysql-bkup container_name: mysql-bkup - command: - - /bin/sh - - -c - - mysql-bkup backup --storage s3 -d my-database --mode scheduled --period "0 1 * * *" + command: backup --storage s3 -d my-database --mode scheduled --period "0 1 * * *" environment: - DB_PORT=3306 - DB_HOST=mysql diff --git a/docs/how-tos/backup-to-ssh.md b/docs/how-tos/backup-to-ssh.md index f8d4f80..863f661 100644 --- a/docs/how-tos/backup-to-ssh.md +++ b/docs/how-tos/backup-to-ssh.md @@ -23,10 +23,7 @@ services: # for a list of available releases. image: jkaninda/mysql-bkup container_name: mysql-bkup - command: - - /bin/sh - - -c - - mysql-bkup backup --storage remote -d database + command: backup --storage remote -d database volumes: - ./id_ed25519:/tmp/id_ed25519" environment: @@ -66,10 +63,7 @@ services: # for a list of available releases. image: jkaninda/mysql-bkup container_name: mysql-bkup - command: - - /bin/sh - - -c - - mysql-bkup backup -d database --storage ssh --mode scheduled --period "0 1 * * *" + command: backup -d database --storage ssh --mode scheduled --period "0 1 * * *" volumes: - ./id_ed25519:/tmp/id_ed25519" environment: diff --git a/docs/how-tos/backup.md b/docs/how-tos/backup.md index 9fbf3dd..1c7a7bb 100644 --- a/docs/how-tos/backup.md +++ b/docs/how-tos/backup.md @@ -7,7 +7,7 @@ nav_order: 1 # Backup database -To backup the database, you need to add `backup` subcommand to `mysql-bkup` or `bkup`. +To backup the database, you need to add `backup` command. {: .note } The default storage is local storage mounted to __/backup__. The backup is compressed by default using gzip. The flag __`disable-compression`__ can be used when you need to disable backup compression. @@ -27,10 +27,7 @@ services: # for a list of available releases. image: jkaninda/mysql-bkup container_name: mysql-bkup - command: - - /bin/sh - - -c - - mysql-bkup backup -d database + command: backup -d database volumes: - ./backup:/backup environment: @@ -54,7 +51,7 @@ networks: -e "DB_HOST=dbhost" \ -e "DB_USERNAME=username" \ -e "DB_PASSWORD=password" \ - jkaninda/mysql-bkup mysql-bkup backup -d database_name + jkaninda/mysql-bkup backup -d database_name ``` In case you need to use recurring backups, you can use `--mode scheduled` and specify the periodical backup time by adding `--period "0 1 * * *"` flag as described below. @@ -68,10 +65,7 @@ services: # for a list of available releases. image: jkaninda/mysql-bkup container_name: mysql-bkup - command: - - /bin/sh - - -c - - mysql-bkup backup -d database --mode scheduled --period "0 1 * * *" + command: backup -d database --mode scheduled --period "0 1 * * *" volumes: - ./backup:/backup environment: diff --git a/docs/how-tos/deploy-on-kubernetes.md b/docs/how-tos/deploy-on-kubernetes.md new file mode 100644 index 0000000..49185af --- /dev/null +++ b/docs/how-tos/deploy-on-kubernetes.md @@ -0,0 +1,240 @@ +--- +title: Deploy on Kubernetes +layout: default +parent: How Tos +nav_order: 8 +--- + +## Deploy on Kubernetes + +To deploy MySQL Backup on Kubernetes, you can use Job to backup or Restore your database. +For recurring backup you can use CronJob, you don't need to run it in scheduled mode. as described bellow. + +## Backup Job + +```yaml +apiVersion: batch/v1 +kind: Job +metadata: + name: backup +spec: + ttlSecondsAfterFinished: 100 + template: + spec: + containers: + - name: mysql-bkup + # In production, it is advised to lock your image tag to a proper + # release version instead of using `latest`. + # Check https://github.com/jkaninda/mysql-bkup/releases + # for a list of available releases. + image: jkaninda/mysql-bkup + command: + - bkup + - backup + - --storage + - ssh + - --disable-compression + resources: + limits: + memory: "128Mi" + cpu: "500m" + env: + - name: DB_PORT + value: "3306" + - name: DB_HOST + value: "" + - name: DB_NAME + value: "dbname" + - name: DB_USERNAME + value: "postgres" + # Please use secret! + - name: DB_PASSWORD + value: "" + - name: SSH_HOST_NAME + value: "xxx" + - name: SSH_PORT + value: "22" + - name: SSH_USER + value: "xxx" + - name: SSH_PASSWORD + value: "xxxx" + - name: SSH_REMOTE_PATH + value: "/home/toto/backup" + # Optional, required if you want to encrypt your backup + - name: GPG_PASSPHRASE + value: "xxxx" + restartPolicy: Never +``` + +## Restore Job + +```yaml +apiVersion: batch/v1 +kind: Job +metadata: + name: restore-job +spec: + ttlSecondsAfterFinished: 100 + template: + spec: + containers: + - name: mysql-bkup + # In production, it is advised to lock your image tag to a proper + # release version instead of using `latest`. + # Check https://github.com/jkaninda/mysql-bkup/releases + # for a list of available releases. + image: jkaninda/mysql-bkup + command: + - bkup + - restore + - --storage + - ssh + - --file store_20231219_022941.sql.gz + resources: + limits: + memory: "128Mi" + cpu: "500m" + env: + - name: DB_PORT + value: "3306" + - name: DB_HOST + value: "" + - name: DB_NAME + value: "dbname" + - name: DB_USERNAME + value: "postgres" + # Please use secret! + - name: DB_PASSWORD + value: "" + - name: SSH_HOST_NAME + value: "xxx" + - name: SSH_PORT + value: "22" + - name: SSH_USER + value: "xxx" + - name: SSH_PASSWORD + value: "xxxx" + - name: SSH_REMOTE_PATH + value: "/home/toto/backup" + # Optional, required if your backup was encrypted + #- name: GPG_PASSPHRASE + # value: "xxxx" + restartPolicy: Never +``` + +## Recurring backup + +```yaml +apiVersion: batch/v1 +kind: CronJob +metadata: + name: backup-job +spec: + schedule: "* * * * *" + jobTemplate: + spec: + template: + spec: + containers: + - name: mysql-bkup + image: jkaninda/mysql-bkup + command: + - bkup + - backup + - --storage + - ssh + - --disable-compression + resources: + limits: + memory: "128Mi" + cpu: "500m" + env: + - name: DB_PORT + value: "3306" + - name: DB_HOST + value: "" + - name: DB_NAME + value: "test" + - name: DB_USERNAME + value: "postgres" + # Please use secret! + - name: DB_PASSWORD + value: "" + - name: SSH_HOST_NAME + value: "192.168.1.16" + - name: SSH_PORT + value: "2222" + - name: SSH_USER + value: "jkaninda" + - name: SSH_REMOTE_PATH + value: "/config/backup" + - name: SSH_PASSWORD + value: "password" + # Optional, required if you want to encrypt your backup + #- name: GPG_PASSPHRASE + # value: "xxx" + restartPolicy: Never +``` + +## Kubernetes Rootless + + +```yaml +apiVersion: batch/v1 +kind: CronJob +metadata: + name: backup-job +spec: + schedule: "* * * * *" + jobTemplate: + spec: + template: + spec: + securityContext: + runAsUser: 1000 + runAsGroup: 3000 + fsGroup: 2000 + containers: + # In production, it is advised to lock your image tag to a proper + # release version instead of using `latest`. + # Check https://github.com/jkaninda/mysql-bkup/releases + # for a list of available releases. + - name: mysql-bkup + image: jkaninda/mysql-bkup + command: + - bkup + - backup + - --storage + - ssh + - --disable-compression + resources: + limits: + memory: "128Mi" + cpu: "500m" + env: + - name: DB_PORT + value: "3306" + - name: DB_HOST + value: "" + - name: DB_NAME + value: "test" + - name: DB_USERNAME + value: "postgres" + # Please use secret! + - name: DB_PASSWORD + value: "" + - name: SSH_HOST_NAME + value: "192.168.1.16" + - name: SSH_PORT + value: "2222" + - name: SSH_USER + value: "jkaninda" + - name: SSH_REMOTE_PATH + value: "/config/backup" + - name: SSH_PASSWORD + value: "password" + # Optional, required if you want to encrypt your backup + #- name: GPG_PASSPHRASE + # value: "xxx" + restartPolicy: OnFailure +``` diff --git a/docs/how-tos/encrypt-backup.md b/docs/how-tos/encrypt-backup.md index 1c3a4f4..a866de0 100644 --- a/docs/how-tos/encrypt-backup.md +++ b/docs/how-tos/encrypt-backup.md @@ -32,10 +32,7 @@ services: # for a list of available releases. image: jkaninda/mysql-bkup container_name: mysql-bkup - command: - - /bin/sh - - -c - - mysql-bkup backup -d database + command: backup -d database volumes: - ./backup:/backup environment: diff --git a/docs/how-tos/restore-from-s3.md b/docs/how-tos/restore-from-s3.md index 94cf509..16d6e4a 100644 --- a/docs/how-tos/restore-from-s3.md +++ b/docs/how-tos/restore-from-s3.md @@ -7,7 +7,7 @@ nav_order: 5 # Restore database from S3 storage -To restore the database, you need to add `restore` subcommand to `mysql-bkup` or `bkup` and specify the file to restore by adding `--file store_20231219_022941.sql.gz`. +To restore the database, you need to add `restore` command and specify the file to restore by adding `--file store_20231219_022941.sql.gz`. {: .note } It supports __.sql__ and __.sql.gz__ compressed file. @@ -23,10 +23,7 @@ services: # for a list of available releases. image: jkaninda/mysql-bkup container_name: mysql-bkup - command: - - /bin/sh - - -c - - mysql-bkup restore --storage s3 -d my-database -f store_20231219_022941.sql.gz --path /my-custom-path + command: restore --storage s3 -d my-database -f store_20231219_022941.sql.gz --path /my-custom-path volumes: - ./backup:/backup environment: diff --git a/docs/how-tos/restore-from-ssh.md b/docs/how-tos/restore-from-ssh.md index 661d481..7c789b5 100644 --- a/docs/how-tos/restore-from-ssh.md +++ b/docs/how-tos/restore-from-ssh.md @@ -6,7 +6,7 @@ nav_order: 6 --- # Restore database from SSH remote server -To restore the database from your remote server, you need to add `restore` subcommand to `mysql-bkup` or `bkup` and specify the file to restore by adding `--file store_20231219_022941.sql.gz`. +To restore the database from your remote server, you need to add `restore` command and specify the file to restore by adding `--file store_20231219_022941.sql.gz`. {: .note } It supports __.sql__ and __.sql.gz__ compressed file. @@ -22,10 +22,7 @@ services: # for a list of available releases. image: jkaninda/mysql-bkup container_name: mysql-bkup - command: - - /bin/sh - - -c - - mysql-bkup restore --storage ssh -d my-database -f store_20231219_022941.sql.gz --path /home/jkaninda/backups + command: restore --storage ssh -d my-database -f store_20231219_022941.sql.gz --path /home/jkaninda/backups volumes: - ./backup:/backup environment: diff --git a/docs/how-tos/restore.md b/docs/how-tos/restore.md index e0a8cb5..1244e61 100644 --- a/docs/how-tos/restore.md +++ b/docs/how-tos/restore.md @@ -7,7 +7,7 @@ nav_order: 4 # Restore database -To restore the database, you need to add `restore` subcommand to `mysql-bkup` or `bkup` and specify the file to restore by adding `--file store_20231219_022941.sql.gz`. +To restore the database, you need to add `restore` command and specify the file to restore by adding `--file store_20231219_022941.sql.gz`. {: .note } It supports __.sql__ and __.sql.gz__ compressed file. @@ -23,10 +23,7 @@ services: # for a list of available releases. image: jkaninda/mysql-bkup container_name: mysql-bkup - command: - - /bin/sh - - -c - - mysql-bkup restore -d database -f store_20231219_022941.sql.gz + command: restore -d database -f store_20231219_022941.sql.gz volumes: - ./backup:/backup environment: diff --git a/docs/index.md b/docs/index.md index 421e17d..2cb1620 100644 --- a/docs/index.md +++ b/docs/index.md @@ -6,7 +6,7 @@ nav_order: 1 # About mysql-bkup {:.no_toc} -mysql-bkup is a Docker container image that can be used to backup and restore MySQL database. It supports local storage, AWS S3 or any S3 Alternatives for Object Storage, and SSH compatible storage. +MySQL Backup is a Docker container image that can be used to backup and restore MySQL database. It supports local storage, AWS S3 or any S3 Alternatives for Object Storage, and SSH remote storage. It also supports __encrypting__ your backups using GPG. We are open to receiving stars, PRs, and issues! @@ -32,7 +32,7 @@ Code and documentation for `v1` version on [this branch][v1-branch]. ### Simple backup using Docker CLI -To run a one time backup, bind your local volume to `/backup` in the container and run the `mysql-bkup backup` command: +To run a one time backup, bind your local volume to `/backup` in the container and run the `backup` command: ```shell docker run --rm --network your_network_name \ @@ -40,7 +40,7 @@ To run a one time backup, bind your local volume to `/backup` in the container a -e "DB_HOST=dbhost" \ -e "DB_USERNAME=username" \ -e "DB_PASSWORD=password" \ - jkaninda/mysql-bkup mysql-bkup backup -d database_name + jkaninda/mysql-bkup backup -d database_name ``` Alternatively, pass a `--env-file` in order to use a full config as described below. @@ -56,10 +56,7 @@ services: # for a list of available releases. image: jkaninda/mysql-bkup container_name: mysql-bkup - command: - - /bin/sh - - -c - - mysql-bkup backup + command: backup volumes: - ./backup:/backup environment: @@ -81,8 +78,8 @@ This Docker image is published to both Docker Hub and the GitHub container regis Depending on your preferences and needs, you can reference both `jkaninda/mysql-bkup` as well as `ghcr.io/jkaninda/mysql-bkup`: ``` -docker pull jkaninda/mysql-bkup:v1.2.0 -docker pull ghcr.io/jkaninda/mysql-bkup:v1.2.0 +docker pull jkaninda/mysql-bkup +docker pull ghcr.io/jkaninda/mysql-bkup ``` Documentation references Docker Hub, but all examples will work using ghcr.io just as well. diff --git a/examples/docker-compose.s3.yaml b/examples/docker-compose.s3.yaml index 6567699..7791da5 100644 --- a/examples/docker-compose.s3.yaml +++ b/examples/docker-compose.s3.yaml @@ -6,10 +6,7 @@ services: # for a list of available releases. image: jkaninda/mysql-bkup container_name: mysql-bkup - command: - - /bin/sh - - -c - - mysql-bkup backup --storage s3 -d my-database" + command: backup --storage s3 -d my-database" environment: - DB_PORT=3306 - DB_HOST=mysql diff --git a/examples/docker-compose.scheduled.local.yaml b/examples/docker-compose.scheduled.local.yaml index 0503ea0..1ab1314 100644 --- a/examples/docker-compose.scheduled.local.yaml +++ b/examples/docker-compose.scheduled.local.yaml @@ -1,12 +1,11 @@ version: "3" services: mysql-bkup: + # In production, it is advised to lock your image tag to a proper + # release version instead of using `latest`. image: jkaninda/mysql-bkup container_name: mysql-bkup - command: - - /bin/sh - - -c - - mysql-bkup backup --dbname database_name --mode scheduled --period "0 1 * * *" + command: backup --dbname database_name --mode scheduled --period "0 1 * * *" volumes: - ./backup:/backup environment: diff --git a/examples/docker-compose.scheduled.s3.yaml b/examples/docker-compose.scheduled.s3.yaml index 1482ce6..4b32476 100644 --- a/examples/docker-compose.scheduled.s3.yaml +++ b/examples/docker-compose.scheduled.s3.yaml @@ -6,10 +6,7 @@ services: # for a list of available releases. image: jkaninda/mysql-bkup container_name: mysql-bkup - command: - - /bin/sh - - -c - - mysql-bkup backup --storage s3 -d my-database --mode scheduled --period "0 1 * * *" + command: backup --storage s3 -d my-database --mode scheduled --period "0 1 * * *" environment: - DB_PORT=3306 - DB_HOST=mysql diff --git a/examples/docker-compose.yaml b/examples/docker-compose.yaml index d9235d3..d74b018 100644 --- a/examples/docker-compose.yaml +++ b/examples/docker-compose.yaml @@ -3,10 +3,7 @@ services: mysql-bkup: image: jkaninda/mysql-bkup container_name: mysql-bkup - command: - - /bin/sh - - -c - - mysql-bkup backup --dbname database_name + command: backup --dbname database_name volumes: - ./backup:/backup environment: diff --git a/pkg/scripts.go b/pkg/scripts.go index e05ad55..98870bb 100644 --- a/pkg/scripts.go +++ b/pkg/scripts.go @@ -24,7 +24,7 @@ func CreateCrontabScript(disableCompression bool, storage string) { scriptContent := fmt.Sprintf(`#!/usr/bin/env bash set -e -bkup backup --dbname %s --port %s --storage %s %v +/usr/local/bin/mysql-bkup backup --dbname %s --port %s --storage %s %v `, os.Getenv("DB_NAME"), os.Getenv("DB_PORT"), storage, disableC) if err := utils.WriteToFile(backupCronFile, scriptContent); err != nil { From 88ada6fefde624794a94c3f4177ea730767c118c Mon Sep 17 00:00:00 2001 From: Jonas Kaninda Date: Sat, 10 Aug 2024 11:12:17 +0200 Subject: [PATCH 2/4] docs: update example --- Makefile | 4 ++-- docs/how-tos/deploy-on-kubernetes.md | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 2433f0a..aa4126a 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ BINARY_NAME=mysql-bkup -IMAGE_NAME=jkaninda/mysql-bkup +IMAGE_NAME=jkaninda/mysql-bkup:develop-e6c8b0923d2063c97567547d82ce7909a4f553bb include .env export @@ -18,7 +18,7 @@ compile: docker-build: docker build -f docker/Dockerfile -t jkaninda/mysql-bkup:latest . -docker-run: docker-build +docker-run: #docker-build docker run --rm --network web --name mysql-bkup -v "./backup:/backup" -e "DB_HOST=${DB_HOST}" -e "DB_NAME=${DB_NAME}" -e "DB_USERNAME=${DB_USERNAME}" -e "DB_PASSWORD=${DB_PASSWORD}" -e "GPG_PASSPHRASE=${GPG_PASSPHRASE}" ${IMAGE_NAME} backup --prune --keep-last 2 docker-restore: docker-build docker run --rm --network web --name mysql-bkup -v "./backup:/backup" -e "DB_HOST=${DB_HOST}" -e "DB_NAME=${DB_NAME}" -e "DB_USERNAME=${DB_USERNAME}" -e "DB_PASSWORD=${DB_PASSWORD}" -e "GPG_PASSPHRASE=${GPG_PASSPHRASE}" ${IMAGE_NAME} restore -f ${FILE_NAME} diff --git a/docs/how-tos/deploy-on-kubernetes.md b/docs/how-tos/deploy-on-kubernetes.md index 49185af..5cd97a0 100644 --- a/docs/how-tos/deploy-on-kubernetes.md +++ b/docs/how-tos/deploy-on-kubernetes.md @@ -46,7 +46,7 @@ spec: - name: DB_NAME value: "dbname" - name: DB_USERNAME - value: "postgres" + value: "username" # Please use secret! - name: DB_PASSWORD value: "" @@ -102,7 +102,7 @@ spec: - name: DB_NAME value: "dbname" - name: DB_USERNAME - value: "postgres" + value: "username" # Please use secret! - name: DB_PASSWORD value: "" @@ -115,7 +115,7 @@ spec: - name: SSH_PASSWORD value: "xxxx" - name: SSH_REMOTE_PATH - value: "/home/toto/backup" + value: "/home/xxxx/backup" # Optional, required if your backup was encrypted #- name: GPG_PASSPHRASE # value: "xxxx" @@ -154,20 +154,20 @@ spec: - name: DB_HOST value: "" - name: DB_NAME - value: "test" + value: "username" - name: DB_USERNAME - value: "postgres" + value: "username" # Please use secret! - name: DB_PASSWORD value: "" - name: SSH_HOST_NAME - value: "192.168.1.16" + value: "xxx" - name: SSH_PORT - value: "2222" + value: "xxx" - name: SSH_USER value: "jkaninda" - name: SSH_REMOTE_PATH - value: "/config/backup" + value: "/home/jkaninda/backup" - name: SSH_PASSWORD value: "password" # Optional, required if you want to encrypt your backup @@ -217,20 +217,20 @@ spec: - name: DB_HOST value: "" - name: DB_NAME - value: "test" + value: "xxx" - name: DB_USERNAME - value: "postgres" + value: "xxx" # Please use secret! - name: DB_PASSWORD value: "" - name: SSH_HOST_NAME - value: "192.168.1.16" + value: "xxx" - name: SSH_PORT - value: "2222" + value: "22" - name: SSH_USER value: "jkaninda" - name: SSH_REMOTE_PATH - value: "/config/backup" + value: "/home/jkaninda/backup" - name: SSH_PASSWORD value: "password" # Optional, required if you want to encrypt your backup From 5c2c05499fb97df2ca5ed13ce65c1e5c881674c3 Mon Sep 17 00:00:00 2001 From: Jonas Kaninda Date: Sat, 10 Aug 2024 11:12:43 +0200 Subject: [PATCH 3/4] docs: update example --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index aa4126a..6516d7c 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ BINARY_NAME=mysql-bkup -IMAGE_NAME=jkaninda/mysql-bkup:develop-e6c8b0923d2063c97567547d82ce7909a4f553bb +IMAGE_NAME=jkaninda/mysql-bkup include .env export From d90647aae752a1ece380e137ab544a608d2960a1 Mon Sep 17 00:00:00 2001 From: Jonas Kaninda Date: Sat, 10 Aug 2024 11:22:08 +0200 Subject: [PATCH 4/4] Update app version --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 61743a7..65f894c 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -31,7 +31,7 @@ ENV SSH_HOST_NAME="" ENV SSH_IDENTIFY_FILE="" ENV SSH_PORT="22" ARG DEBIAN_FRONTEND=noninteractive -ENV VERSION="v1.0" +ENV VERSION="v1.2.1" ARG WORKDIR="/app" ARG BACKUPDIR="/backup" ARG BACKUP_TMP_DIR="/tmp/backup"