• Stars
    star
    387
  • Rank 110,971 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 4 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple command to backup a Notion workspace

notion-backup

This is a very simple tool to export a workspace from Notion, designed to work as part of a GitHub workflow.

It reads NOTION_TOKEN and NOTION_SPACE_ID from the environment, and outputs the export to both html and markdown directories in the current working directory, as well as to html.zip and markdown.zip.

Obtaining tokens

Automatically downloading backups from Notion requires two unique authentication tokens and your individual space ID which must be obtained for the script to work.

  1. Log into your Notion account in your browser of choice if you haven't done so already.
  2. Open a new tab in your browser and open the development tools. This is usually easiest done by right-click and selecting Inspect Element (Chrome, Edge, Safari) or Inspect (Firefox). Switch to the Network tab.
  3. Open https://notion.so/f/. You must use this specific subdirectory to obtain the right cookies.
  4. Insert getSpaces into the search filter of the Network tab. This should give you one result. Click on it.
  5. In the Preview tab, look for the key space. There you should find a list of all the workspaces you have access to. Unless you're part of shared workspaces there should only be one.
  6. Copy the UUID of the workspace you want to backup (e.g. 6e560115-7a65-4f65-bb04-1825b43748f1). This is your NOTION_SPACE_ID.
  7. Switch to the Application (Chrome, Edge) or Storage (Firefox, Safari) tab on the top.
  8. In the left sidebar, select Cookies -> https://www.notion.so (Chrome, Edge, Firefox) or Cookies – https://www.notion.so (Safari).
  9. Copy the value of token_v2 as your NOTION_TOKEN and the value of file_token as your NOTION_FILE_TOKEN.
  10. Set the three environment variables as secrets for actions in your GitHub repository.

NOTE: if you log out of your account or your session expires naturally, the NOTION_TOKEN and NOTION_FILE_TOKEN will get invalidated and the backup will fail. In this case you need to obtain new tokens by repeating this process. There is currently no practical way to automize this until Notion decide to add a backup endpoint to their official API, at which point this script will be able to use a proper authentication token.

Setup

This assumes you are looking to set this up to back up Notion to GitHub.

  1. Obtain the required values for the environment variables as explained above.
  2. Create a repo for your backup. You probably want it private.
  3. Set the NOTION_TOKEN, NOTION_FILE_TOKEN and NOTION_SPACE_ID environment variables as secrets in your GitHub repo.
  4. Give Actions write access to your repository: Settings > Actions > General > Workflow permissions > choose Read and write permissions
  5. Install the following under .github/workflows/whatever.yml in your repo.
  6. Configure the frequency by changing the cron value. You can use Crontab.guru.
  7. Push and control your backup workflow from the Actions tab of your repository Github page.
name: "Notion backup"

