Skip to content
This repository has been archived by the owner on Aug 15, 2023. It is now read-only.

使用 cron 服务定时备份机器人的数据 #116

Open
Arondight opened this issue Sep 18, 2021 · 2 comments
Open

使用 cron 服务定时备份机器人的数据 #116

Arondight opened this issue Sep 18, 2021 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@Arondight
Copy link
Owner

Arondight commented Sep 18, 2021

这里演示了如何进行定时数据备份,假设操作系统为 CentOS,并且机器人的目录位于 /opt/apps/Adachi-BOT/ ,数据要备份到 /opt/data/Adachi-BOT/ ,如下所示。

/opt/apps/Adachi-BOT
├── app.js
├── bot.pm2
├── config
├── config_defaults
├── data
├── docs
├── images
├── LICENSE
├── node_modules
├── package.json
├── package-lock.json
├── README.md
├── resources
├── resources_custom
└── src
/opt/data/Adachi-BOT
└── data

下面的命令使用 cronie 每天凌晨四点将 /opt/apps/Adachi-BOT/data/ 下的数据文件同步到 /opt/data/Adachi-BOT/data/ 中的 Git 仓库中,并做一个带时间戳的提交。

sudo -i
yum -y install cronie git rsync
systemctl enable --now crond.service
crontab -l | { cat; echo '0 4 * * * /bin/mkdir -pv "/opt/data/Adachi-BOT/data/" && /bin/rsync --exclude=".gitignore" --exclude="record/" -aP "/opt/apps/Adachi-BOT/data/" "/opt/data/Adachi-BOT/data/" && cd "/opt/data/Adachi-BOT/data/" && /bin/git init && /bin/git add . && /bin/git commit -am "$(date +\%Y\%m\%d-\%H\%M\%S)"'; } | crontab -
@Arondight Arondight added the documentation Improvements or additions to documentation label Sep 18, 2021
@Arondight
Copy link
Owner Author

注意使用 crontab -l 确认你添加的定时任务,你也可以使用 crontab -e 来在一个文本编辑器中交互式地去编辑这些任务。

@Xm798

This comment was marked as resolved.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants