use*_*142 2 postgresql backup cron
我不确定这里发生了什么:
我有一个在 root 下运行良好的备份脚本。它会在正确的目录中生成一个 >300kb 的数据库转储。
但是,当使用完全相同的命令将其作为 cron 作业运行时,会出现一个空的 gzip 文件,其中没有任何内容。
cron 日志显示没有错误,只是命令已运行。
这是脚本:
#! /bin/bash
DIR="/opt/backup"
YMD=$(date "+%Y-%m-%d")
su -c "pg_dump -U postgres mydatabasename | gzip -6 > "$DIR/database_backup.$YMD.gz" " postgres
# delete backup files older than 60 days
OLD=$(find $DIR -type d -mtime +60)
if [ -n "$OLD" ] ; then
echo deleting old backup files: $OLD
echo $OLD | xargs rm -rfv
fi
Run Code Online (Sandbox Code Playgroud)
当改为:
pg_dump -U postgres mydatabasename | gzip -6 > "$DIR/database_backup.$YMD.gz"
Run Code Online (Sandbox Code Playgroud)
同样的事情发生。
和 cron 工作:
01 10 * * * root sh /opt/daily_backup_script.sh
Run Code Online (Sandbox Code Playgroud)
它生成一个 database_backup 文件,只是一个空文件。有谁知道这里发生了什么?
编辑:
好的,简化为这个,但它仍然无法通过 cron 工作
#! /bin/bash
DIR="/opt/backup"
YMD=$(date "+%Y-%m-%d")
pg_dumpall -U postgres > "$DIR/database_backup.$YMD"
Run Code Online (Sandbox Code Playgroud)
和
01 10 * * * root /opt/daily_backup_script.sh
Run Code Online (Sandbox Code Playgroud)