I have written a service that triggers a shell script to backup a postgres database, on a CentOS7 server. It dumps the backup file into the /tmp/ folder and then it is supposed to copy the file across to another server, but something is amiss, I suspect it is my bash. The service does the backup fine, but fails when it comes to copying it to the other server.
I am able to manually scp the backup file from /tmp/ folder in server1 to the /tmp/ folder in server2 using public key authentication, so passwordless between the two, but I'm not sure why the systemd trips up with the following error:
Aug 17 14:29:34 pcc-home-page-one.novalocal systemd[1]: Started backup service for production.
Aug 17 14:29:35 pcc-home-page-one.novalocal backup.sh[1467]: Permission denied, please try again.
Aug 17 14:29:35 pcc-home-page-one.novalocal backup.sh[1467]: Permission denied, please try again.
Aug 17 14:29:35 pcc-home-page-one.novalocal backup.sh[1467]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
Aug 17 14:29:35 pcc-home-page-one.novalocal backup.sh[1467]: lost connection
Aug 17 14:29:35 pcc-home-page-one.novalocal systemd[1]: backup.service: main process exited, code=exited, status=1/FAILURE
Aug 17 14:29:35 pcc-home-page-one.novalocal systemd[1]: Unit backup.service entered failed state.
Aug 17 14:29:35 pcc-home-page-one.novalocal systemd[1]: backup.service failed.
Here is my bash script:
#!/usr/bin/env bash
today=$(date +"%d-%m-%Y")
pg_dump -U db_backup -h localhost pcc_db >/tmp/backup-${today}.bak
scp /tmp/backup-${today}.bak ifunk@10.88.59.200:/tmp/
and here is the service file:
[Unit]
Description=backup service for production
[Service]
Type=simple
ExecStart=/home/ifunk/backup.sh
What can I do to get get the scp line in the script to work please?
EDIT: Looking at the journalctl logs I get the following error:
Unregistered Authentication Agent for unix-process:3757:6223410 (system bus name :1.42, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_GB.UTF-8) (disconnected from bus)
I've set SELinux to Permissive, and run daemon-reload, but the service still fails with this same error.