-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:finish backup and restore (#2968)
* backup and restore * delete sh * modify config
- Loading branch information
1 parent
937ebde
commit 713e6fb
Showing
13 changed files
with
209 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
kbcli backuprepo create my-repo \ | ||
--provider s3 \ | ||
--region ${S3_REGION} \ | ||
--bucket ${S3_BUCKET} \ | ||
--endpoint ${S3_ENDPOINT} \ | ||
--access-key-id ${S3_ACCESS_KEY} \ | ||
--secret-access-key ${S3_SECRET_KEY} \ | ||
--access-method ${S3_ACCESS_METHOD} \ | ||
--default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
tools/kubeblocks_helm/reinstall.sh → tools/kubeblocks_helm/install.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
helm uninstall pika && helm uninstall pika-cluster | ||
sleep 5 | ||
helm install pika ./pika && helm install pika-cluster ./pika-cluster |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
helm install pika-master-slave ./pika-master-slave && helm install pika-master-slave-cluster ./pika-master-slave-cluster |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
tools/kubeblocks_helm/pika-master-slave/dataprotection/backup.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash | ||
set -o pipefail | ||
function handle_exit() { | ||
exit_code=$? | ||
if [ $exit_code -ne 0 ]; then | ||
echo "failed with exit code $exit_code" | ||
exit 1 | ||
fi | ||
} | ||
trap handle_exit EXIT | ||
export PATH="$PATH:$DP_DATASAFED_BIN_PATH" | ||
export DATASAFED_BACKEND_BASE_PATH="$DP_BACKUP_BASE_PATH" | ||
|
||
connect_url="redis-cli -h ${DP_DB_HOST} -p ${DP_DB_PORT}" | ||
last_save=$(${connect_url} LASTSAVE) | ||
|
||
echo "INFO: start BGSAVE" | ||
${connect_url} BGSAVE | ||
|
||
echo "INFO: wait for saving dump successfully" | ||
while true; do | ||
end_save=$(${connect_url} LASTSAVE) | ||
if [ $end_save -ne $last_save ];then | ||
break | ||
fi | ||
sleep 1 | ||
done | ||
|
||
cd ${DATA_DIR} | ||
|
||
if [ -d "log" ] || [ -d "db" ]; then | ||
tar -cvf - ./log ./db | datasafed push -z zstd-fastest - "${DP_BACKUP_NAME}.tar.zst" | ||
else | ||
echo "no log db" | ||
exit 1 | ||
fi | ||
echo "INFO: save data file successfully" | ||
TOTAL_SIZE=$(datasafed stat / | grep TotalSize | awk '{print $2}') | ||
echo "{\"totalSize\":\"$TOTAL_SIZE\"}" >"${DP_BACKUP_INFO_FILE}" && sync |
21 changes: 21 additions & 0 deletions
21
tools/kubeblocks_helm/pika-master-slave/dataprotection/restore.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
set -e | ||
set -o pipefail | ||
export PATH="$PATH:$DP_DATASAFED_BIN_PATH" | ||
export DATASAFED_BACKEND_BASE_PATH="$DP_BACKUP_BASE_PATH" | ||
mkdir -p ${DATA_DIR} | ||
res=`find ${DATA_DIR} -type f` | ||
data_protection_file=${DATA_DIR}/.kb-data-protection | ||
if [ ! -z "${res}" ] && [ ! -f ${data_protection_file} ]; then | ||
echo "${DATA_DIR} is not empty! Please make sure that the directory is empty before restoring the backup." | ||
exit 1 | ||
fi | ||
# touch placeholder file | ||
touch ${data_protection_file} | ||
|
||
backupFile="${DP_BACKUP_NAME}.tar.zst" | ||
if [ "$(datasafed list ${backupFile})" == "${backupFile}" ]; then | ||
datasafed pull -d zstd-fastest "${backupFile}" - | tar -xvf - -C ${DATA_DIR} | ||
else | ||
datasafed pull "${DP_BACKUP_NAME}.tar.gz" - | tar -xzvf - -C ${DATA_DIR} | ||
fi | ||
rm -rf ${data_protection_file} && sync |
37 changes: 37 additions & 0 deletions
37
tools/kubeblocks_helm/pika-master-slave/templates/backupactionset.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
apiVersion: dataprotection.kubeblocks.io/v1alpha1 | ||
kind: ActionSet | ||
metadata: | ||
name: pika-backup | ||
labels: | ||
clusterdefinition.kubeblocks.io/name: pika-master-slave-cluster | ||
{{- include "pika.labels" . | nindent 4 }} | ||
spec: | ||
backupType: Full | ||
env: | ||
- name: DATA_DIR | ||
value: /data | ||
- name: DP_DB_PORT | ||
value: "9221" | ||
backup: | ||
preBackup: [] | ||
postBackup: [] | ||
backupData: | ||
image: {{ include "redis.image" . }} | ||
runOnTargetPodNode: true | ||
syncProgress: | ||
enabled: true | ||
intervalSeconds: 5 | ||
command: | ||
- bash | ||
- -c | ||
- | | ||
{{- .Files.Get "dataprotection/backup.sh" | nindent 8 }} | ||
restore: | ||
prepareData: | ||
image: {{ include "redis.image" . }} | ||
command: | ||
- bash | ||
- -c | ||
- | | ||
{{- .Files.Get "dataprotection/restore.sh" | nindent 8 }} | ||
postReady: [] |
26 changes: 26 additions & 0 deletions
26
tools/kubeblocks_helm/pika-master-slave/templates/backuppolicytemplate.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
apiVersion: apps.kubeblocks.io/v1alpha1 | ||
kind: BackupPolicyTemplate | ||
metadata: | ||
name: pika-backup-policy-template | ||
labels: | ||
clusterdefinition.kubeblocks.io/name: pika-master-slave-cluster | ||
{{- include "pika.labels" . | nindent 4 }} | ||
spec: | ||
backupPolicies: | ||
- componentDefs: | ||
- pika | ||
target: | ||
role: master | ||
backupMethods: | ||
- name: datafile | ||
snapshotVolumes: false | ||
actionSetName: pika-backup | ||
targetVolumes: | ||
volumeMounts: | ||
- name: data | ||
mountPath: /data | ||
schedules: | ||
- backupMethod: datafile | ||
enabled: true | ||
cronExpression: "0 18 * * 0" | ||
retentionPeriod: 3m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
helm uninstall pika-cluster && helm uninstall pika |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
helm uninstall pika-master-slave-cluster && helm uninstall pika-master-slave |