Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: halodb Create backup functionality #267

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions addons/halo/dataprotection/backup-info-collector.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function get_current_time() {
curr_time=$(psql -U ${DP_DB_USER} -d halo0root -t -c "SELECT now() AT TIME ZONE 'UTC'")
echo $curr_time
}

function stat_and_save_backup_info() {
export PATH="$PATH:$DP_DATASAFED_BIN_PATH"
export DATASAFED_BACKEND_BASE_PATH="$DP_BACKUP_BASE_PATH"
START_TIME=$1
STOP_TIME=$2
if [ -z $STOP_TIME ]; then
STOP_TIME=$(get_current_time)
fi
START_TIME=$(date -d "${START_TIME}" -u '+%Y-%m-%dT%H:%M:%SZ')
STOP_TIME=$(date -d "${STOP_TIME}" -u '+%Y-%m-%dT%H:%M:%SZ')
TOTAL_SIZE=$(datasafed stat / | grep TotalSize | awk '{print $2}')
echo "{\"totalSize\":\"$TOTAL_SIZE\",\"timeRange\":{\"start\":\"${START_TIME}\",\"end\":\"${STOP_TIME}\"}}" >"${DP_BACKUP_INFO_FILE}"
}

# if the script exits with a non-zero exit code, touch a file to indicate that the backup failed,
# the sync progress container will check this file and exit if it exists
function handle_exit() {
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "failed with exit code $exit_code"
touch "${DP_BACKUP_INFO_FILE}.exit"
exit 1
fi
}
13 changes: 13 additions & 0 deletions addons/halo/dataprotection/halo-basebackup-backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set -e
set -o pipefail
export PATH="$PATH:$DP_DATASAFED_BIN_PATH"
export DATASAFED_BACKEND_BASE_PATH="$DP_BACKUP_BASE_PATH"
export PGPASSWORD=${DP_DB_PASSWORD}

trap handle_exit EXIT

START_TIME=`get_current_time`
echo ${DP_DB_PASSWORD} | pg_basebackup -Ft -Pv -c fast -Xf -D - -h ${DP_DB_HOST} -U ${DP_DB_USER} -W | datasafed push -z zstd-fastest - "/${DP_BACKUP_NAME}.tar.zst"

# stat and save the backup information
stat_and_save_backup_info $START_TIME
33 changes: 33 additions & 0 deletions addons/halo/templates/actionset-halobasebackup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: dataprotection.kubeblocks.io/v1alpha1
kind: ActionSet
metadata:
name: pg-basebackup
labels:
clusterdefinition.kubeblocks.io/name: halo
{{- include "halo.labels" . | nindent 4 }}
spec:
backupType: Full
env:
- name: DATA_DIR
value: {{ .Values.dataMountPath }}
- name: DP_DB_USER
value: halo
- name: DP_BACKUP_BASE_PATH
value: /u01/app/halo/product/dbms/14/bin
- name: DP_DB_HOST
value: localhost
backup:
preBackup: []
postBackup: []
backupData:
image: {{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}
command:
- bash
- -c
- |
{{- .Files.Get "dataprotection/backup-info-collector.sh" | nindent 8 -}}
{{- .Files.Get "dataprotection/halo-basebackup-backup.sh" | nindent 8 -}}
syncProgress:
enabled: true
intervalSeconds: 5

25 changes: 25 additions & 0 deletions addons/halo/templates/backuppolicytemplate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: apps.kubeblocks.io/v1alpha1
kind: BackupPolicyTemplate
metadata:
name: halo-backup-policy-template
labels:
clusterdefinition.kubeblocks.io/name: halo
{{- include "halo.labels" . | nindent 4 }}
spec:
clusterDefinitionRef: halo
backupPolicies:
- componentDefRef: halo
backupMethods:
- name: pg-basebackup
snapshotVolumes: false
actionSetName: pg-basebackup
targetVolumes:
volumeMounts:
- name: data
mountPath: {{ .Values.dataMountPath }}
schedules:
- backupMethod: pg-basebackup
enabled: false
cronExpression: "*/5 * * * *"
retentionPeriod: 7d

5 changes: 4 additions & 1 deletion addons/halo/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ image:
## pullSecrets:
## - myRegistryKeySecretName
##

pullSecrets: []
## Set to true if you would like to see extra information on logs
##
debug: true
## Set PostgreSQL preload extension shared libraries.
## @param postgresqlSharedPreloadLibraries Shared preload libraries (comma-separated list)
##
Expand Down