title: PostgreSQL database backup is empty - what's wrong?
body: <p>I want to configure backup of the Alfresco database (PostgreSQL rdbms).</p>
  
  <p>For that I have a script like this:</p>
  
  <p>psql-create-backup:</p>
  
  <pre><code>#!/bin/sh
  pg_dump -h localhost -U postgres -Fc -Z9 -c -f /home/bykovan/alfresco-data-backup/"`date +%d-%m-%Y`".alfresco.backup alfresco
  </code></pre>
  
  <p>I saved it in <code>/home/bykovan</code> and gave rights to execute:</p>
  
  <pre><code>[bykovan@docflow ~]$ sudo chmod 711 psql-create-backup
  </code></pre>
  
  <p>Then I added the job to cron:</p>
  
  <pre><code>[bykovan@docflow ~]$ sudo crontab -e
  ...
  
  0 0 * * * /home/bykovan/psql-create-backup
  </code></pre>
  
  <p>In the <code>pg_hba.conf</code> I added this line <code>host all all 127.0.0.1/32 trust</code>:</p>
  
  <pre><code>[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 --
  </code></pre>
  
  <p>Backups are empty:</p>
  
  <pre><code>[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
  </code></pre>
  
  <hr>
  
  <p>In the <code>pg_hba.conf</code> I added this lines:</p>
  
  <pre><code>host    all  all       ::1/128      md5
  host    all  postgres  127.0.0.1/32 trust 
  </code></pre>
  
  <p>Then restart service:</p>
  
  <pre><code>[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
  </code></pre>
  
  <p>Then ran command direct in the prompt (<em>I was prompted for the password</em>) and saw the following:</p>
  
  <pre><code>[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
  </code></pre>
  
  <p>But running the task via cron gave me the empty files...</p>
  
  <p>Where I'm wrong?</p>