From 620801cb99b91faa39555ada085102bd7ac8119f Mon Sep 17 00:00:00 2001 From: Jonas Kaninda Date: Sun, 21 Jan 2024 15:18:35 +0100 Subject: [PATCH 1/3] refactor: refactoring of code, update docs --- README.md | 34 +++++++++++++++++------ examples/docker-compose.s3.yaml | 2 +- examples/docker-compose.scheduled.s3.yaml | 2 +- pkg/restore.go | 2 +- pkg/s3fs.go | 7 +++-- 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index be77d94..0a62857 100644 --- a/README.md +++ b/README.md @@ -41,21 +41,37 @@ MySQL Backup and Restoration tool. Backup database to AWS S3 storage or any S3 A | Options | Shorts | Usage | |-----------------------|--------|--------------------------------------------------------------------| | mysql-bkup | bkup | CLI utility | -| backup | | Backup database operation | -| restore | | Restore database operation | -| history | | Show the history of backup | +| backup | | Backup database operation | +| restore | | Restore database operation | +| history | | Show the history of backup | | --storage | -s | Set storage. local or s3 (default: local) | | --file | -f | Set file name for restoration | -| --path | | Set s3 path without file name. eg: /custom_path | +| --path | | Set s3 path without file name. eg: /custom_path | | --dbname | -d | Set database name | | --port | -p | Set database port (default: 3306) | | --mode | -m | Set execution mode. default or scheduled (default: default) | -| --disable-compression | | Disable database backup compression | -| --period | | Set crontab period for scheduled mode only. (default: "0 1 * * *") | +| --disable-compression | | Disable database backup compression | +| --period | | Set crontab period for scheduled mode only. (default: "0 1 * * *") | | --timeout | -t | Set timeout (default: 60s) | | --help | -h | Print this help message and exit | | --version | -V | Print version information and exit | + +## Environment variables + +| Name | Requirement | Description | +|-------------|--------------------------------------------------|----------------------| +| DB_PORT | Optional, default 3306 | Database port number | +| DB_HOST | Required | Database host | +| DB_NAME | Optional if it was provided from the -d flag | Database name | +| DB_USERNAME | Required | Database user name | +| DB_PASSWORD | Required | Database password | +| ACCESS_KEY | Optional | AWS S3 Access Key | +| SECRET_KEY | Optional | AWS S3 Secret Key | +| BUCKET_NAME | Optional | AWS S3 Bucket Name | +| S3_ENDPOINT | Optional | AWS S3 Endpoint | +| FILE_NAME | Optional if it was provided from the --file flag | File to restore | + ## Note: Creating a user for backup tasks who has read-only access is recommended! @@ -217,7 +233,7 @@ services: - DB_PASSWORD=password - ACCESS_KEY=${ACCESS_KEY} - SECRET_KEY=${SECRET_KEY} - - BUCKETNAME=${BUCKETNAME} + - BUCKET_NAME=${BUCKET_NAME} - S3_ENDPOINT=${S3_ENDPOINT} ``` @@ -300,7 +316,7 @@ services: - DB_PASSWORD=${DB_PASSWORD} - ACCESS_KEY=${ACCESS_KEY} - SECRET_KEY=${SECRET_KEY} - - BUCKETNAME=${BUCKETNAME} + - BUCKET_NAME=${BUCKET_NAME} - S3_ENDPOINT=${S3_ENDPOINT} ``` @@ -346,7 +362,7 @@ spec: value: "" - name: SECRET_KEY value: "" - - name: BUCKETNAME + - name: BUCKET_NAME value: "" - name: S3_ENDPOINT value: "https://s3.us-west-2.amazonaws.com" diff --git a/examples/docker-compose.s3.yaml b/examples/docker-compose.s3.yaml index 1c0493b..29e0ca5 100644 --- a/examples/docker-compose.s3.yaml +++ b/examples/docker-compose.s3.yaml @@ -17,5 +17,5 @@ services: - DB_PASSWORD=${DB_PASSWORD} - ACCESS_KEY=${ACCESS_KEY} - SECRET_KEY=${SECRET_KEY} - - BUCKETNAME=${BUCKETNAME} + - BUCKET_NAME=${BUCKET_NAME} - S3_ENDPOINT=https://s3.us-west-2.amazonaws.com \ No newline at end of file diff --git a/examples/docker-compose.scheduled.s3.yaml b/examples/docker-compose.scheduled.s3.yaml index 8bfd4fb..c7e4771 100644 --- a/examples/docker-compose.scheduled.s3.yaml +++ b/examples/docker-compose.scheduled.s3.yaml @@ -17,5 +17,5 @@ services: - DB_PASSWORD=${DB_PASSWORD} - ACCESS_KEY=${ACCESS_KEY} - SECRET_KEY=${SECRET_KEY} - - BUCKETNAME=${BUCKETNAME} + - BUCKET_NAME=${BUCKET_NAME} - S3_ENDPOINT=https://s3.us-west-2.amazonaws.com \ No newline at end of file diff --git a/pkg/restore.go b/pkg/restore.go index 6731757..92aaa3d 100644 --- a/pkg/restore.go +++ b/pkg/restore.go @@ -39,7 +39,7 @@ func RestoreDatabase(file string) { dbPort = os.Getenv("DB_PORT") storagePath = os.Getenv("STORAGE_PATH") if file == "" { - utils.Fatal("Error required --file") + utils.Fatal("Error, file required") } if os.Getenv("DB_HOST") == "" || os.Getenv("DB_NAME") == "" || os.Getenv("DB_USERNAME") == "" || os.Getenv("DB_PASSWORD") == "" || file == "" { diff --git a/pkg/s3fs.go b/pkg/s3fs.go index 33c8811..559396b 100644 --- a/pkg/s3fs.go +++ b/pkg/s3fs.go @@ -26,11 +26,14 @@ func S3Mount() { func MountS3Storage(s3Path string) { accessKey = os.Getenv("ACCESS_KEY") secretKey = os.Getenv("SECRET_KEY") - bucketName = os.Getenv("BUCKETNAME") + bucketName = os.Getenv("BUCKET_NAME") + if bucketName == "" { + bucketName = os.Getenv("BUCKETNAME") + } s3Endpoint = os.Getenv("S3_ENDPOINT") if accessKey == "" || secretKey == "" || bucketName == "" { - utils.Fatal("Please make sure all environment variables are set") + utils.Fatal("Please make sure all environment variables are set for S3") } else { storagePath := fmt.Sprintf("%s%s", s3MountPath, s3Path) err := os.Setenv("STORAGE_PATH", storagePath) From 902695032c2c03d0d8d1fee2bc2249b4df933f41 Mon Sep 17 00:00:00 2001 From: Jonas Kaninda Date: Sun, 21 Jan 2024 15:24:44 +0100 Subject: [PATCH 2/3] docs: add more details for env variables --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0a62857..e9896f7 100644 --- a/README.md +++ b/README.md @@ -66,10 +66,10 @@ MySQL Backup and Restoration tool. Backup database to AWS S3 storage or any S3 A | DB_NAME | Optional if it was provided from the -d flag | Database name | | DB_USERNAME | Required | Database user name | | DB_PASSWORD | Required | Database password | -| ACCESS_KEY | Optional | AWS S3 Access Key | -| SECRET_KEY | Optional | AWS S3 Secret Key | -| BUCKET_NAME | Optional | AWS S3 Bucket Name | -| S3_ENDPOINT | Optional | AWS S3 Endpoint | +| ACCESS_KEY | Optional, required for S3 storage | AWS S3 Access Key | +| SECRET_KEY | Optional, required for S3 storage | AWS S3 Secret Key | +| BUCKET_NAME | Optional, required for S3 storage | AWS S3 Bucket Name | +| S3_ENDPOINT | Optional, required for S3 storage | AWS S3 Endpoint | | FILE_NAME | Optional if it was provided from the --file flag | File to restore | ## Note: From f53c68cd5cf09d0e79aaabce46fe51e265026706 Mon Sep 17 00:00:00 2001 From: Jonas Kaninda Date: Sun, 21 Jan 2024 15:26:20 +0100 Subject: [PATCH 3/3] New release --- .github/workflows/build.yml | 2 +- docker/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3498d02..fe023ed 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,5 +35,5 @@ jobs: file: "./docker/Dockerfile" platforms: linux/amd64,linux/arm64 tags: | - "${{env.BUILDKIT_IMAGE}}:v0.5" + "${{env.BUILDKIT_IMAGE}}:v0.6" "${{env.BUILDKIT_IMAGE}}:latest" diff --git a/docker/Dockerfile b/docker/Dockerfile index 0a27fd2..6e4111b 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -21,7 +21,7 @@ ENV ACCESS_KEY="" ENV SECRET_KEY="" ENV S3_ENDPOINT=https://s3.amazonaws.com ARG DEBIAN_FRONTEND=noninteractive -ENV VERSION="v0.5" +ENV VERSION="v0.6" LABEL authors="Jonas Kaninda" RUN apt-get update -qq