From 876fa41c9bb1f187e0a5f2bfebd15aa404c37f89 Mon Sep 17 00:00:00 2001 From: zjx20 Date: Wed, 3 Jan 2024 11:35:26 +0800 Subject: [PATCH] chore: backup postgresql with zstd instead of gzip (#175) --- addons/postgresql/dataprotection/pg-basebackup-backup.sh | 2 +- addons/postgresql/dataprotection/pg-basebackup-restore.sh | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/addons/postgresql/dataprotection/pg-basebackup-backup.sh b/addons/postgresql/dataprotection/pg-basebackup-backup.sh index e95db8a8d..0e2b63e84 100644 --- a/addons/postgresql/dataprotection/pg-basebackup-backup.sh +++ b/addons/postgresql/dataprotection/pg-basebackup-backup.sh @@ -7,7 +7,7 @@ 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 | gzip | datasafed push - "/${DP_BACKUP_NAME}.tar.gz" +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 - "/${DP_BACKUP_NAME}.tar.zst" # stat and save the backup information stat_and_save_backup_info $START_TIME \ No newline at end of file diff --git a/addons/postgresql/dataprotection/pg-basebackup-restore.sh b/addons/postgresql/dataprotection/pg-basebackup-restore.sh index 23652f439..405cbc56a 100644 --- a/addons/postgresql/dataprotection/pg-basebackup-restore.sh +++ b/addons/postgresql/dataprotection/pg-basebackup-restore.sh @@ -13,6 +13,13 @@ function remote_file_exists() { mkdir -p ${DATA_DIR}; +if [ $(remote_file_exists "${DP_BACKUP_NAME}.tar.zst") == "true" ]; then + datasafed pull -d zstd "${DP_BACKUP_NAME}.tar.zst" - | tar -xvf - -C "${DATA_DIR}/" + echo "done!"; + exit 0 +fi + +# for compatibility if [ $(remote_file_exists "${DP_BACKUP_NAME}.tar.gz") == "true" ]; then datasafed pull "${DP_BACKUP_NAME}.tar.gz" - | gunzip | tar -xvf - -C "${DATA_DIR}/" echo "done!";