一、环境准备
检测系统是否安装crond服务
crond服务命令说明
service crond start //启动服务
service crond stop //关闭服务
service crond restart //重启服务
service crond reload //重新载入配置
service crond status //查看crontab服务状态
crontab -e #编辑crontab定时任务
crontab -l #查询crontab任务
crontab -r #删除当前用户所有的crontab任务
systemctl status crond.service #查看crond系统服务的状态
命令 service crond status
确认有crond服务就可以进行下面操作了
二、数据库备份
以pgsql为例
1,在pg库所在服务器的目标目录下创建一个backup.sh脚本文件
2,创建定时任务
命令 : crontab -e
命令中前面是定时的时间
然后sh /path/xx.sh 执行脚本
3,遇到的问题
定时任务创建完了过后
执行命令 service crond restart
在查看执行状态 service crond status
第一个问题就是unknown limit item ‘noproc’
cat /etc/security/limits.conf
- soft nproc 11000
- hard nproc 11000
- 用vim把noproc改成nproc
第二个问题就是no local interface found for ::1
命令
vi /etc/postfix/main.cf
将inet_interfaces = localhost 改为 all
修改完后重启
service postfix start
三、效果
最后把定时任务时间改下,重启下服务
备份sql成功
pgsql备份
sudo ./pg_dump -h ip -p 5432 -U postgres -d 要备份数据库名> 备份文件名称
sql恢复
psql -d 数据库名称 -U postgres -f 备份文件路径