Export Memos to Markdown files
•2 min read
A huge advantage of self-hosting applications is that you have full access to your data—until you find yourself using a tool that no longer fits your needs. When you decide to migrate your data, you may realize the application doesn’t have an export feature. This is the situation I faced when I wanted to migrate my notes from Memos . If you’re in a similar situation, this guide is for you.
Prerequisites
- Access to the Memos data files (
memos_prod.db) - Python installed on your machine
Exporting memos to markdown files
- Create a new file:
process-memos.py - Add the following to the created file:
process-memos.py
import os
import sqlite3
# Paths
memos = 'memos_prod.db'
export_folder = 'memos_export'
# Ensure export folder exists
os.makedirs(export_folder, exist_ok=True)
# Connect to SQLite database
con = sqlite3.connect(memos)
cur = con.cursor()
res = cur.execute("SELECT id, content FROM memo")
rows = res.fetchall()
con.close()
# Process each memo
for row in rows:
id = row[0]
content = row[1]
if not content.strip():
continue # Skip empty content
first_line = content.split('\n', 1)[0].strip()
if not first_line:
first_line = f"memo_{id}" # Use ID if first line is empty
# Sanitize filename
filename = "".join(c for c in first_line if c.isalnum()
or c in (' ', '_', '-')).strip()
filename = filename[:50] # Limit filename length
filepath = os.path.join(export_folder, f"{filename}.md")
# Write content to file
with open(filepath, 'w', encoding='utf-8') as out_file:
out_file.write(content)The script is looking for the memos_prod.db file and will export to the memos_export folder. If you want, you can modify it under the # Paths comment in the script
- Open a new terminal in the directory where you created the file
- Run
python ./process-memos.py - Your exported markdown files are available in the
memos_exportfolder
