简体   繁体   中英

PostgreSQL database backup is empty - what's wrong?

I want to configure backup of the Alfresco database (PostgreSQL rdbms).

For that I have a script like this:

psql-create-backup:

#!/bin/sh
pg_dump -h localhost -U postgres -Fc -Z9 -c -f /home/bykovan/alfresco-data-backup/"`date +%d-%m-%Y`".alfresco.backup alfresco

I saved it in /home/bykovan and gave rights to execute:

[bykovan@docflow ~]$ sudo chmod 711 psql-create-backup

Then I added the job to cron:

[bykovan@docflow ~]$ sudo crontab -e
...

0 0 * * * /home/bykovan/psql-create-backup

In the pg_hba.conf I added this line host all all 127.0.0.1/32 trust :

[bykovan@docflow ~]$ sudo vi /var/lib/pgsql/9.5/data/pg_hba.conf

-- SKIPPED --


# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
#local   all             all                                     peer
local   all             all                                     md5
# IPv4 local connections:
#host    all             all             127.0.0.1/32            ident
host     all             all             127.0.0.1/32            trust
host     all             all             127.0.0.1/32            md5
# IPv6 local connections:
#host    all             all             ::1/128                 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres        127.0.0.1/32            ident
#host    replication     postgres        ::1/128                 ident

host    all             all             192.168.0.0/16            md5
-- VISUAL BLOCK --

Backups are empty:

[bykovan@docflow alfresco-data-backup]$ ls -lh

-rw-r--r-- 1 root root 0 feb 18 00:00 18-02-2017.alfresco.backup
-rw-r--r-- 1 root root 0 feb 19 00:00 19-02-2017.alfresco.backup
-rw-r--r-- 1 root root 0 feb 20 00:00 20-02-2017.alfresco.backup
-rw-r--r-- 1 root root 0 feb 21 00:00 21-02-2017.alfresco.backup

In the pg_hba.conf I added this lines:

host    all  all       ::1/128      md5
host    all  postgres  127.0.0.1/32 trust 

Then restart service:

[bykovan@docflow ~]$ sudo service postgresql-9.5 stop
Redirecting to /bin/systemctl stop  postgresql-9.5.service
[bykovan@docflow ~]$ sudo service postgresql-9.5 start
Redirecting to /bin/systemctl start  postgresql-9.5.service

Then ran command direct in the prompt ( I was prompted for the password ) and saw the following:

[bykovan@docflow alfresco-data-backup]$ ls -lh

-rw-r--r-- 1 root root    0 feb 17 18:39 17-02-2017.alfresco.backup
-rw-r--r-- 1 root root    0 feb 18 00:00 18-02-2017.alfresco.backup
-rw-r--r-- 1 root root    0 feb 19 00:00 19-02-2017.alfresco.backup
-rw-r--r-- 1 root root    0 feb 20 00:00 20-02-2017.alfresco.backup
-rw-r--r-- 1 root root    0 feb 21 19:41 21-02-2017.alfresco.backup
-rw-r--r-- 1 root root 667K feb 22 07:04 22-02-2017.alfresco.backup

But running the task via cron gave me the empty files...

Where I'm wrong?

I set the password in the script, it now looks like this:

PGPASSWORD="some_password" pg_dump -h localhost -U postgres -Fc -Z9 -c -f /home/bykovan/alfresco-data-backup/"`date +%d-%m-%Y`".alfresco.backup alfresco

Now everything is Ok.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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