44 lines
1.2 KiB
Bash
Executable File
44 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
||
# zq 工作区同步脚本
|
||
# 流程:NAS pull → Git commit/push(Gitea备份)→ NAS push
|
||
|
||
ZQ_DIR="$HOME/work/zq"
|
||
LOG_FILE="$HOME/work/zq-sync.log"
|
||
DATE=$(date '+%Y-%m-%d %H:%M:%S')
|
||
|
||
log() {
|
||
echo "[$DATE] $1" >> "$LOG_FILE"
|
||
}
|
||
|
||
log "========== 开始同步 =========="
|
||
|
||
cd "$ZQ_DIR" || exit 1
|
||
|
||
# 1. 从 NAS WebDAV 拉取最新内容
|
||
log "1. 从 NAS 拉取更新..."
|
||
rclone sync "nas-webdav:/home/Drive/工作区/张青/工作区/" "$ZQ_DIR/" \
|
||
--exclude ".git/" \
|
||
--exclude ".gitignore" \
|
||
--log-level INFO >> "$LOG_FILE" 2>&1
|
||
|
||
# 2. 检查是否有变更,有则提交到 Git(推送到 Gitea 备份)
|
||
CHANGES=$(git status --porcelain)
|
||
|
||
if [ -n "$CHANGES" ]; then
|
||
log "2. 检测到变更,提交到 Gitea..."
|
||
git add -A
|
||
git commit -m "自动备份: $DATE" >> "$LOG_FILE" 2>&1
|
||
git push origin main >> "$LOG_FILE" 2>&1
|
||
else
|
||
log "2. 没有变更,跳过 Git 提交。"
|
||
fi
|
||
|
||
# 3. 同步回 NAS
|
||
log "3. 同步回 NAS..."
|
||
rclone sync "$ZQ_DIR/" "nas-webdav:/home/Drive/工作区/张青/工作区/" \
|
||
--exclude ".git/" \
|
||
--exclude ".gitignore" \
|
||
--log-level INFO >> "$LOG_FILE" 2>&1
|
||
|
||
log "========== 同步完成 =========="
|