From 1899fa06e7d59409d304f508ca4f1b25607107f5 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Thu, 16 Jan 2025 14:34:39 +0700 Subject: [PATCH] feat: multi bucket backup --- src/controllers/backup-controller.ts | 39 +++++++++++++++------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/controllers/backup-controller.ts b/src/controllers/backup-controller.ts index 320030f..6c0a5e0 100644 --- a/src/controllers/backup-controller.ts +++ b/src/controllers/backup-controller.ts @@ -29,6 +29,9 @@ const MAIN_MINIO_SECRET_KEY = getEnvVar("MAIN_MINIO_SECRET_KEY"); const MAIN_MINIO_BUCKET = getEnvVar("MAIN_MINIO_BUCKET"); const BACKUP_MINIO_BUCKET = getEnvVar("BACKUP_MINIO_BUCKET"); +const s3TargetUrl = `${MAIN_MINIO_USE_SSL === "true" ? "https://" : "http://"}${MAIN_MINIO_HOST}${(MAIN_MINIO_PORT && ":" + MAIN_MINIO_PORT) || ""}`; +const s3BackupUrl = `${MAIN_MINIO_USE_SSL === "true" ? "https://" : "http://"}${MAIN_MINIO_HOST}${(MAIN_MINIO_PORT && ":" + MAIN_MINIO_PORT) || ""}`; + function jsonParseOrPlainText(str: string) { try { return JSON.parse(str); @@ -51,7 +54,7 @@ export class BackupController extends Controller { "Content-Type": "application/json", }, body: JSON.stringify({ - s3_backup_endpoint: `${MAIN_MINIO_USE_SSL === "true" ? "https://" : "http://"}${MAIN_MINIO_HOST}${(MAIN_MINIO_PORT && ":" + MAIN_MINIO_PORT) || ""}`, + s3_backup_endpoint: s3BackupUrl, s3_backup_access: MAIN_MINIO_ACCESS_KEY, s3_backup_secret: MAIN_MINIO_SECRET_KEY, s3_backup_bucket: BACKUP_MINIO_BUCKET, @@ -133,16 +136,16 @@ export class BackupController extends Controller { body: JSON.stringify({ backup_name: name, storage: { - s3_source_endpoint: `${MAIN_MINIO_USE_SSL === "true" ? "https://" : "http://"}${MAIN_MINIO_HOST}${(MAIN_MINIO_PORT && ":" + MAIN_MINIO_PORT) || ""}`, + s3_source_endpoint: s3TargetUrl, s3_source_access: MAIN_MINIO_ACCESS_KEY, s3_source_secret: MAIN_MINIO_SECRET_KEY, - s3_source_bucket: MAIN_MINIO_BUCKET, - s3_dest_endpoint: `${MAIN_MINIO_USE_SSL === "true" ? "https://" : "http://"}${MAIN_MINIO_HOST}${(MAIN_MINIO_PORT && ":" + MAIN_MINIO_PORT) || ""}`, + s3_source_bucket: MAIN_MINIO_BUCKET.replaceAll(",", " "), + s3_dest_endpoint: s3BackupUrl, s3_dest_access: MAIN_MINIO_ACCESS_KEY, s3_dest_secret: MAIN_MINIO_SECRET_KEY, }, database: { - s3_endpoint: `${MAIN_MINIO_USE_SSL === "true" ? "https://" : "http://"}${MAIN_MINIO_HOST}${(MAIN_MINIO_PORT && ":" + MAIN_MINIO_PORT) || ""}`, + s3_endpoint: s3BackupUrl, s3_access: MAIN_MINIO_ACCESS_KEY, s3_secret: MAIN_MINIO_SECRET_KEY, s3_bucket: BACKUP_MINIO_BUCKET, @@ -176,16 +179,16 @@ export class BackupController extends Controller { body: JSON.stringify({ backup_name: body.name, storage: { - s3_restore_endpoint: `${MAIN_MINIO_USE_SSL === "true" ? "https://" : "http://"}${MAIN_MINIO_HOST}${(MAIN_MINIO_PORT && ":" + MAIN_MINIO_PORT) || ""}`, + s3_restore_endpoint: s3TargetUrl, s3_restore_access: MAIN_MINIO_ACCESS_KEY, s3_restore_secret: MAIN_MINIO_SECRET_KEY, - s3_restore_bucket: MAIN_MINIO_BUCKET, - s3_backup_endpoint: `${MAIN_MINIO_USE_SSL === "true" ? "https://" : "http://"}${MAIN_MINIO_HOST}${(MAIN_MINIO_PORT && ":" + MAIN_MINIO_PORT) || ""}`, + s3_restore_bucket: MAIN_MINIO_BUCKET.replaceAll(",", " "), + s3_backup_endpoint: s3BackupUrl, s3_backup_access: MAIN_MINIO_ACCESS_KEY, s3_backup_secret: MAIN_MINIO_SECRET_KEY, }, database: { - s3_endpoint: `${MAIN_MINIO_USE_SSL === "true" ? "https://" : "http://"}${MAIN_MINIO_HOST}${(MAIN_MINIO_PORT && ":" + MAIN_MINIO_PORT) || ""}`, + s3_endpoint: s3BackupUrl, s3_access: MAIN_MINIO_ACCESS_KEY, s3_secret: MAIN_MINIO_SECRET_KEY, s3_bucket: BACKUP_MINIO_BUCKET, @@ -211,7 +214,7 @@ export class BackupController extends Controller { }, body: JSON.stringify({ backup_name: body.name, - s3_backup_endpoint: `${MAIN_MINIO_USE_SSL === "true" ? "https://" : "http://"}${MAIN_MINIO_HOST}${(MAIN_MINIO_PORT && ":" + MAIN_MINIO_PORT) || ""}`, + s3_backup_endpoint: s3BackupUrl, s3_backup_access: MAIN_MINIO_ACCESS_KEY, s3_backup_secret: MAIN_MINIO_SECRET_KEY, s3_backup_bucket: BACKUP_MINIO_BUCKET, @@ -276,16 +279,16 @@ export class BackupController extends Controller { backup_name: body.name, prefix_timestamp: true, storage: { - s3_source_endpoint: `${MAIN_MINIO_USE_SSL === "true" ? "https://" : "http://"}${MAIN_MINIO_HOST}${(MAIN_MINIO_PORT && ":" + MAIN_MINIO_PORT) || ""}`, + s3_source_endpoint: s3TargetUrl, s3_source_access: MAIN_MINIO_ACCESS_KEY, s3_source_secret: MAIN_MINIO_SECRET_KEY, - s3_source_bucket: MAIN_MINIO_BUCKET, - s3_dest_endpoint: `${MAIN_MINIO_USE_SSL === "true" ? "https://" : "http://"}${MAIN_MINIO_HOST}${(MAIN_MINIO_PORT && ":" + MAIN_MINIO_PORT) || ""}`, + s3_source_bucket: MAIN_MINIO_BUCKET.replaceAll(",", " "), + s3_dest_endpoint: s3BackupUrl, s3_dest_access: MAIN_MINIO_ACCESS_KEY, s3_dest_secret: MAIN_MINIO_SECRET_KEY, }, database: { - s3_endpoint: `${MAIN_MINIO_USE_SSL === "true" ? "https://" : "http://"}${MAIN_MINIO_HOST}${(MAIN_MINIO_PORT && ":" + MAIN_MINIO_PORT) || ""}`, + s3_endpoint: s3BackupUrl, s3_access: MAIN_MINIO_ACCESS_KEY, s3_secret: MAIN_MINIO_SECRET_KEY, s3_bucket: BACKUP_MINIO_BUCKET, @@ -327,16 +330,16 @@ export class BackupController extends Controller { backup_name: body.name, prefix_timestamp: true, storage: { - s3_source_endpoint: `${MAIN_MINIO_USE_SSL === "true" ? "https://" : "http://"}${MAIN_MINIO_HOST}${(MAIN_MINIO_PORT && ":" + MAIN_MINIO_PORT) || ""}`, + s3_source_endpoint: s3TargetUrl, s3_source_access: MAIN_MINIO_ACCESS_KEY, s3_source_secret: MAIN_MINIO_SECRET_KEY, - s3_source_bucket: MAIN_MINIO_BUCKET, - s3_dest_endpoint: `${MAIN_MINIO_USE_SSL === "true" ? "https://" : "http://"}${MAIN_MINIO_HOST}${(MAIN_MINIO_PORT && ":" + MAIN_MINIO_PORT) || ""}`, + s3_source_bucket: MAIN_MINIO_BUCKET.replaceAll(",", " "), + s3_dest_endpoint: s3BackupUrl, s3_dest_access: MAIN_MINIO_ACCESS_KEY, s3_dest_secret: MAIN_MINIO_SECRET_KEY, }, database: { - s3_endpoint: `${MAIN_MINIO_USE_SSL === "true" ? "https://" : "http://"}${MAIN_MINIO_HOST}${(MAIN_MINIO_PORT && ":" + MAIN_MINIO_PORT) || ""}`, + s3_endpoint: s3BackupUrl, s3_access: MAIN_MINIO_ACCESS_KEY, s3_secret: MAIN_MINIO_SECRET_KEY, s3_bucket: BACKUP_MINIO_BUCKET,