This is a simple Python script that uses the Notion client SDK to download all the pages from your Notion account in markdown and save them as a zipped back-up file. There are some pre-requisites to run this -
- Create a Notion integration in your account. You need to be the owner/admin of the account. Check this link for more details.
- Add this integration to all the pages you want to back-up. Adding the parent page automatically adds all the children pages.
The first recommended step is to create a Python virtual environment in the directory and install the required packages in it.
python -m venv notion_env
source notion_env/bin/activate
pip install notion-client notion2md python-dotenvNext you want to create a .env file and paste your Notion Integration Secret in there.
NOTION_TOKEN=""You can now run this script
python backup_notion.pyIt should create a backup file named notion_backup_YYYY-MM-DD.zip with today's date.
If you'd like to back-up your Notion automatically every week or every night, you can use cron to schedule that job if you are using a Linux based computer. Here is how I did for my system.
0 3 * * 6 /home/user/NotionBackup/notion_env/bin/python /home/user/NotionBackup/backup_notion.py >> /home/user/NotionBackup/cron.log 2>&1