Spaces:
Running
Running
Update sync-root-data.sh
Browse files- sync-root-data.sh +24 -14
sync-root-data.sh
CHANGED
|
@@ -23,21 +23,23 @@ data_available() {
|
|
| 23 |
mkdir -p "$DATA_ROOT" 2>/dev/null || return 1
|
| 24 |
}
|
| 25 |
|
| 26 |
-
|
|
|
|
| 27 |
if data_available; then
|
| 28 |
-
echo "
|
| 29 |
-
rsync -rlptD --no-specials --no-devices --update "${EXCLUDES[@]}" "$DATA_ROOT/"
|
| 30 |
else
|
| 31 |
-
echo "Persistent /data is not available; skipping
|
| 32 |
fi
|
| 33 |
}
|
| 34 |
|
| 35 |
-
|
|
|
|
| 36 |
if data_available; then
|
| 37 |
-
echo "
|
| 38 |
-
rsync -rlptD --no-specials --no-devices
|
| 39 |
else
|
| 40 |
-
echo "Persistent /data is not available; skipping
|
| 41 |
fi
|
| 42 |
}
|
| 43 |
|
|
@@ -48,19 +50,27 @@ sync_config_newer() {
|
|
| 48 |
if [ -f "$data_config" ] && { [ ! -f "$root_config" ] || [ "$data_config" -nt "$root_config" ]; }; then
|
| 49 |
mkdir -p "$(dirname "$root_config")"
|
| 50 |
cp -p "$data_config" "$root_config" || true
|
| 51 |
-
echo "Pulled newer OpenClaw config
|
| 52 |
elif [ -f "$root_config" ] && { [ ! -f "$data_config" ] || [ "$root_config" -nt "$data_config" ]; }; then
|
| 53 |
mkdir -p "$(dirname "$data_config")"
|
| 54 |
cp -p "$root_config" "$data_config" || true
|
| 55 |
-
echo "Persisted newer OpenClaw config
|
| 56 |
fi
|
| 57 |
}
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
reconcile_root_data() {
|
| 60 |
if data_available; then
|
| 61 |
-
restore_root
|
| 62 |
-
sync_config_newer
|
| 63 |
persist_root
|
|
|
|
|
|
|
| 64 |
else
|
| 65 |
echo "Persistent /data is not available; skipping two-way sync."
|
| 66 |
fi
|
|
@@ -83,7 +93,7 @@ case "${1:-loop}" in
|
|
| 83 |
done
|
| 84 |
;;
|
| 85 |
*)
|
| 86 |
-
echo "Usage: $0 {restore|persist|loop}"
|
| 87 |
exit 2
|
| 88 |
;;
|
| 89 |
-
esac
|
|
|
|
| 23 |
mkdir -p "$DATA_ROOT" 2>/dev/null || return 1
|
| 24 |
}
|
| 25 |
|
| 26 |
+
# /root → /data (--update: hanya file lebih baru di root yg masuk data)
|
| 27 |
+
persist_root() {
|
| 28 |
if data_available; then
|
| 29 |
+
echo "Syncing /root → $DATA_ROOT (update: root wins if newer)..."
|
| 30 |
+
rsync -rlptD --no-specials --no-devices --update --delete "${EXCLUDES[@]}" /root/ "$DATA_ROOT/" || true
|
| 31 |
else
|
| 32 |
+
echo "Persistent /data is not available; skipping persist."
|
| 33 |
fi
|
| 34 |
}
|
| 35 |
|
| 36 |
+
# /data → /root (FORCE: data selalu menang, tanpa --update)
|
| 37 |
+
restore_root() {
|
| 38 |
if data_available; then
|
| 39 |
+
echo "Restoring $DATA_ROOT → /root (force: data always wins)..."
|
| 40 |
+
rsync -rlptD --no-specials --no-devices "${EXCLUDES[@]}" "$DATA_ROOT/" /root/ || true
|
| 41 |
else
|
| 42 |
+
echo "Persistent /data is not available; skipping restore."
|
| 43 |
fi
|
| 44 |
}
|
| 45 |
|
|
|
|
| 50 |
if [ -f "$data_config" ] && { [ ! -f "$root_config" ] || [ "$data_config" -nt "$root_config" ]; }; then
|
| 51 |
mkdir -p "$(dirname "$root_config")"
|
| 52 |
cp -p "$data_config" "$root_config" || true
|
| 53 |
+
echo "Pulled newer OpenClaw config: $data_config → $root_config"
|
| 54 |
elif [ -f "$root_config" ] && { [ ! -f "$data_config" ] || [ "$root_config" -nt "$data_config" ]; }; then
|
| 55 |
mkdir -p "$(dirname "$data_config")"
|
| 56 |
cp -p "$root_config" "$data_config" || true
|
| 57 |
+
echo "Persisted newer OpenClaw config: $root_config → $data_config"
|
| 58 |
fi
|
| 59 |
}
|
| 60 |
|
| 61 |
+
# Urutan penting:
|
| 62 |
+
# 1. persist → /root → /data (--update, perubahan root masuk data dulu)
|
| 63 |
+
# 2. config → two-way reconcile openclaw.json
|
| 64 |
+
# 3. restore → /data → /root (force, data selalu menang sebagai sumber kebenaran)
|
| 65 |
+
#
|
| 66 |
+
# Efeknya:
|
| 67 |
+
# - Root berubah → masuk data di step 1, restore step 3 no-op (sudah sama) ✓
|
| 68 |
+
# - Data berubah → step 1 tidak tumpuk data (--update), step 3 force ke root ✓
|
| 69 |
reconcile_root_data() {
|
| 70 |
if data_available; then
|
|
|
|
|
|
|
| 71 |
persist_root
|
| 72 |
+
sync_config_newer
|
| 73 |
+
restore_root
|
| 74 |
else
|
| 75 |
echo "Persistent /data is not available; skipping two-way sync."
|
| 76 |
fi
|
|
|
|
| 93 |
done
|
| 94 |
;;
|
| 95 |
*)
|
| 96 |
+
echo "Usage: $0 {restore|persist|reconcile|loop}"
|
| 97 |
exit 2
|
| 98 |
;;
|
| 99 |
+
esac
|