我有两个文件,分别名为 lb 和 z-backup。z-backup 是一个放置在 cron.daily 中的 sh 脚本,它将 lb (sh) 脚本调用为 anacron 作业。
这些是文件及其位置:
ls -l ~/bin/lb -rwxrwxr-x 1 chh1 chh1 1300 Oct 23 11:56 /home/chh1/bin/lb
ls -l /etc/cron.daily/z-backup -rwxr-xr-x 1 root root 141 Oct 23 12:29 /etc/cron.daily/z-backup
lb的内容为:
#!/bin/sh
pg_dump -h localhost -p 5432 -U postgres -d crewdb -w -C -F p -b -f ~/Dropbox/postgres_backup/crewdb.backup.sql >/home/chh1/Desktop/pg_dump_log 2>&1
exit
z-backup的内容为:
#!/bin/sh
set -e
# Anacron script to run a daily backup at boot time.
exec /home/chh1/bin/lb >>/home/chh1/Desktop/anacron_log 2>&1
exit
当我运行以下命令时收到一条错误消息:
sudo run-parts /etc/cron.daily
run-parts: /etc/cron.daily/z-backup exited with return code 1
从 z-backup 脚本创建的 anacron_log 是空的:
cat ~/Desktop/anacron_log
<<there is not message>>
从 lb 脚本创建的 pg_dump_log 显示错误消息:
cat ~/Desktop/pg_dump_log
pg_dump: [archiver (db)] connection to database "crewdb" failed: fe_sendauth: no password supplied
其他信息
cat ~/.pgpass && ls -la ~/.pgpass
# hostname:port:database:username:password
*:*:crewdb:*:xDf&&li@
-rw------- 1 chh1 chh1 68 Oct 23 11:09 .pgpass
sudo cat /.pgpass && ls -la /.pgpass
# hostname:port:database:username:password
*:*:crewdb:*:xDf&&li@
-rw------- 1 root root 68 Oct 21 10:39 /.pgpass
Unix user: chh1
Database name: crewdb
Postgresql superuser: postgres
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
crewdb | postgres | UTF8 | en_NZ.UTF-8 | en_NZ.UTF-8 | =Tc/postgres +
| | | | | postgres=CTc/postgres+
| | | | | chh1=CTc/postgres
postgres | postgres | UTF8 | en_NZ.UTF-8 | en_NZ.UTF-8 |
template0 | postgres | UTF8 | en_NZ.UTF-8 | en_NZ.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_NZ.UTF-8 | en_NZ.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
echo "PATH=$PATH:/usr/lib/postgresql/10/bin
export PATH" >> .profile
sudo grep ^[^#] /etc/postgresql/10/main/pg_hba.conf
[sudo] password for chh1:
local all postgres md5
local all all peer
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
local replication all peer
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
我不知道如何解决 pg_dump_log 中的错误消息并让 anacron 作业正常工作。当我从终端运行 lb 脚本时,Postgresql 备份顺利进行。有人知道为什么这不起作用吗?非常感谢您的帮助。
答案1
我找到了答案。我将 pg_hba.conf 文件更改为:
[sudo] password for chh1:
local all all trust
local all all trust
host all all 127.0.0.1/32 trust
host all all ::1/128 md5
local replication all md5
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
现在,anacron 一切运行正常。