Skip to content

Added Checksum #20

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

Merged
merged 2 commits into from
Mar 12, 2025
Merged
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
28 changes: 28 additions & 0 deletions application/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ else
log "INFO" "${MYNAME}: Backup of ${DB_NAME} completed in $(expr ${end} - ${start}) seconds, ($(stat -c %s /tmp/${DB_NAME}.sql) bytes).";
fi

log "INFO" "Generating checksum for backup file"
cd /tmp || {
error_message="${MYNAME}: FATAL: Failed to change directory to /tmp";
log "ERROR" "${error_message}";
error_to_sentry "${error_message}" "${DB_NAME}" "1";
exit 1;
}

# Create checksum file format
sha256sum "${DB_NAME}.sql" > "${DB_NAME}.sql.sha256" || {
error_message="${MYNAME}: FATAL: Failed to generate checksum for backup of ${DB_NAME}";
log "ERROR" "${error_message}";
error_to_sentry "${error_message}" "${DB_NAME}" "1";
exit 1;
}

# Compression
start=$(date +%s);
gzip -f /tmp/${DB_NAME}.sql || STATUS=$?;
Expand All @@ -72,6 +88,18 @@ else
log "INFO" "${MYNAME}: Compressing backup of ${DB_NAME} completed in $(expr ${end} - ${start}) seconds.";
fi

# Validate checksum
log "INFO" "Validating backup checksum"
# Optional: Added this line for debug
log "DEBUG" "Checksum file contents: $(cat "${DB_NAME}.sql.sha256")"

sha256sum -c "${DB_NAME}.sql.sha256" || {
error_message="${MYNAME}: FATAL: Checksum validation failed for backup of ${DB_NAME}";
log "ERROR" "${error_message}";
error_to_sentry "${error_message}" "${DB_NAME}" "1";
exit 1;
}

# S3 Upload
start=$(date +%s);
s3cmd put /tmp/${DB_NAME}.sql.gz ${S3_BUCKET} || STATUS=$?;
Expand Down