Skip to content

Instantly share code, notes, and snippets.

@Cactiw
Created December 17, 2022 21:47
Show Gist options
  • Save Cactiw/c2397561966e2f343b0563a6c5b7f17f to your computer and use it in GitHub Desktop.
Save Cactiw/c2397561966e2f343b0563a6c5b7f17f to your computer and use it in GitHub Desktop.
This is quick fix for sentry generated backup.json file.
import json
FILENAME = "backup.json"
FILENAME_FIXED = "backup_fixed.json"
def restore():
with open(FILENAME, "r") as f:
lines = f.readlines()
lines = lines[lines.index('[\n'):]
with open(FILENAME_FIXED, "w") as f:
f.writelines(lines)
with open(FILENAME_FIXED, "r") as f:
data = json.load(f)
for d in data:
value = d.get("fields", {}).get("value")
if value is not None and not isinstance(value, str):
d["fields"]["value"] = str(value)
with open(FILENAME_FIXED, "w") as f:
f.write(json.dumps(data, indent=4, ensure_ascii=False))
return data
if __name__ == "__main__":
restore()
@matthewbyrne
Copy link

@Lucaber , my adapted script above should be of help if you have your original exported backup.

@Lucaber
Copy link

Lucaber commented Feb 1, 2023

If i remember correctly, numbers were also saved incorrectly as base64 encoded strings with quotes. 8 -> "8" | base64.
This resulted in broken "sentry:option-epoch" options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment