yum -y install epel-release
yum -y install python-pip
pip install apscheduler
pscp local_dir user@ip:/remote_dir
# 例:
pscp C:\Users\pantao\Documents\Projects\python\auto_backup\mysql_auto_backup.py root@180.97.80.83:/root/auto_backup
pscp C:\Users\pantao\Documents\Projects\python\auto_backup\config.json root@180.97.80.83:/root/auto_backup
{
"nodes": [
{
"user": "zhazhapan",
"password": "zhazhapan",
"host": "127.0.0.1",
"dbs": [
"efo"
]
}
],
"mysqldump": "",
"path": "/Users/pantao/Desktop/backup",
"dateFormat": "%Y-%m-%d-%H-%M-%S",
"expired": "60*60*24*100",
"schedulerParams": {
"cron": false,
"dayOfWeek": "0-6",
"hour": 15,
"minute": 27,
"seconds": 10
}
}
说明:如果
mysqldump
已添加到环境变量(可直接执行mysqldump
命令),则设置配置文件中的mysqldump
值为空; 否则请将mysqldump
值设置mysqldump
所在的路径(并在结尾添加一个文件分隔符),比如/usr/local/mysql-5.7.17-macos10.12-x86_64/bin/
cd /root/auto_backup
setsid python mysql_auto_backup.py
# 或者
nohup python mysql_auto_backup.py &
ps -ef | grep mysql_auto_backup.py
-
新建自启脚本
vim auto.sh
-
添加内容
#!/usr/bin/env bash cd /root/auto_backup setsid python mysql_auto_backup.py
-
在
/etc/rc.local
最后一行中添加脚本路径/root/auto_backup/auto.sh