安装 pm2
安装 node
https://nodejs.org/dist/v22.23.5/node-v22.23.5-x64.msi 一直 next 即可
安装 pm2
bash
npm install -g pm2编写 git 推送 py 脚本
python
import os
import time
# 获取当前时间
now_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
def callback(result):
os.system(result)
# add the file
add = "git add ."
# commit the file
commit = "git commit -m 'auto commit: {}'".format(now_time)
# push the file
push = "git push origin master"
callback(add)
callback(commit)
callback(push)pm2 执行脚本并定时推送
bash
# 1 天 = 86400000 ms
pm2 start XXX.py --restart-delay 86400000mongo 每天自动全备份
安装 node、pm2
见上文「安装 pm2」,步骤相同。
安装 mongoTools
MongoDB Database Tools 官方下载页:https://www.mongodb.com/try/download/database-tools 下载 Windows 版本后解压,把里面的 bin 目录加到系统环境变量 PATH
编写备份脚本
python
import os
import time
# 获取当前日期
def get_date():
date = time.strftime('%Y%m%d', time.localtime(time.time()))
return date
os.system('mongodump -o F:\\db_back\\back\\{}'.format(get_date()))pm2 定时执行
bash
# 1 天 = 86400000 ms
pm2 start XXX.py --restart-delay 86400000pm2 保存
bash
pm2 save