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 github-actions@github.com
          git add .
          git commit -m "Automated snapshot"
          git push
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值