feat(database-dump-via-docker-sock): 支持Kingbase数据库备份

This commit is contained in:
严浩
2025-09-23 14:44:27 +08:00
parent 109fc8eac1
commit adfa640822

View File

@@ -2,7 +2,7 @@
set -eu
# Generic database backup triggered through the Docker Engine unix socket.
# Supports PostgreSQL and MySQL/MariaDB containers.
# Supports PostgreSQL, MySQL/MariaDB, and Kingbase containers.
log() {
printf '%s\n' "$(date -u '+%Y-%m-%dT%H:%M:%SZ') $*"
@@ -11,14 +11,14 @@ log() {
print_usage() {
cat <<EOF_USAGE >&2
Usage: $0 [--socket=PATH] [--api-version=VERSION] --container=NAME \\
[--type=postgres|mysql] --backup-prefix=PREFIX [--backup-dir=DIR] \\
[--type=postgres|mysql|kingbase] --backup-prefix=PREFIX [--backup-dir=DIR] \\
[--mysql-user=USER] [--mysql-password=PASSWORD]
Options:
--socket=PATH Docker Engine unix socket path (default: /var/run/docker.sock)
--api-version=VERSION Docker API version (default: v1.51)
--container=NAME Container name to execute the backup in
--type=TYPE Database type: postgres or mysql (auto-detected from container name if omitted)
--type=TYPE Database type: postgres, mysql, or kingbase (auto-detected from container name if omitted)
--backup-dir=DIR Directory to store backups (default: /backups)
--backup-prefix=PREFIX Backup filename prefix
--mysql-user=USER MySQL user (default: root)
@@ -53,6 +53,10 @@ detect_db_type_from_name() {
printf 'mysql'
return 0
;;
*kingbase*)
printf 'kingbase'
return 0
;;
esac
return 1
@@ -198,7 +202,7 @@ if [ -z "$DB_TYPE" ]; then
log "auto-detected database type '$DB_TYPE' from container name '$CONTAINER_NAME'"
else
printf 'Unable to detect database type from container name: %s\n' "$CONTAINER_NAME" >&2
printf 'Please specify --type=postgres or --type=mysql\n' >&2
printf 'Please specify --type=postgres, --type=mysql, or --type=kingbase\n' >&2
exit 1
fi
fi
@@ -219,6 +223,11 @@ case $DB_TYPE in
fi
COMPRESS_CMD="zstd"
;;
kingbase)
BACKUP_EXTENSION=".sql.zst"
DUMP_CMD="sys_dumpall --clean --username=\"\${DB_USER:-kingbase}\""
COMPRESS_CMD="zstd"
;;
*)
printf 'Unsupported database type: %s\n' "$DB_TYPE" >&2
exit 1