0

I have CentOS 7 (3.10.0-1062.18.1.el7.x86_64) with SELinux enabled. PostgreSQL 12 installed (not sure if it is related).

I try to backup database and move backup files to another disk. How I create backups files is unrelated, so I'll skip to the last step. I have backup files under /var/lib/pgsql/12/backups and want to copy them to /mnt/disk2 (destination path does not matter, tried various).

I use the following command for effective copying.

rsync -v --recursive --copy-links --copy-dirlinks --ignore-existing --delete-delay /var/lib/pgsql/12/backups/ /mnt/disk2/

When I run it from interactive SSH session under root account it works fine, files are transferred as expected.

Obviously, I have created systemd timer and service to run backup script periodically. Very simple service.

[Unit]
Description=Backup PostgreSQL Databases

[Service]
ExecStart=/opt/postgres-backup.sh

Again, if I execute "/opt/postgres-backup.sh" from SSH session, everyhting is file.

But when script is run from systemd timer, under root account as well (I verify that by executing whoami) rsync command fails and I get error message

sending incremental file list
rsync: change_dir "/var/lib/pgsql/12/backups" failed: Permission denied (13)
rsync: ERROR: cannot stat destination "/mnt/disk2/": Permission denied (13)
rsync error: errors selecting input/output files, dirs (code 3) at main.c(635) [Receiver=3.1.2]

Surprisingly

cp -R /var/lib/pgsql/12/backups/ /mnt/disk2/

works fine in both cases.

I have already tried chmod -R 777 /var/lib/pgsql/12/backups/ and restorecon -R /var/lib/pgsql/12/backups/

What else can be checked? What can be possible cause of rsync failure?

adontz
  • 337
  • 4
  • 12

0 Answers0