一、## 在linux上的定时备份
1、编写脚本新建xxx.sh文件
filename=$(date +%y%m%d)
/usr/pgsql-12/bin/pg_dump -U onespace2020 -F c -f /root/onespace/sql/projectmonitoring+$filename.tar projectmonitoring
2、给xxx.sh可执行权限
chmod +x xxx.sh
3、使用 crontab 添加定时任务,在终端输入以下命令:
crontab -e
4、在crontab -e显示的文件中添加以下内容(单独占一行),实现每天3点时热备份(不影响用户正常使用)数据库:
0 3 * * * /root/xxx.sh
5、重启定时器
service crond restart
二、## 在window上的定时备份
1、编写脚本
@echo off
set NOW_TIME=%date:~0,4%-%date:~5,2%-%date:~8,2%-%time:~0,2%-%time:~3,2%-%time:~6,2%
set PGPASSWORD=123456
set path1=D:\Program Files\PostgreSQL\12\bin\pg_dump.exe
"D:\Program Files\PostgreSQL\12\bin\pg_dump.exe" -U postgres -F c -f "D:\projectjianshi\sql\projectmonitoring"%NOW_TIME%".tar" projectmonitoring
exist
2、打开任务计划程序
2、创建基本任务
3、设置触发器规则
4、设置执行时间
5、启动程序
6、选择执行脚本
7、完成