Notion Github Actions 自动备份

获取 Notion 相关的 token

因为 Notion 官方目前没有 API 支持导出备份整个空间, 所以需要从 Cookie 中获取相关值来实现自动备份.

token_v2

在这里插入图片描述

space_id

在这里插入图片描述

file_token

找个页面点击导出
在这里插入图片描述

使用 Github Actions 自动备份

仓库一定要选 Private, 不然就公开啦!

新建后点击 Setting —> Actions —> General, 往下滚动找到图中的权限配置, 设置默认权限为可读可写 (如图所示):

还是这个页面, 点击 Secrets and variables —> Actions, 如图添加三项 Secret, 分别对应上面鼓捣到的三个小东西:

  • NOTION_TOKEN 填上面的 token_v2
  • NOTION_SPACE_ID 填上面的 space_id
  • NOTION_FILE_TOKEN 填上面的 file_token

最后一步, 打开 Actions 标签页, 点击 Simple workflowConfigure 按钮创建一个任务:

清空默认的代码, 复制下面的内容, 粘贴到文件里:


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

猜你喜欢

转载自blog.csdn.net/weixin_42452716/article/details/134643032