Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Load environment variables from the .env file
- export $(grep -v '^#' "$(dirname "$0")/../.env" | xargs)
- ###########################################################################################################################################
- # Variables
- SOURCE_POOL="nas"
- DATASET="immich"
- SNAPSHOT_NAME="daily-$(date +%Y-%m-%d)"
- TELEGRAM_MESSAGE="📢 *Immich Snapshot*%0A%0ASnapshot: $SNAPSHOT_NAME%0A%0A"
- ###########################################################################################################################################
- # Function to accumulate messages
- append_message() {
- local MESSAGE="$1"
- TELEGRAM_MESSAGE+="$MESSAGE%0A"
- }
- # Function to send telegram message
- send_telegram_message() {
- local MESSAGE="$1"
- $TELEGRAM_MESSAGE_SCRIPT "$TELEGRAM_MESSAGE" "$TELEGRAM_ZFS_TOKEN" "$TELEGRAM_ZFS_CHAT_ID"
- }
- ###########################################################################################################################################
- # Record the start time
- START_TIME=$(date +%s)
- ###########################################################################################################################################
- # Create the snapshot and capture output
- SNAPSHOT_OUTPUT=$(zfs snapshot -r "$SOURCE_POOL/$DATASET@$SNAPSHOT_NAME" 2>&1)
- SNAPSHOT_STATUS=$?
- # Check if the command was successful
- if [[ $SNAPSHOT_STATUS -eq 0 ]]; then
- append_message "✅ Snapshot created"
- else
- append_message "❌ Snapshot creation failed"
- fi
- ###########################################################################################################################################
- # Record the end time
- END_TIME=$(date +%s)
- # Calculate total execution time in seconds
- ELAPSED_TIME=$((END_TIME - START_TIME))
- # Convert to minutes and seconds format
- MINUTES=$((ELAPSED_TIME / 60))
- SECONDS=$((ELAPSED_TIME % 60))
- # Append execution time to the message log
- append_message "%0A⏳ Total time: ${MINUTES}m ${SECONDS}s"
- ###########################################################################################################################################
- # Create snapshot output logs to the message log
- if [[ $SNAPSHOT_STATUS -ne 0 ]]; then
- append_message "%0A\`\`\`Error $SNAPSHOT_OUTPUT\`\`\`"
- fi
- ###########################################################################################################################################
- # Send the telegram message
- send_telegram_message
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement