DEV Community

How Apple Notes stores your notes, and how to recover one from a backup by hand

You changed a note, or deleted it, and the 30 days in "Recently Deleted" are over. Notes has no version history, so the only older copy is in a backup. Time Machine and Finder can restore the whole Notes folder, but that replaces everything you have today.

Here is how to open the old copy yourself and pull out just the note you need.

Where Notes keeps its data on a Mac

Everything lives in one SQLite database:

  • ~/Library/Group Containers/group.com.apple.notes/NoteStore.sqlite
  • ~/Library/Group Containers/group.com.apple.notes/NoteStore.sqlite-wal
  • ~/Library/Group Containers/group.com.apple.notes/NoteStore.sqlite-shm

Next to it there is an Accounts/<UUID>/Media folder, which holds attachments such as images and PDFs.

The database runs in WAL mode (PRAGMA journal_mode returns wal). That means recent changes are written to NoteStore.sqlite-wal first and only folded into the main file later, at a checkpoint.

So the rule is simple: always copy all three files together. If you copy only NoteStore.sqlite, you can miss the newest edits, and on my Mac sqlite3 -readonly refused to open a copy without its -shm file at all ("unable to open database file (14)").

Never open the live files while Notes is running, and never edit them. Work on a copy.

Getting the old copy out of a backup

Time Machine. On a current APFS Time Machine disk, each backup is a dated folder, and inside it the path mirrors your disk, something like:

/Volumes/<backup disk>/<date>.backup/<date>/Macintosh HD - Data/Users/<you>/Library/Group Containers/group.com.apple.notes/

Pick a backup from before the change and copy the three NoteStore.sqlite* files into a scratch folder. If you do this from the command line, Terminal needs Full Disk Access (System Settings, Privacy & Security), because macOS protects this folder.

iPhone backup made in Finder. Unencrypted backups live in ~/Library/Application Support/MobileSync/Backup/<device id>/. Files there do not have their real names. Each file is stored under the SHA-1 of domain-relativePath, in a folder named after the first two hex characters.

For the Notes database that string is:

AppDomainGroup-group.com.apple.notes-NoteStore.sqlite

which gives:

$ printf 'AppDomainGroup-group.com.apple.notes-NoteStore.sqlite' | shasum
4f98687d8ab0d6d1a371110e6b7300f6e465bef2 -

So the file is 4f/4f98687d8ab0d6d1a371110e6b7300f6e465bef2.

You can also look it up in the backup's Manifest.db, which maps hashed names to real paths:

SELECT fileID, domain, relativePath FROM Files WHERE relativePath LIKE '%NoteStore.sqlite%';

That query also shows the -wal and -shm files if the backup has them; copy them too and rename all three back to NoteStore.sqlite, NoteStore.sqlite-wal and NoteStore.sqlite-shm.

If the backup is encrypted, the files are encrypted as well and you need a tool that knows the backup password to decrypt them first. The steps below only cover the plain case.

Finding the note

Notes uses Core Data, so the table names start with Z. Notes, folders and attachments all share one table, ZICCLOUDSYNCINGOBJECT, and the note bodies are in ZICNOTEDATA. You can see the entity list in Z_PRIMARYKEY (on my Mac ICNote, ICFolder, ICAttachment, ICNoteData and so on).

List the notes in your copy with their last modified date:

SELECT n.Z_PK, n.ZTITLE1, datetime(n.ZMODIFICATIONDATE1 + 978307200, 'unixepoch', 'localtime') AS modified, length(d.ZDATA) AS bytes FROM ZICCLOUDSYNCINGOBJECT n JOIN ZICNOTEDATA d ON d.Z_PK = n.ZNOTEDATA WHERE n.ZTITLE1 IS NOT NULL ORDER BY n.ZMODIFICATIONDATE1 DESC;

Two things to know:

  • Dates are Core Data timestamps: seconds since 1 January 2001, not 1970. Adding 978307200 turns them into Unix time.
  • Column names have numbers on the end (ZTITLE1, ZMODIFICATIONDATE1, ZCREATIONDATE3) and these can shift between macOS versions, because Core Data numbers them per model. If the query fails, run .schema ZICCLOUDSYNCINGOBJECT and look for the title and date columns.

Folders are rows in the same table. The folder with ZFOLDERTYPE = 1 was "Recently Deleted" on my Mac, which is handy if you are looking for a note that was deleted shortly before the backup.

Reading the body

The note text is not stored as plain text. ZICNOTEDATA.ZDATA is a gzip-compressed protobuf. You can see the gzip header (1f 8b) yourself:

SELECT count(*), sum(hex(substr(ZDATA, 1, 2)) = '1F8B') FROM ZICNOTEDATA;

Rows that are not gzip are usually empty or belong to locked notes. Locked notes (ZISPASSWORDPROTECTED = 1) are encrypted; ZICNOTEDATA has ZCRYPTOINITIALIZATIONVECTOR and ZCRYPTOTAG columns for them, and you cannot read them without the note password.

To pull one body out, use the writefile() function built into the sqlite3 shell:

sqlite3 -readonly NoteStore.sqlite \
  "SELECT writefile('note.gz', ZDATA) FROM ZICNOTEDATA WHERE ZNOTE = 123;"
gunzip -c note.gz | strings

Replace 123 with the Z_PK from the list above. strings is a rough way in: you get the text runs out of the protobuf, which is often enough to copy a lost paragraph back. You lose formatting, checklists, tables and the positions of attachments, because those are encoded in the protobuf around the text.

For a proper decode, use apple_cloud_notes_parser (MIT licence, Ruby). It reads a Mac Notes folder (--mac), a single NoteStore.sqlite (--file) or a whole iPhone backup folder (--itunes-dir), decodes the protobuf, and with a full backup it can also pull out embedded images and drawings. It is the best open tool I know of for this.

Putting the note back

Do not copy an old NoteStore.sqlite over the live one. If iCloud Notes is on, the database is a sync cache, and swapping it can confuse sync or bring back old state in odd ways. Instead, paste the recovered text into a new note, or export from the parser and import that into Notes.

What I tested

On macOS 27 I copied the three NoteStore.sqlite* files to a scratch folder and ran every query above on the copy: the WAL mode check, the table and column names, the 2001 epoch dates, the gzip header count, writefile() plus gunzip on one note, and the hash of the iPhone backup path. I did not have a Time Machine disk or an iPhone backup on this Mac, so the backup paths are from documentation and the hash calculation, not from opening a real backup.

Disclosure: I built a tool for this

I make NoteRescue at Kayabyte, a Mac app that does the steps above for you. It finds your Time Machine snapshots and iPhone backups (encrypted too, with the backup password you chose in Finder), compares them with today, and lists notes that are missing or changed. The scan is free, and for Notes the free scan shows the first paragraph of each note, so you can see whether the note you want is there before paying. Unlocking Notes is USD 24.99 once, no subscription; it then exports notes as Markdown, HTML, PDF or text, or puts them into Notes in a new "Recovered" folder without touching your current notes. Locked notes are counted but never opened. It needs macOS 15 or later and Full Disk Access, and it also covers Contacts, Safari, Calendar, Reminders and Voice Memos.

If you would rather not do it by hand: NoteRescue. If you do it by hand, everything above works without it.

Written with help from an AI assistant; tested on macOS by me.

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.