mirror of
https://github.com/jkaninda/mysql-bkup.git
synced 2025-12-06 13:39:41 +01:00
refactor: refactoring of code, update docs
This commit is contained in:
34
README.md
34
README.md
@@ -41,21 +41,37 @@ MySQL Backup and Restoration tool. Backup database to AWS S3 storage or any S3 A
|
|||||||
| Options | Shorts | Usage |
|
| Options | Shorts | Usage |
|
||||||
|-----------------------|--------|--------------------------------------------------------------------|
|
|-----------------------|--------|--------------------------------------------------------------------|
|
||||||
| mysql-bkup | bkup | CLI utility |
|
| mysql-bkup | bkup | CLI utility |
|
||||||
| backup | | Backup database operation |
|
| backup | | Backup database operation |
|
||||||
| restore | | Restore database operation |
|
| restore | | Restore database operation |
|
||||||
| history | | Show the history of backup |
|
| history | | Show the history of backup |
|
||||||
| --storage | -s | Set storage. local or s3 (default: local) |
|
| --storage | -s | Set storage. local or s3 (default: local) |
|
||||||
| --file | -f | Set file name for restoration |
|
| --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 |
|
| --dbname | -d | Set database name |
|
||||||
| --port | -p | Set database port (default: 3306) |
|
| --port | -p | Set database port (default: 3306) |
|
||||||
| --mode | -m | Set execution mode. default or scheduled (default: default) |
|
| --mode | -m | Set execution mode. default or scheduled (default: default) |
|
||||||
| --disable-compression | | Disable database backup compression |
|
| --disable-compression | | Disable database backup compression |
|
||||||
| --period | | Set crontab period for scheduled mode only. (default: "0 1 * * *") |
|
| --period | | Set crontab period for scheduled mode only. (default: "0 1 * * *") |
|
||||||
| --timeout | -t | Set timeout (default: 60s) |
|
| --timeout | -t | Set timeout (default: 60s) |
|
||||||
| --help | -h | Print this help message and exit |
|
| --help | -h | Print this help message and exit |
|
||||||
| --version | -V | Print version information 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:
|
## Note:
|
||||||
|
|
||||||
Creating a user for backup tasks who has read-only access is recommended!
|
Creating a user for backup tasks who has read-only access is recommended!
|
||||||
@@ -217,7 +233,7 @@ services:
|
|||||||
- DB_PASSWORD=password
|
- DB_PASSWORD=password
|
||||||
- ACCESS_KEY=${ACCESS_KEY}
|
- ACCESS_KEY=${ACCESS_KEY}
|
||||||
- SECRET_KEY=${SECRET_KEY}
|
- SECRET_KEY=${SECRET_KEY}
|
||||||
- BUCKETNAME=${BUCKETNAME}
|
- BUCKET_NAME=${BUCKET_NAME}
|
||||||
- S3_ENDPOINT=${S3_ENDPOINT}
|
- S3_ENDPOINT=${S3_ENDPOINT}
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -300,7 +316,7 @@ services:
|
|||||||
- DB_PASSWORD=${DB_PASSWORD}
|
- DB_PASSWORD=${DB_PASSWORD}
|
||||||
- ACCESS_KEY=${ACCESS_KEY}
|
- ACCESS_KEY=${ACCESS_KEY}
|
||||||
- SECRET_KEY=${SECRET_KEY}
|
- SECRET_KEY=${SECRET_KEY}
|
||||||
- BUCKETNAME=${BUCKETNAME}
|
- BUCKET_NAME=${BUCKET_NAME}
|
||||||
- S3_ENDPOINT=${S3_ENDPOINT}
|
- S3_ENDPOINT=${S3_ENDPOINT}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -346,7 +362,7 @@ spec:
|
|||||||
value: ""
|
value: ""
|
||||||
- name: SECRET_KEY
|
- name: SECRET_KEY
|
||||||
value: ""
|
value: ""
|
||||||
- name: BUCKETNAME
|
- name: BUCKET_NAME
|
||||||
value: ""
|
value: ""
|
||||||
- name: S3_ENDPOINT
|
- name: S3_ENDPOINT
|
||||||
value: "https://s3.us-west-2.amazonaws.com"
|
value: "https://s3.us-west-2.amazonaws.com"
|
||||||
|
|||||||
@@ -17,5 +17,5 @@ services:
|
|||||||
- DB_PASSWORD=${DB_PASSWORD}
|
- DB_PASSWORD=${DB_PASSWORD}
|
||||||
- ACCESS_KEY=${ACCESS_KEY}
|
- ACCESS_KEY=${ACCESS_KEY}
|
||||||
- SECRET_KEY=${SECRET_KEY}
|
- SECRET_KEY=${SECRET_KEY}
|
||||||
- BUCKETNAME=${BUCKETNAME}
|
- BUCKET_NAME=${BUCKET_NAME}
|
||||||
- S3_ENDPOINT=https://s3.us-west-2.amazonaws.com
|
- S3_ENDPOINT=https://s3.us-west-2.amazonaws.com
|
||||||
@@ -17,5 +17,5 @@ services:
|
|||||||
- DB_PASSWORD=${DB_PASSWORD}
|
- DB_PASSWORD=${DB_PASSWORD}
|
||||||
- ACCESS_KEY=${ACCESS_KEY}
|
- ACCESS_KEY=${ACCESS_KEY}
|
||||||
- SECRET_KEY=${SECRET_KEY}
|
- SECRET_KEY=${SECRET_KEY}
|
||||||
- BUCKETNAME=${BUCKETNAME}
|
- BUCKET_NAME=${BUCKET_NAME}
|
||||||
- S3_ENDPOINT=https://s3.us-west-2.amazonaws.com
|
- S3_ENDPOINT=https://s3.us-west-2.amazonaws.com
|
||||||
@@ -39,7 +39,7 @@ func RestoreDatabase(file string) {
|
|||||||
dbPort = os.Getenv("DB_PORT")
|
dbPort = os.Getenv("DB_PORT")
|
||||||
storagePath = os.Getenv("STORAGE_PATH")
|
storagePath = os.Getenv("STORAGE_PATH")
|
||||||
if file == "" {
|
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 == "" {
|
if os.Getenv("DB_HOST") == "" || os.Getenv("DB_NAME") == "" || os.Getenv("DB_USERNAME") == "" || os.Getenv("DB_PASSWORD") == "" || file == "" {
|
||||||
|
|||||||
@@ -26,11 +26,14 @@ func S3Mount() {
|
|||||||
func MountS3Storage(s3Path string) {
|
func MountS3Storage(s3Path string) {
|
||||||
accessKey = os.Getenv("ACCESS_KEY")
|
accessKey = os.Getenv("ACCESS_KEY")
|
||||||
secretKey = os.Getenv("SECRET_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")
|
s3Endpoint = os.Getenv("S3_ENDPOINT")
|
||||||
|
|
||||||
if accessKey == "" || secretKey == "" || bucketName == "" {
|
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 {
|
} else {
|
||||||
storagePath := fmt.Sprintf("%s%s", s3MountPath, s3Path)
|
storagePath := fmt.Sprintf("%s%s", s3MountPath, s3Path)
|
||||||
err := os.Setenv("STORAGE_PATH", storagePath)
|
err := os.Setenv("STORAGE_PATH", storagePath)
|
||||||
|
|||||||
Reference in New Issue
Block a user