on:
  push:
    branches:
      - master
  schedule:
    -   cron: "0 */4 * * *"

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  backup:
    runs-on: ubuntu-latest
    name: Backup
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@v3

      - uses: actions/setup-node@v2
        with:
          node-version: '18'

      - name: Delete previous backup
        run: rm -rf markdown html *.zip

      - name: Setup dependencies
        run: npm install -g notion-backup

      - name: Run backup
        run: notion-backup
        env:
          NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }}
          NOTION_FILE_TOKEN: ${{ secrets.NOTION_FILE_TOKEN }}
          NOTION_SPACE_ID: ${{ secrets.NOTION_SPACE_ID }}
          NODE_OPTIONS: "--max-http-header-size 15000"

      - name: Delete zips
        run: |
          rm -f *.zip
          rm -f markdown/*-Part*.zip
          rm -f html/*-Part*.zip

      - name: Commit changes
        run: |
          git config user.name github-actions
          git config user.email [email protected]
          git add .
          git commit -m "Automated snapshot"
          git push

LFS Support

You won't be able to backup files exceeding a size of 100MB unless you enable Git LFS. Add a file named .gitattributes at the root of your repository and add the following. If you want to support other file types, just add a new line for that file type.

*.zip filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.jpg filter=lfs diff=lfs merge=lfs -text
*.jpeg filter=lfs diff=lfs merge=lfs -text
*.psd filter=lfs diff=lfs merge=lfs -text

More Repositories

1

svgboilerplate

OLD REPO, NO LONGER ACTIVE
JavaScript
89
star
2

quasi

Quasicrystals in SVG
JavaScript
77
star
3

formic

Playing with forms
JavaScript
34
star
4

html-sanitiser

A simple sanitiser/sanitizer for NodeJS
28
star
5

webidl.js

DEPRECATED β€” Use https://github.com/darobin/webidl2.js instead
JavaScript
24
star
6

web-schema

The meeting of JSON Schema and HTML form validation
JavaScript
14
star
7

express-browserid

Plug-and-play BrowserID in Express (caution: more playground than production!)
JavaScript
10
star
8

after5

After5
JavaScript
9
star
9

chaitin-lisp

Toying with a port of Chaitin's LISP
R
8
star
10

web-wish

Web Wishes β€” An API to plug user services together
HTML
7
star
11

couchdb-client

A Perl client library for CouchDB
6
star
12

politi.es

rethinking
JavaScript
6
star
13

inception-wiki

6
star
14

breakup

Breaking up is never easy, I know, but I haaaave tooooo go
HTML
6
star
15

html-ruby

Ruby markup extensions for HTML
5
star
16

locale-host

ExpressJS plugin to support setting the locale through the host
JavaScript
5
star
17

couth

Refined Relaxation
JavaScript
5
star
18

bevy

A simple server to manage multiple Node services
JavaScript
5
star
19

garuda

Governance of Ad Requests by a Union of Diverse Actors
HTML
5
star
20

wocuments

JavaScript
4
star
21

ttc

Think Tank CrowdsourcΓ©
JavaScript
4
star
22

test-harness-tutorial

A runnable tutorial for testharness.js
JavaScript
4
star
23

pup

Principles of User Privacy
HTML
3
star
24

dwim

Do What I Mean (for VCS command line)
3
star
25

hacking-democracy

A braindump and manifesto of sorts on how to hack democracy
3
star
26

couchdb-deploy

simplified deployment using CouchDB-Client
Perl
3
star
27

jaspilite

Chimera involving JS, jQuery, CSS, and XSLT. Fear me.
JavaScript
3
star
28

webidl-rpc

A WebIDL binding for JSON-RPC
JavaScript
2
star
29

horsweb.org

Source for the horsweb.org conference web site
HTML
2
star
30

express-csrf

Small helper plugin for the CSRF middleware in Express
JavaScript
2
star
31

proto-handler-reqs

Protocol handler requirements
HTML
2
star
32

polypod

Experimenting with Polypod atop WNFS
JavaScript
2
star
33

xml-prague-2012

XML Prague 2012 Paper
JavaScript
2
star
34

html5-rec

The source of the published HTML5 Recommendation β€” for people who want to do things to it
JavaScript
2
star
35

ipd-morality

Playing with IPD and morality definitions
JavaScript
2
star
36

ancient-webref

References for Web Specifications (http://webref.herokuapp.com/)
JavaScript
2
star
37

html-serialise

Serialising an HTML DOM to string as per the specification
JavaScript
2
star
38

mq-assets-implementation

Implementation notes on not loading some assets behind a media query, in some cases
2
star
39

wile

Extension to play with Web Tiles
JavaScript
2
star
40

usable-gmail

Just building up things to help make Gmail a less painful experience
JavaScript
1
star
41

contacts-intents

Experimental demo for Contacts over Intents
1
star
42

group-hug

Playing the with the W3C Data API
HTML
1
star
43

ipseity

InterPlanetary Standards Edited and Integrated to Travel Yonder (IPSEITY)
JavaScript
1
star
44

kipple

My own kipple
JavaScript
1
star
45

pw10

Chut, c'est une surprise
1
star
46

gmail-style

A style sheet that makes GMail a bit less cluttered and unusable
CSS
1
star
47

hotdam

HTML Opaque, Trustworthy, Declarative Ads Markup
1
star
48

sliders

Slides in JS
1
star
49

api-design-privacy

Privacy by Design in APIs
1
star
50

paris-epub-workshop

Position paper for the Paris epub workshop
1
star
51

web-api-security-architecture

An overview of the security ecosystem for Web APIs
1
star
52

inyurts

Investigating Intents
1
star
53

svelte-preprocess-splintered

Svelte components with HTML/Svelte, CSS, and JS in separate files
JavaScript
1
star
54

etiologi.es

Philosophical tinkering
HTML
1
star
55

coproduction-citoyenne

Les sources d'un vieux texte publié comme note auprès de la Fondapol
1
star
56

robin-vs-theme

My theme for VS Code
1
star
57

seditious

(Ideas for) a structured SVG editor
JavaScript
1
star
58

express-gpc

Easy detection of the GPC flag (https://globalprivacycontrol.org/)
JavaScript
1
star
59

github-hook-simplify

Simplifies (and trims down) the payload for GitHub hook data
JavaScript
1
star
60

dap-charter-3

Proposed third charter for DAP
1
star
61

roam2notion

A tool to migrate my Roam content to Notion
JavaScript
1
star
62

polity.coop

The source code for the polity.coop project
JavaScript
1
star
63

notion-sync

Easily sync a Notion space to something else
JavaScript
1
star
64

cosmi

Delegated dispatch Connect/Node application framework
JavaScript
1
star
65

vision-old

Web Vision
HTML
1
star
66

eslint-config-robin

JavaScript β€” FOR SCIENCE!
JavaScript
1
star
67

specstatic

Making specs awesomely nicer
JavaScript
1
star
68

gr

Personal playground for graph-related things
JavaScript
1
star
69

system-level-apis-charter

Proposed charter for the System Level APIs group
1
star
70

contacts-api

Draft of the DAP WG Pick Contacts Intent specification
1
star
71

wise

Web Infrastructure Search Endowment (WISE)
HTML
1
star
72

standards.group

The standards.group website
CSS
1
star