Linux系统设置Postgresql数据库定时自动备份
一,编写脚本
文件后缀为.sh 如:(db_backup.sh)
// 数据库文件bin文件路径,数据库IP地址
/export/servers/app/postgresql-12.5/bin/pg_dump -F c -O -U postgres -h 127.0.0.1 -p 5432 -f /data/db_backup/majorcpc_$(date +%Y%m%d_%H_%M_%S).sql majorcpc
//脚本类型
echo "backup finished"
二,将脚本文件放置对应用户的文件夹
三,Linux里设置定时执行Shell脚本
1.给Shell脚本赋予可执行权限
Shell文件默认路径 /usr/share/cockpit/shell
// **/**/insertBook.sh脚本文件路径
chmod -R 777 insertBook.sh
2.设置定时器
crontab -e
设置定时器
# 意思是每天01:00执行insertBook.sh脚本
0 1 * * * /data/mysqlbak/insertBook.sh
3.重启crontab服务让新配置的定时任务生效
service crond restart