Skip to content

Instantly share code, notes, and snippets.

@rcarmo
Created December 25, 2018 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcarmo/f2a8a14ef5f3d77759555f3fea5e7c37 to your computer and use it in GitHub Desktop.
Save rcarmo/f2a8a14ef5f3d77759555f3fea5e7c37 to your computer and use it in GitHub Desktop.
Backup HomeKit data
export SOURCE?=rcarmo@home.lan:~/.config/
export TARGET?=home.lan
export TAG_DATE=`date -u +"%Y%m%d"`
.PHONY: snapshot init
init:
mkdir -p $(TARGET)
git init
snapshot:
rsync --delete-after -rvze ssh $(SOURCE) $(TARGET)
python3 prettyprint.py # pretty print all the JSON files
git add .; git commit -a -m "Snapshot on $(TAG_DATE)"
#!/bin/env python3
from json import loads, dumps
from glob import iglob
for f in iglob("**/*.json", recursive=True):
try:
with open(f, 'r') as h:
data = loads(h.read())
with open(f, 'w') as h:
h.write(dumps(data, sort_keys=True, indent=4))
print(f)
except Exception as e:
print("Could not pretty print {f}: {e}".format(**locals()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment