Portal postgres DB Backup fails from cron
search cancel

Portal postgres DB Backup fails from cron

book

Article ID: 250747

calendar_today

Updated On:

Products

CA API Developer Portal

Issue/Introduction

We have portal5.0 ( Broadcom centos Image) and we are using the embedded "postgres" database inside this image.

We have implemented the broadcom procedure to backup this database as https://techdocs.broadcom.com/us/en/ca-enterprise-software/layer7-api-management/api-developer-portal/5-0/set-up-and-maintenance/maintain-the-api-developer-portal/back-up-and-restore-internal-database.html

But the "db_backup_dump" files created by this backup are of zero bytes, please find details below:

Backup

-bash-4.2# crontab -l

0 0 * * 0 /opt/ca/apim-portal/util/db-backup.sh

-rw-r--r--. 1 root root 0 Aug 21 00:00 postgres_backup-2022-08-21-00-00-01.sql

-rw-r--r--. 1 root root 0 Aug 28 00:00 postgres_backup-2022-08-28-00-00-01.sql

 

Environment

Release : 5.0

Component :

Resolution

The portal database  backup script works when you run it from the command prompt but not from cron.

The error in the log for cron says  "the input device is not a tty"

The script call the backup as follows 

docker exec -it --user root $(docker ps --format "{{.ID}}" --filter name=portal_portaldb.1) sh -c 'PGPASSWORD=${POSTGRES_PASSWORD} pg_dumpall -U ${POSTGRES_USER} -c' postgres > ../backup/$name

To fix it remove -t parameter -t, –tty Allocate a pseudo-TTY and use only -i

change it to 

docker exec -i --user root $(docker ps --format "{{.ID}}" --filter name=portal_portaldb.1) sh -c 'PGPASSWORD=${POSTGRES_PASSWORD} pg_dumpall -U ${POSTGRES_USER} -c' postgres > ../backup/$name