Commit ·
88c5bc9
1
Parent(s): 9b35ec3
Enable two-way root data sync
Browse files- start.sh +1 -1
- sync-root-data.sh +32 -3
start.sh
CHANGED
|
@@ -203,7 +203,7 @@ else:
|
|
| 203 |
path.write_text(json.dumps(data, indent=2) + '\n')
|
| 204 |
PY
|
| 205 |
|
| 206 |
-
/app/sync-root-data.sh
|
| 207 |
|
| 208 |
/app/sync-root-data.sh loop &
|
| 209 |
|
|
|
|
| 203 |
path.write_text(json.dumps(data, indent=2) + '\n')
|
| 204 |
PY
|
| 205 |
|
| 206 |
+
/app/sync-root-data.sh reconcile
|
| 207 |
|
| 208 |
/app/sync-root-data.sh loop &
|
| 209 |
|
sync-root-data.sh
CHANGED
|
@@ -3,6 +3,7 @@ set -euo pipefail
|
|
| 3 |
|
| 4 |
DATA_ROOT="${DATA_ROOT:-/data/root}"
|
| 5 |
SYNC_INTERVAL="${SYNC_INTERVAL:-300}"
|
|
|
|
| 6 |
|
| 7 |
EXCLUDES=(
|
| 8 |
"--exclude=.cache"
|
|
@@ -25,7 +26,7 @@ data_available() {
|
|
| 25 |
restore_root() {
|
| 26 |
if data_available; then
|
| 27 |
echo "Restoring persistent data from $DATA_ROOT to /root..."
|
| 28 |
-
rsync -rlptD --no-specials --no-devices "${EXCLUDES[@]}" "$DATA_ROOT/" /root/ || true
|
| 29 |
else
|
| 30 |
echo "Persistent /data is not available; skipping restore."
|
| 31 |
fi
|
|
@@ -34,12 +35,37 @@ restore_root() {
|
|
| 34 |
persist_root() {
|
| 35 |
if data_available; then
|
| 36 |
echo "Syncing /root to $DATA_ROOT..."
|
| 37 |
-
rsync -rlptD --no-specials --no-devices --delete "${EXCLUDES[@]}" /root/ "$DATA_ROOT/" || true
|
| 38 |
else
|
| 39 |
echo "Persistent /data is not available; skipping sync."
|
| 40 |
fi
|
| 41 |
}
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
case "${1:-loop}" in
|
| 44 |
restore)
|
| 45 |
restore_root
|
|
@@ -47,9 +73,12 @@ case "${1:-loop}" in
|
|
| 47 |
persist)
|
| 48 |
persist_root
|
| 49 |
;;
|
|
|
|
|
|
|
|
|
|
| 50 |
loop)
|
| 51 |
while true; do
|
| 52 |
-
|
| 53 |
sleep "$SYNC_INTERVAL"
|
| 54 |
done
|
| 55 |
;;
|
|
|
|
| 3 |
|
| 4 |
DATA_ROOT="${DATA_ROOT:-/data/root}"
|
| 5 |
SYNC_INTERVAL="${SYNC_INTERVAL:-300}"
|
| 6 |
+
CONFIG_PATH=".openclaw/openclaw.json"
|
| 7 |
|
| 8 |
EXCLUDES=(
|
| 9 |
"--exclude=.cache"
|
|
|
|
| 26 |
restore_root() {
|
| 27 |
if data_available; then
|
| 28 |
echo "Restoring persistent data from $DATA_ROOT to /root..."
|
| 29 |
+
rsync -rlptD --no-specials --no-devices --update "${EXCLUDES[@]}" "$DATA_ROOT/" /root/ || true
|
| 30 |
else
|
| 31 |
echo "Persistent /data is not available; skipping restore."
|
| 32 |
fi
|
|
|
|
| 35 |
persist_root() {
|
| 36 |
if data_available; then
|
| 37 |
echo "Syncing /root to $DATA_ROOT..."
|
| 38 |
+
rsync -rlptD --no-specials --no-devices --update --delete "${EXCLUDES[@]}" /root/ "$DATA_ROOT/" || true
|
| 39 |
else
|
| 40 |
echo "Persistent /data is not available; skipping sync."
|
| 41 |
fi
|
| 42 |
}
|
| 43 |
|
| 44 |
+
sync_config_newer() {
|
| 45 |
+
local root_config="/root/$CONFIG_PATH"
|
| 46 |
+
local data_config="$DATA_ROOT/$CONFIG_PATH"
|
| 47 |
+
|
| 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 from $data_config to $root_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 from $root_config to $data_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
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
case "${1:-loop}" in
|
| 70 |
restore)
|
| 71 |
restore_root
|
|
|
|
| 73 |
persist)
|
| 74 |
persist_root
|
| 75 |
;;
|
| 76 |
+
reconcile)
|
| 77 |
+
reconcile_root_data
|
| 78 |
+
;;
|
| 79 |
loop)
|
| 80 |
while true; do
|
| 81 |
+
reconcile_root_data
|
| 82 |
sleep "$SYNC_INTERVAL"
|
| 83 |
done
|
| 84 |
;;
|