Automatic Notion Backup
2/20/2021
Notion allows us to manually export our workspace to markdown, HTML and other formats from the setting. This is tedious.
By the end of this post, you will be able to set up automatic backup of your Notion workspace.
Setup
You need to allow the github action’s runtime to access your notion’s workspace. You need your notion’s token and notion’s space id to do that.
Get your notion’s token, by going to “Settings” in “Settings & Members” under workspace and then to “Export all workspace content”. Make sure to open your browser’s network tab before exporting the workspace.
Check the “Request Headers” of ‘enqueueTask’ in the network tab. You will see token_v2=xxxxx;
in front of cookie. Your notion token will be xxxxx
.
Check for space id from the ‘loadPageChunk’ request in the Network tab.
You can see the space id of my workspace in the above image. It starts with ‘abe1’ and ends with ‘8’.
Now create a private or public repo on Github for your backup.
Now define those token and space id in secrets of your repositories’ setting with key NOTION_SPACE_ID
and NOTION_TOKEN
.
Now go to the “Actions” tab of the repo and set up a workflow with the below config.
name: "Notion backup"
on:
push:
branches:
- master
schedule:
- cron: "0 10 * * 0"
jobs:
backup:
runs-on: ubuntu-latest
name: Backup
timeout-minutes: 15
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '12'
- name: Setup dependencies
run: npm install -g notion-backup
- name: Run backup
run: notion-backup
env:
NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }}
NOTION_SPACE_ID: ${{ secrets.NOTION_SPACE_ID }}
- name: Commit changes
uses: elstudio/actions-js-build/commit@v3
with:
commitMessage: Automated snapshot
You can update the cron setting to suit your need. The above cron will run every Sunday at 10 UTC or whenever you push any changes to master. You could make use of crontab to find a suitable cron.
Now commit these changes to the master branch. Github action you set will trigger and export your notion workspace as both HTML and markdown.
You have now set up an periodic backup of your Notion workspace on Github.