It might just be me, but in everything where I am putting content together or using data that means something that is useful to me I automatically think about what happens if I lose it, can I withstand to lose that or is it important that I need a backup?

This weekend I fully transitioned over to using Notion for my note taking app but it also is or can be used as an “All in One workspace” it also has a lot of team collaboration benefits but the first and foremost goal for me was to have a single place that I could store not only specific notes and organise them but also to run a KanBan style workflow to keep track of objectives.

You can find out more about Notion here. Quick note – It does have dark mode so it will not burn your retinas. It also provides web, application cross platform including mobile devices as you would expect in the year of 2021.

I am also sure that many of you are using some form of note taking app, my go to before was Microsoft OneNote which does give a lot of the same functionality as Notion but I just think there is more and we will see as we embark on this note journey adventure.

The Beginning

I started by transferring or creating new pages for my workflow and there are so many prebuilt templates that you will find something that helps you in your day to day. This is not really the aim of the blog though, but I am impressed with how this works, looks and you can easily link your notes and tasks together.

Backup

Next we get to my bread and butter, my what happens if the world ended or a little bit of the world ended, which 2020 proved to me that you should always think a little like that, failures happen etc. it was also helped on by a little twitter thread I had that mentioned backup and security, security I cannot do anything about this is their platform but backup is on my list and my head, it is after all my data.

Both Oliver and Phoebe bring up great points when it comes to dealing with making sure you have a copy of your data, either by manually taking a copy of them or automating the taking of that copy.

Manual Backup

Built into Notion is a function to export. If you head to Settings & Members

You will then have a new window appear

From here select Settings and you will have the Export Content option.

It’s as simple as that, when you hit that Export all workspace content you then get some options for the format in how you want to and where you would like to export to.

Automated Backups

The above manual option is great, but the better option is going to be automating that process daily or at least scheduled so you do not have to worry about that. Now for this section I am not going to claim I was the brains behind the code here but I am hoping that sharing here will help someone who would like to make a scheduled export of their Notion data.

First of all we have established that you likely have your Notion account and some data in there or at least the intention on that side, next we need to think about where we would like to store the exports on that schedule, my first thought was GitHub and I am sure this is possible but the walkthrough I found was focused on GitLab which was also fine as I have an account over there and they also have a free tier which is ideal for this use case, I believe you can have up to 10GB of data stored across your repositories.

Start by creating that account on GitLab.

Next, we need to get some important strings from our Notion account. I am using chrome as my browser and I am on Windows so I will walk through this process. Firstly login to the web app site of Notion and head to that same settings page we see above. Once there then open up Chrome DevTools. For windows you can do this in chrome by pressing ctrl + shift + j.

Step 1

Go to the network tab highlighted below and then enable XHR on the filter. Then on your notion side of the page select Export all workspace content. On the right then you will see “enqueueTask”

Step 2

Next in the headers tab to the right you need to locate two items we need for the scheduled export. We need to scroll down and find the token_v2 and take a copy of that variable and copy to notepad for use later. And then you will also need the spaceID, both highlighted down below on the screenshot.

NOTION_TOKEN_V2 Value

NOTION_SPACE_ID Value

Step 3

Next, we need to head over to GitLab to create a new repository (I have not shown how to create a repository, it is very straight forward) and get an access key.

  1. Top right corner icon, select this and user settings
  2. Left side select access tokens
  3. Give your access token a name
  4. I did not supply an expire date
  5. Choose the scope allowed for the access token
  6. Take a copy of the access key and add this to your previous list

NOTION_TOKEN_V2 Value

NOTION_SPACE_ID Value

CI_PUSH_TOKEN Access Token from GitLab

Step 4

Next in GitLab we want to set up CI/CD and in the editor that appears you will need to copy and paste this file https://gitlab.com/aburtsev/notion-backup-script/-/raw/master/.gitlab-ci.yml this was created by Artur Burtsev, I am just using his contributions to remind me if I have to do this again in the future. But full credit goes to him for creating the process.

Step 5

We are then ready to combine all of this to create a schedule.

Within here this is where we would define those previously gathered variables to include here.

As I am not showing any values above this is the complete list.

NOTION_TOKEN_V2 Value

NOTION_SPACE_ID Value

CI_PUSH_TOKEN Access Token from GitLab

EXPORT_FILENAME /tmp/export.zip

PYTHONUNBUFFERED 1

TZ GB (obviously change according to your location)

You can then hit the play button to test everything works and then navigate to the repository and you should see a new backup folder.

And if you go into that folder you are going to see your notes, all written in markdown so you can visually see and read them here also.

Restore vs Access

I have not explored the restore vs access but just having a point in time accessible copy of these if the platform was to be unavailable was my aim and goal. I would like to give Artur Burtsev another shout out as he really did the work here, I have just documented his process for my own requirements but maybe this will also help someone else.

Leave a Reply

Your email address will not be published. Required fields are marked *