简体   繁体   English

postgresql 中的自动备份创建空备份

[英]automatic backup in postgresql creates the empty backup

I want to automate backup of PostgreSQL database using crontab in UNIX.我想使用 UNIX 中的 crontab 自动备份 PostgreSQL 数据库。 I have tried but it will create 0 bytes backup.我已经尝试过,但它会创建 0 字节备份。

My crontab entry is:我的 crontab 条目是:

24 * * * *  /home/desktop/myscript.sh

and my sh file contains the following code:我的 sh 文件包含以下代码:

pg_dump -U PostgreSQL -d test > b.backup

It will create the file but the file is empty.它将创建文件,但文件为空。 Is there any solution?有什么解决办法吗? Is there any way to solve this question?有没有办法解决这个问题?

Don't assume that any environment variables are set in a cron job;不要假设在 cron 作业中设置了任何环境变量; be explicit:明确:

/full/path/to/pg_dump -U postgres -d test > /full/path/to/b.backup

Look for mail in your inbox for failure reports from cron .在收件箱中查找来自cron的失败报告的邮件。

You must specify full path to pg_dump您必须指定 pg_dump 的完整路径

#!/bin/bash
BKPDATE=$(date +%d.%m.%Y-%H:%M:%S)
cd /var/lib/pgsql/12/backups
/usr/pgsql-12/bin/pg_dump -Fc dl_db > DBNAME_$BKPDATE.dmp --verbose 2> LOG_$BKPDATE.log

or you must add PostgreSQL's bin directory to the path like below:或者您必须将 PostgreSQL 的 bin 目录添加到如下路径:

vi /var/lib/pgsql/.pgsql_profile

   export PATH=$PATH:/usr/pgsql-12/bin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM