hauke96 / GeoNotes

A simple app to create georeferences notes.
GNU General Public License v3.0
55 stars 10 forks source link

Recovering notes from adb backup #96

Closed opk12 closed 1 year ago

opk12 commented 1 year ago

Here's how I recovered the notes from a backup of the app private data directory, in case it can help anyone.

I used it to import 560 notes, some of which contain <>"/, in QGis and OsmAnd. It takes the notes from all categories and does not know about photos.

adb backup  -f backup.ab  de.hauke_stieler.geonotes

wget 'https://raw.githubusercontent.com/lclevy/ab_decrypt/master/ab_decrypt.py'
chmod +x ./ab_decrypt.py
# add shebang at the top
# for debian 11: change `import Crypto` in `import Cryptodome`
# for debian 11: install python3-pycryptodome

# run ab_decrypt.py
# extract the generated tar file

python3

>>> import html, sqlite3, sys
>>> con = sqlite3.connect("/tar output directory/de.hauke_stieler.geonotes/db/geonotes")
>>> cur = con.cursor()
>>> res = cur.execute("select * from notes")
>>> def make_gpx(file=sys.stdout):
...     print("""<?xml version="1.0" encoding="UTF-8"?><gpx version="1.1">""", file=file)
...     count = 0
...     for row in res:
...         # print(row)
...         primary_key, lat, lon, desc, created_at, category = row[0], row[1], row[2], row[3], row[4], row[5]
...         desc_escaped = html.escape(desc, quote=False)
...             # Apparently, this matches (or is close enough to) GeoNotes built-in export feature
...         msg = f"""    <wpt lat="{lat}" lon="{lon}"><name>{primary_key}</name><desc>{desc_escaped}</desc></wpt>"""
...         print(msg, file=file)
...     print("""</gpx>""", file=file)
... 
>>> with open("out.gpx", 'w') as f:
...     make_gpx(f)