在Ubuntu上使用pgAdmin设置定时备份主要有以下两种方法:
- 使用pgAgent:
- 安装pgAgent:可通过pgAdmin 4管理工具集成安装,或从官网下载安装。
- 创建定时任务:在pgAdmin 4左侧导航树中找到“pgAgent Jobs”节点,右键选择“Create”>“pgAgent Job”。在“Steps”页面设置备份步骤,如输入备份命令;在“Schedules”页面定义执行时间计划。
- 使用操作系统定时任务(crontab):
- 编辑crontab文件:在终端中输入
crontab -e。 - 添加定时任务:按格式添加一行,如
0 0 * * * /usr/bin/pg_dump --no-password -U username db_name > /path/to/backup/backup_$(date +\%Y\%m\%d).sql,注意将密码存入.pgpass文件并设置权限为600。