史诗级的滑稽导致不可挽回的数据丢失

起因

  • 在七月初,手贱格式化了电脑内的所有数据,虽然已经做了部分的备份,但这是数据丢失仍然不可挽回。
  • 痛并思痛,这次有两种可行的方法来对原来的只部署生成好的页面,不上传源码进行改造。

承转

  • 目前有两种简单而可行性高的方法,也便于后期的维护和移植

  • 第一种,很简单的使用两个repository或者一个repository的两个分支,将他们当作不同的两个独立文件进行维护,这种方法很容易操作,只需要重新建立一个存放源码的repository,执行git push 操作即可;

  • 第二种方法,主要是解决第一种方法的弊处——每次部署都需要对源文件和目标文件进行push,不仅麻烦,而且容易出错,并且不易回滚。于是,在网上寻得了另一种方法:

    • 只对源代码进行维护,使用在线部署的网站,将目标库托管,并自定义脚本,自动部署;

    • 具体需要两个不同的库,一个存放网站代码,一个存放源代码

    • 将源代码的git配好,这里不再赘述;

    • 第二步,在源代码的repository中加入appveyor.yml 文件中,相关内容如下:

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      clone_depth: 5

      environment:
      access_token:
      secure: [secure code]

      install:
      - node --version
      - npm --version
      - npm install
      - npm install hexo-cli -g

      build_script:
      - hexo generate

      artifacts:
      - path: public

      on_success:
      - git config --global credential.helper store
      - ps: Add-Content "$env:USERPROFILE\.git-credentials" "https://$($env:access_token):x-oauth-basic@github.com`n"
      - git config --global user.email "%GIT_USER_EMAIL%"
      - git config --global user.name "%GIT_USER_NAME%"
      - git clone --depth 5 -q --branch=%TARGET_BRANCH% %STATIC_SITE_REPO% %TEMP%\static-site
      - cd %TEMP%\static-site
      - del * /f /q
      - for /d %%p IN (*) do rmdir "%%p" /s /q
      - SETLOCAL EnableDelayedExpansion & robocopy "%APPVEYOR_BUILD_FOLDER%\public" "%TEMP%\static-site" /e & IF !ERRORLEVEL! EQU 1 (exit 0) ELSE (IF !ERRORLEVEL! EQU 3 (exit 0) ELSE (exit 1))
      - git add -A
      - if "%APPVEYOR_REPO_BRANCH%"=="master" if not defined APPVEYOR_PULL_REQUEST_NUMBER (git diff --quiet --exit-code --cached || git commit -m "Update Static Site" && git push origin %TARGET_BRANCH% && appveyor AddMessage "Static Site Updated")
    • 将在github上申请的personal access tokens 粘贴到appVeor 进行加密,再将加密后的code替换上文中的[scure code] 部分;

    • 最后将源代码的repository添加到appVeor上,配置环境;

    • appVeor环境配置

    • 这样,只需要git push所有的部署自动完成,一劳永逸。


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!