在搭建好hexo博客之后也要给自己的博客进行备份,文章丢失可是很麻烦的一件事情。我的博客的数据都是直接保存在cloudstudio,用的时候总是会感觉有点问题,生怕自己哪天不小心把工作空间给删除了,那就蛮麻烦了。所以我采用了 hexo-git-backup 这个工具进行备份。

查看hexo版本

1
hexo version

第一行的hexo:xxx既为版本

1.png

如图,我的版本是4.0.0

安装

如果你的版本是2.x.x使用这条命令:

1
npm install hexo-git-backup@0.0.91 --save

如果你的版本是3.x.x则使用这条命令:

1
npm install hexo-git-backup --save

这里我使用的是第二条命令,因为我的hexo版本为4.0.0

建立分支

来到你的github仓库目录或者是coding的仓库目录,选择新建分支,因为我是双线部署,所以两个都要创建分支,我创建的分支名都为backup

2.png

3.png

配置

打开博客配置文件_config.yml

在最下方添加

1
2
3
4
5
backup:
type: git
repository:
github: git@github.com:xxx/xxx.git,branchName
coding: git@github.com:xxx/xxx.git,branchName

branchName为分支名,要和前面的仓库地址用英文逗号隔开。

这里就差不多配置完成了

使用

1
hexo backup

or

1
hexo b

配置项

如果你只是想备份主题目录,只需要添加theme属性

1
2
3
4
5
6
backup:
type: git
theme: coney,landscape,xxx
repository:
github: git@github.com:xxx/xxx.git,branchName
gitcafe: git@github.com:xxx/xxx.git,branchName

如果你想自定义提交的message信息,那么只需要添加message属性

1
2
3
4
5
6
backup:
type: git
message: update xxx
repository:
github: git@github.com:xxx/xxx.git,branchName
gitcafe: git@github.com:xxx/xxx.git,branchName

插件地址

hexo-git-backup

评论