fix: update backup script for better directory handling

- Change TEMP_DIR to use a more structured temporary path
- Adjust rsync command to reflect the new directory structure
- Improve MSG_TEXT formatting for better clarity
- Add 'jq' to the dependencies for JSON processing

These changes address issues with the previous temporary directory location and enhance the output messages for a more informative backup success notification.
This commit is contained in:
songtianlun 2025-04-22 15:48:17 +08:00
parent 0e56e0e26c
commit e5e9bfd9f3
2 changed files with 6 additions and 5 deletions

View File

@ -53,16 +53,17 @@ data:
DIR_NAME=$(basename "$dir")
TIMESTAMP=$(date +%Y-%m-%d-%H-%M-%S)
BACKUP_NAME="backup-${DIR_NAME}-${TIMESTAMP}.tar.gz"
TEMP_DIR=$(mktemp -d)
TEMP_DIR="/tmp/data/${TIMESTAMP}/"
BACKUP_PATH="/tmp/${BACKUP_NAME}"
SOURCE_SIZE=$(du -sh /data/local-csi | cut -f1)
echo "正在备份目录: $dir"
rsync -a "/data/local-csi/$DIR_NAME/" "$TEMP_DIR/"
mkdir -p "$TEMP_DIR/$DIR_NAME"
rsync -a "/data/local-csi/$DIR_NAME/" "$TEMP_DIR/$DIR_NAME/"
# 创建备份压缩包
# tar -czf "$BACKUP_PATH" -C "/data/local-csi" "$DIR_NAME"
tar -czf "$BACKUP_PATH" -C "/data/local-csi" "$TEMP_DIR"
tar -czf "$BACKUP_PATH" -C "$TEMP_DIR" "$DIR_NAME"
# 清理临时目录
rm -rf "$TEMP_DIR"
@ -104,7 +105,7 @@ data:
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"
MSG_TEXT="Host: $NODE_NAME, Source: /data, Source Size: $SOURCE_SIZE, Duration: ${DURATION}s"
JSON_PAYLOAD=$(jq -n \
--arg title "$MSG_TITLE" \
--arg text "$MSG_TEXT" \

View File

@ -36,7 +36,7 @@ spec:
- -c
- |
# 安装依赖工具
apk add --no-cache bash s3cmd tar rsync curl
apk add --no-cache bash s3cmd tar rsync curl jq
# 启动一个循环,每分钟检查一次触发文件
while true; do