feat: add Feishu webhook notification for backups
- Include a webhook URL to send notifications after backups. - Capture and log the duration and size of the backups. - Create a new Kubernetes secret for storing the Feishu webhook URL. - Enhance the backup script to notify users of backup success with details. This change improves monitoring and user notification of backup events, allowing for better awareness and response times in case of failure or success of the backup processes.
This commit is contained in:
parent
6d2acdcd1e
commit
1203a57641
@ -20,6 +20,9 @@ data:
|
||||
HOSTNAME=$(hostname)
|
||||
HOSTNAME="${NODE_NAME:-$HOSTNAME}"
|
||||
|
||||
FEISHU_WEBHOOK_URL=$(cat /etc/feishu-webhook/url)
|
||||
|
||||
START_TIME=$(date +%s)
|
||||
|
||||
# 配置 s3cmd
|
||||
cat > ~/.s3cfg << EOF
|
||||
@ -52,6 +55,7 @@ data:
|
||||
BACKUP_NAME="backup-${DIR_NAME}-${TIMESTAMP}.tar.gz"
|
||||
TEMP_DIR=$(mktemp -d)
|
||||
BACKUP_PATH="/tmp/${BACKUP_NAME}"
|
||||
SOURCE_SIZE=$(du -sh /data/local-csi | cut -f1)
|
||||
|
||||
echo "正在备份目录: $dir"
|
||||
|
||||
@ -95,8 +99,20 @@ data:
|
||||
fi
|
||||
done
|
||||
|
||||
END_TIME=$(date +%s)
|
||||
echo "备份完成"
|
||||
|
||||
DURATION=$((END_TIME - START_TIME))
|
||||
MSG_TITLE="✅ [K3s Backup] $NODE_NAME Backup Success"
|
||||
MSG_TEXT="Host: $NODE_NAME\nSource: /data\nSource Size: $SOURCE_SIZE\nDuration: ${DURATION}s"
|
||||
JSON_PAYLOAD=$(jq -n \
|
||||
--arg title "$MSG_TITLE" \
|
||||
--arg text "$MSG_TEXT" \
|
||||
'{msg_type: "post", content: {post: {zh_cn: {title: $title, content: [[{tag: "text", text: $text}]]}}}}')
|
||||
echo "Sending notification to Feishu..."
|
||||
curl -X POST -H "Content-Type: application/json" -d "$JSON_PAYLOAD" "$FEISHU_WEBHOOK_URL"
|
||||
echo "Notification sent."
|
||||
|
||||
s3cmd-trigger.sh: |
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
@ -98,6 +98,9 @@ spec:
|
||||
mountPath: /data
|
||||
- name: scripts
|
||||
mountPath: /scripts
|
||||
- name: feishu-webhook-volume
|
||||
mountPath: /etc/feishu-webhook # 挂载飞书 Webhook Secret
|
||||
readOnly: true
|
||||
volumes:
|
||||
- name: host-data
|
||||
hostPath:
|
||||
@ -106,3 +109,6 @@ spec:
|
||||
configMap:
|
||||
name: backup-script
|
||||
defaultMode: 0755
|
||||
- name: feishu-webhook-volume
|
||||
secret:
|
||||
secretName: feishu-webhook
|
||||
|
9
backups/daemonset+cronjob/secret-feishu-webhook.yaml
Normal file
9
backups/daemonset+cronjob/secret-feishu-webhook.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
apiVersion: v1
|
||||
data:
|
||||
# https://open.feishu.cn/open-apis/bot/v2/hook/f2a8d634-6a90-4f86-ac2f-ef6a53dbd680
|
||||
url: aHR0cHM6Ly9vcGVuLmZlaXNodS5jbi9vcGVuLWFwaXMvYm90L3YyL2hvb2svZjJhOGQ2MzQtNmE5MC00Zjg2LWFjMmYtZWY2YTUzZGJkNjgw
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: feishu-webhook
|
||||
namespace: backup-system
|
||||
type: Opaque
|
@ -10,4 +10,6 @@ data:
|
||||
access-key: RVZuWFViR2xld2t0dFF0em9XUWs= # EVnXUbGlewkttQtzoWQk
|
||||
secret-key: THNxVFRmc0VEVzBFY3Buc09aOUxyTnhwc21zajdIMGxlR2R0WHBwRg== # LsqTTfsEDW0EcpnsOZ9LrNxpsmsj7H0leGdtXppF
|
||||
bucket: YmFja3Vwcw== # backups
|
||||
# https://open.feishu.cn/open-apis/bot/v2/hook/f2a8d634-6a90-4f86-ac2f-ef6a53dbd680
|
||||
#feishu-webhook: aHR0cHM6Ly9vcGVuLmZlaXNodS5jbi9vcGVuLWFwaXMvYm90L3YyL2hvb2svZjJhOGQ2MzQtNmE5MC00Zjg2LWFjMmYtZWY2YTUzZGJkNjgw
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user