From 0497619e67eb0bbc33b33262392964bb5fc6013b Mon Sep 17 00:00:00 2001 From: karuo Date: Mon, 16 Mar 2026 02:51:54 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=84=20=E5=8D=A1=E8=8B=A5AI=20=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=202026-03-16=2002:51=20|=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=EF=BC=9A=E9=87=91=E4=BB=93=E3=80=81=E8=BF=90=E8=90=A5=E4=B8=AD?= =?UTF-8?q?=E6=9E=A2=E5=B7=A5=E4=BD=9C=E5=8F=B0=20|=20=E6=8E=92=E9=99=A4?= =?UTF-8?q?=20>20MB:=2011=20=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../金仓_存储备份/群晖NAS管理/SKILL.md | 9 ++ .../scripts/com.karuo.time_machine_home_auto.plist | 21 ++++ .../群晖NAS管理/scripts/time_machine_home_auto.sh | 111 ++++++++++++++++++ 运营中枢/工作台/gitea_push_log.md | 1 + 运营中枢/工作台/代码管理.md | 1 + 5 files changed, 143 insertions(+) create mode 100644 01_卡资(金)/金仓_存储备份/群晖NAS管理/scripts/com.karuo.time_machine_home_auto.plist create mode 100755 01_卡资(金)/金仓_存储备份/群晖NAS管理/scripts/time_machine_home_auto.sh diff --git a/01_卡资(金)/金仓_存储备份/群晖NAS管理/SKILL.md b/01_卡资(金)/金仓_存储备份/群晖NAS管理/SKILL.md index d5c5ecbc..6a325c74 100644 --- a/01_卡资(金)/金仓_存储备份/群晖NAS管理/SKILL.md +++ b/01_卡资(金)/金仓_存储备份/群晖NAS管理/SKILL.md @@ -679,6 +679,14 @@ ssh nas "netstat -tlnp | grep 27017" - **验证**:再次运行上面的 `time_machine_diskstation_auto.sh`,确认网络与端口正常;在系统设置中确认红点消失或显示「正在备份」。 - **更新 Skill**:若本次通过某一步(如 DSM 某选项、Mac 重选磁盘)解决问题,将该要点**追加**到 `参考资料/Time_Machine_DiskStation_错误排查.md` 或本小节,便于下次全自动/半自动复用。 +### 4. 回家自动挂载并触发备份 + +- 适用:用户一回家连上家里网络,就希望 Time Machine 自动备份到 `DiskStation.local / Backup`。 +- 脚本:`scripts/time_machine_home_auto.sh` +- 机制:每 10 分钟检查一次;若能连通 `192.168.110.29`,会先挂载 `Backup` 共享,清理多余的 `*.sparsebundle`(仅保留最大的一个),再执行 `tmutil startbackup --auto`。 +- LaunchAgent:`scripts/com.karuo.time_machine_home_auto.plist` +- 安装后无需手动点系统设置;前提是 **Time Machine 目标已经配置为家里 NAS**。 + ### 家里 NAS 速查(Time Machine 用) | 项目 | 值 | @@ -730,6 +738,7 @@ ssh nas "netstat -tlnp | grep 27017" | 脚本 | 功能 | 位置 | 快速运行 | |------|------|------|----------| | `time_machine_diskstation_auto.sh` | Time Machine → 家里 DiskStation 检测/验证,输出材料路径供按参考资料处理 | `./scripts/` | `./scripts/time_machine_diskstation_auto.sh` | +| `time_machine_home_auto.sh` | 回到家自动挂载 `Backup` 并触发 Time Machine 备份 | `./scripts/` | `./scripts/time_machine_home_auto.sh` | | `mount_diskstation_1tb.sh` | 家里 NAS 约 1TB 备份盘挂载到 Mac(内网优先),当硬盘用 + 时间机器 | `./scripts/` | `./scripts/mount_diskstation_1tb.sh` | | `export_macos_vm_to_downloads.sh` | CKB NAS 上 macOS VM 打包下载到本机「下载」文件夹,实时显示大小与用时,并生成使用说明 | `./scripts/` | 见下方「macOS VM 导出到本机」 | | `optimize_macos_vm_compose.sh` | 本机→NAS:macOS VM 流畅度优化 | `./scripts/` | 需本机与 NAS 同网 | diff --git a/01_卡资(金)/金仓_存储备份/群晖NAS管理/scripts/com.karuo.time_machine_home_auto.plist b/01_卡资(金)/金仓_存储备份/群晖NAS管理/scripts/com.karuo.time_machine_home_auto.plist new file mode 100644 index 00000000..49a6c58d --- /dev/null +++ b/01_卡资(金)/金仓_存储备份/群晖NAS管理/scripts/com.karuo.time_machine_home_auto.plist @@ -0,0 +1,21 @@ + + + + + Label + com.karuo.time_machine_home_auto + ProgramArguments + + /bin/bash + /Users/karuo/Documents/个人/卡若AI/01_卡资(金)/金仓_存储备份/群晖NAS管理/scripts/time_machine_home_auto.sh + + RunAtLoad + + StartInterval + 600 + StandardOutPath + /tmp/time_machine_home_auto.log + StandardErrorPath + /tmp/time_machine_home_auto.err + + diff --git a/01_卡资(金)/金仓_存储备份/群晖NAS管理/scripts/time_machine_home_auto.sh b/01_卡资(金)/金仓_存储备份/群晖NAS管理/scripts/time_machine_home_auto.sh new file mode 100755 index 00000000..ccf5c0ec --- /dev/null +++ b/01_卡资(金)/金仓_存储备份/群晖NAS管理/scripts/time_machine_home_auto.sh @@ -0,0 +1,111 @@ +#!/bin/bash +# ============================================ +# 回到家自动触发 Time Machine 到家里 NAS +# 逻辑: +# 1. 仅在能访问 192.168.110.29 时执行 +# 2. 确保 Backup 共享已挂载 +# 3. 若 Time Machine 未在运行,则触发自动备份 +# ============================================ + +set -u +shopt -s nullglob + +NAS_IP="${DISKSTATION_IP:-192.168.110.29}" +NAS_USER="${DISKSTATION_USER:-admin}" +NAS_PASS="${DISKSTATION_PASS:-zhiqun1984}" +TM_SHARE="${TM_SHARE:-Backup}" +MOUNT_POINT="$HOME/DiskStation-TimeMachine" +LOG_PREFIX="[tm-home-auto]" + +log() { + echo "$LOG_PREFIX $1" +} + +is_nas_online() { + python3 - "$NAS_IP" <<'PY' +import socket +import sys + +host = sys.argv[1] +for port in (445, 5000): + try: + sock = socket.create_connection((host, port), timeout=2) + sock.close() + sys.exit(0) + except OSError: + pass +sys.exit(1) +PY +} + +cleanup_extra_sparsebundles() { + local bundles=("$MOUNT_POINT"/*.sparsebundle) + local keep_bundle="" + local keep_size=0 + local size=0 + local bundle="" + + if [ "${#bundles[@]}" -le 1 ]; then + log "备份卷内无需清理,sparsebundle 数量: ${#bundles[@]}" + return 0 + fi + + for bundle in "${bundles[@]}"; do + size="$(du -sk "$bundle" 2>/dev/null | awk '{print $1}')" + size="${size:-0}" + if [ "$size" -gt "$keep_size" ]; then + keep_size="$size" + keep_bundle="$bundle" + fi + done + + log "保留最大备份: $(basename "$keep_bundle") (${keep_size} KB)" + for bundle in "${bundles[@]}"; do + if [ "$bundle" != "$keep_bundle" ]; then + log "删除多余备份: $(basename "$bundle")" + rm -rf "$bundle" + fi + done +} + +if ! command -v tmutil >/dev/null 2>&1; then + log "tmutil 不可用,跳过" + exit 0 +fi + +if ! is_nas_online; then + log "未检测到家里 NAS 在线,跳过" + exit 0 +fi + +mkdir -p "$MOUNT_POINT" + +if ! mount | grep -q "$MOUNT_POINT"; then + log "挂载家里 NAS 的 Time Machine 共享" + mount_smbfs "//${NAS_USER}:${NAS_PASS}@${NAS_IP}/${TM_SHARE}" "$MOUNT_POINT" >/dev/null 2>&1 || { + log "挂载失败,请检查共享名/密码/SMB" + exit 1 + } +fi + +cleanup_extra_sparsebundles + +DEST_INFO="$(tmutil destinationinfo 2>/dev/null || true)" +if ! printf '%s' "$DEST_INFO" | grep -qiE "DiskStation|${NAS_IP}|${TM_SHARE}"; then + log "当前未检测到家里 NAS 为 Time Machine 目标" + exit 1 +fi + +CURRENT_PHASE="$(tmutil currentphase 2>/dev/null || true)" +if printf '%s' "$CURRENT_PHASE" | grep -q "BackupNotRunning"; then + log "触发 Time Machine 自动备份" + tmutil startbackup --auto >/dev/null 2>&1 || { + log "启动备份失败" + exit 1 + } + log "已发起备份" +else + log "Time Machine 正在运行:$CURRENT_PHASE" +fi + +exit 0 diff --git a/运营中枢/工作台/gitea_push_log.md b/运营中枢/工作台/gitea_push_log.md index 252cb16a..ef083a67 100644 --- a/运营中枢/工作台/gitea_push_log.md +++ b/运营中枢/工作台/gitea_push_log.md @@ -370,3 +370,4 @@ | 2026-03-16 00:21:12 | 🔄 卡若AI 同步 2026-03-16 00:21 | 更新:运营中枢参考资料、运营中枢工作台 | 排除 >20MB: 11 个 | | 2026-03-16 01:50:39 | 🔄 卡若AI 同步 2026-03-16 01:50 | 更新:运营中枢参考资料、运营中枢工作台 | 排除 >20MB: 11 个 | | 2026-03-16 02:05:00 | 🔄 卡若AI 同步 2026-03-16 02:04 | 更新:卡木、火炬、运营中枢、运营中枢参考资料、运营中枢工作台 | 排除 >20MB: 11 个 | +| 2026-03-16 02:05:26 | 🔄 卡若AI 同步 2026-03-16 02:05 | 更新:火炬、运营中枢工作台 | 排除 >20MB: 11 个 | diff --git a/运营中枢/工作台/代码管理.md b/运营中枢/工作台/代码管理.md index 106e61da..cdb717d6 100644 --- a/运营中枢/工作台/代码管理.md +++ b/运营中枢/工作台/代码管理.md @@ -373,3 +373,4 @@ | 2026-03-16 00:21:12 | 成功 | 成功 | 🔄 卡若AI 同步 2026-03-16 00:21 | 更新:运营中枢参考资料、运营中枢工作台 | 排除 >20MB: 11 个 | [仓库](http://open.quwanzhi.com:3000/fnvtk/karuo-ai) [百科](http://open.quwanzhi.com:3000/fnvtk/karuo-ai/wiki) | | 2026-03-16 01:50:39 | 成功 | 成功 | 🔄 卡若AI 同步 2026-03-16 01:50 | 更新:运营中枢参考资料、运营中枢工作台 | 排除 >20MB: 11 个 | [仓库](http://open.quwanzhi.com:3000/fnvtk/karuo-ai) [百科](http://open.quwanzhi.com:3000/fnvtk/karuo-ai/wiki) | | 2026-03-16 02:05:00 | 成功 | 成功 | 🔄 卡若AI 同步 2026-03-16 02:04 | 更新:卡木、火炬、运营中枢、运营中枢参考资料、运营中枢工作台 | 排除 >20MB: 11 个 | [仓库](http://open.quwanzhi.com:3000/fnvtk/karuo-ai) [百科](http://open.quwanzhi.com:3000/fnvtk/karuo-ai/wiki) | +| 2026-03-16 02:05:26 | 成功 | 成功 | 🔄 卡若AI 同步 2026-03-16 02:05 | 更新:火炬、运营中枢工作台 | 排除 >20MB: 11 个 | [仓库](http://open.quwanzhi.com:3000/fnvtk/karuo-ai) [百科](http://open.quwanzhi.com:3000/fnvtk/karuo-ai/wiki) |