Skip to content

Commit e05118f

Browse files
alexluongclaude
andcommitted
fix: replace DUMP/RESTORE with HGETALL/HSET in migration script
DUMP/RESTORE fails silently on Dragonfly (and potentially other Redis alternatives) because bash command substitution strips null bytes from the binary payload. Replace with field-by-field HGETALL read loop and HSET, plus a post-copy verification check. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8f36bd0 commit e05118f

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

scripts/issue-680/migrate.sh

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,24 @@ for DEPLOY_ID in "${DEPLOYMENT_IDS[@]}"; do
178178
continue
179179
fi
180180

181-
# Copy the hash
181+
# Copy the hash field by field
182182
dry " COPY $old_key -> $new_key"
183183
if ! $DRY_RUN; then
184-
# DUMP/RESTORE for exact copy
185-
dump=$(rcli DUMP "$old_key" 2>/dev/null || echo "")
186-
if [[ -n "$dump" ]]; then
187-
rcli RESTORE "$new_key" 0 "$dump" > /dev/null 2>&1 || {
188-
# Fallback: manual hash copy if DUMP/RESTORE fails
189-
fields=$(rcli HGETALL "$old_key" 2>/dev/null)
190-
if [[ -n "$fields" ]]; then
191-
rcli HSET "$new_key" $fields > /dev/null
192-
fi
193-
}
184+
# Read all field-value pairs and write them to the new key
185+
hset_args=()
186+
while IFS= read -r field && IFS= read -r value; do
187+
hset_args+=("$field" "$value")
188+
done < <(rcli HGETALL "$old_key" 2>/dev/null)
189+
190+
if [[ ${#hset_args[@]} -gt 0 ]]; then
191+
rcli HSET "$new_key" "${hset_args[@]}" > /dev/null
192+
else
193+
warn " $old_key has no fields, skipping"
194+
fi
195+
196+
# Verify the copy
197+
if [[ $(rcli EXISTS "$new_key" 2>/dev/null) != "1" ]]; then
198+
warn " FAILED to copy $old_key -> $new_key"
194199
fi
195200
fi
196201
done

0 commit comments

Comments
 (0)