-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: DEVOPS-1781 persistence export cron job for checkpoint node (#2079
) * feat: DEVOPS-1781 persistence export cron job for checkpoint node * feat: DEVOPS-1781 persistence export functions * feat: DEVOPS-1781 persistence export folder instead of zip file
- Loading branch information
Showing
2 changed files
with
119 additions
and
8 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,57 @@ | ||
#!/bin/bash | ||
|
||
# Directory where checkpoint files are located | ||
CHECKPOINT_DIR="/data/{{ eth_chain_id }}/checkpoints" | ||
|
||
# GCS bucket where the persistence will be exported | ||
GCS_BUCKET="gs://{{ network_name }}-persistence" | ||
|
||
# Log name in Google Cloud Logging | ||
LOG_NAME="{{ network_name }}-persistence-export-cron-log" | ||
|
||
# Function to log messages to Google Cloud Logging | ||
log_message() { | ||
local message="$1" | ||
logger -t "$LOG_NAME" "$message" | ||
} | ||
|
||
# Function to check if directory is empty | ||
is_dir_empty() { | ||
local dir="$1" | ||
[ -z "$(ls -A $dir)" ] | ||
} | ||
|
||
# Start the persistence export process | ||
start_time=$(date +%s) | ||
|
||
if is_dir_empty "$CHECKPOINT_DIR"; then | ||
# Stop zilliqa service | ||
if ! sudo systemctl stop zilliqa.service; then | ||
log_message "Error: Failed to stop zilliqa service" | ||
exit 1 | ||
fi | ||
|
||
# Create persistence export folder name with timestamp | ||
persistence_export_name="{{ network_name }}-$(date +%Y%m%d%H%M%S)-persistence" | ||
log_message "Creating persistence export: $persistence_export_name" | ||
|
||
# Upload to GCS | ||
if ! gsutil -m cp -r /data "$GCS_BUCKET/$persistence_export_name/"; then | ||
log_message "Error: Failed to upload data to GCS" | ||
sudo systemctl start zilliqa.service | ||
exit 1 | ||
fi | ||
|
||
# Start zilliqa service | ||
if ! sudo systemctl start zilliqa.service; then | ||
log_message "Error: Failed to start zilliqa service" | ||
exit 1 | ||
fi | ||
|
||
# Calculate and log total execution time | ||
end_time=$(date +%s) | ||
duration=$((end_time - start_time)) | ||
log_message "Persistence export completed successfully in $duration seconds" | ||
else | ||
log_message "Checkpoint files present in $CHECKPOINT_DIR. Skipping persistence export." | ||
fi |
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