Created
December 25, 2018 16:38
-
-
Save rcarmo/f2a8a14ef5f3d77759555f3fea5e7c37 to your computer and use it in GitHub Desktop.
Backup HomeKit data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export [email protected]:~/.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)" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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