Updated to include backupdir with copyto function, and lock logic

This commit is contained in:
2026-02-28 01:46:24 -06:00
parent 08bed91465
commit 470a716bbb

View File

@@ -2,7 +2,7 @@
#shellcheck shell=dash
#
event_data=$(cat /tmp/es_state.inf | tr -d '\r' )
event_data=$(cat /tmp/es_state.inf | tr -d '\r')
export LOG_FILE="/recalbox/share/system/logs/savesync.log"
REMOTE_BASE="saves:gamepi-tv"
#DEBUG=1
@@ -10,7 +10,7 @@ REMOTE_BASE="saves:gamepi-tv"
log() {
# $1 = level
# $2 = message
printf "[%s] %s\n" "$(date '+%Y-%m-%d %H:%M:%S')" "$1" >>"$LOG_FILE"
printf "[%s] [%s] %s\n" "$(date '+%Y-%m-%d %H:%M:%S')" "$1" "$2" >>"$LOG_FILE"
}
#log "DEBUG" "Starting based on event: $(echo "$event_data" | tr '\n' ',')"
@@ -44,15 +44,23 @@ echo "$event_data" | while IFS='=' read -r k v; do
log "INFO" "Sync START: $(basename "$gp")"
remote_f="$REMOTE_BASE/$sid/$(basename "$sp")"
#log "DEBUG" "rclone update $remote_f $sp"
find "$sp" -size -256 -delete
rclone update "$remote_f" "$(dirname "$sp")"
log "INFO" "Start sync done"
if [ -f "${sp}.lock" ]; then
log "WARN" "${sp}.lock exists, please check which version you have synced"
else
mkdir -p "$bp"
rclone copyto "$remote_f" "$sp" --backup-dir "$bp" && log "INFO" "Save synced successfully"
fi
log "INFO" "Start sync for $(basename "$sp") done"
elif [ "$act" = "endgame" ]; then
log "INFO" "Sync END: $(basename "$sp")"
#log "DEBUG" "rclone update $sp $REMOTE_BASE/$sid/"
find "$sp" -size -256 -delete
rclone update "$sp" "$REMOTE_BASE/$sid/"
log "INFO" "Final Sync Done."
if [ ! "$(rclone update "$sp" "$REMOTE_BASE/$sid/")" ]; then
log "INFO" "Final Sync Done."
else
touch "${sp}.lock"
log "WARN" "Lockfile created, save could not be synced"
fi
fi
;;
esac