Skip to content

Commit d6aba80

Browse files
author
Bhavishya
committed
using sha1 checksum before uploading the file to cloud
1 parent 250e8b4 commit d6aba80

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

mariadb-logical-backup/mariadb-dump.sh

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ function compress {
4949
gzip
5050
}
5151

52+
function generate_checksum {
53+
local FILE_PATH="${1}"
54+
local CHECKSUM_FILE="/tmp/checksum.sha1"
55+
56+
echo "Generating SHA1 checksum for ${FILE_PATH}..."
57+
sha1sum "${FILE_PATH}" | tee "${CHECKSUM_FILE}"
58+
}
59+
5260
function az_upload {
5361
local FILE_PATH="${1}"
5462
# Path: container/cluster-name/scope/logical_backups/timestamp.sql.gz
@@ -123,6 +131,7 @@ function upload {
123131
"az")
124132
# Azure requires a physical file for 'az storage blob upload' in this context
125133
dump | compress > /tmp/mariadb-backup.sql.gz
134+
generate_checksum /tmp/mariadb-backup.sql.gz
126135
az_upload /tmp/mariadb-backup.sql.gz
127136
rm /tmp/mariadb-backup.sql.gz
128137
;;
@@ -140,12 +149,17 @@ else
140149
# 3. /tmp/final_upload.sql.gz - The valid gzip file sent to S3
141150

142151
echo "Starting debug pipeline..."
143-
dump 2> /tmp/dump_stderr.log | tee /tmp/raw_dump.sql | compress | tee /tmp/final_upload.sql.gz | upload
152+
dump 2> /tmp/dump_stderr.log | tee /tmp/raw_dump.sql | compress > /tmp/final_upload.sql.gz
144153

145154
# Capture status immediately!
146155
PIPELINE_STATUS=("${PIPESTATUS[@]}")
147156

148-
echo "Backup finished with status: ${PIPELINE_STATUS[*]}"
157+
generate_checksum /tmp/final_upload.sql.gz
158+
159+
cat /tmp/final_upload.sql.gz | upload
160+
UPLOAD_EXIT_CODE=$?
161+
162+
echo "Backup finished with status: ${PIPELINE_STATUS[*]} Upload: ${UPLOAD_EXIT_CODE}"
149163
echo "DEBUG FILES GENERATED:"
150164
echo "1. Stderr Log: /tmp/dump_stderr.log"
151165
echo "2. Raw Dump: /tmp/raw_dump.sql"
@@ -158,6 +172,6 @@ else
158172
sleep 500
159173

160174

161-
[[ ${PIPELINE_STATUS[0]} != 0 || ${PIPELINE_STATUS[1]} != 0 || ${PIPELINE_STATUS[2]} != 0 || ${PIPELINE_STATUS[3]} != 0 ]] && (( ERRORCOUNT += 1 ))
175+
[[ ${PIPELINE_STATUS[0]} != 0 || ${PIPELINE_STATUS[1]} != 0 || ${PIPELINE_STATUS[2]} != 0 || ${UPLOAD_EXIT_CODE} != 0 ]] && (( ERRORCOUNT += 1 ))
162176
exit $ERRORCOUNT
163177
fi

0 commit comments

Comments
 (0)