Can't script database backup

Hi,

Are there any tips on scripting database backups? I’ve written a small script based on the recommended commands (https://docs.tutor.overhang.io/local.html#backups-migrating-to-a-different-server), to backup the database automatically during the backup process. I found I got the following error:

the input device is not a TTY

Searching around I found that this is a docker issue and I set export COMPOSE_INTERACTIVE_NO_CLI=1 in my script. I now get the error:

ValueError: I/O operation on closed file.

Is there any way of scripting the database dump so it can be run during a backup process, for example from bacula or CRON?

Thanks,
-David.

I found the following code online (can’t recall from where) and modified it to fit my needs. I have it run twice a day.

!/bin/bash

BACKUPS_DIRECTORY="/tutor/backups/"
NUMBER_OF_BACKUPS_TO_RETAIN="14"

MYSQL_DOCKER_IMAGE="tutor_local_mysql_1"
MONGODB_DOCKER_IMAGE="tutor_local_mongodb_1"
#Check to see if a backups/ folder exists. if not, create it.
if [ ! -d ${BACKUPS_DIRECTORY} ]; then
    mkdir ${BACKUPS_DIRECTORY}
    echo "created backups folder ${BACKUPS_DIRECTORY}"
fi

cd ${BACKUPS_DIRECTORY}

#Backup MySQL databases
echo "Backing up MySQL databases"
docker exec ${MYSQL_DOCKER_IMAGE} /usr/bin/mysqldump -u root --password=${MYSQL_PWD} openedx | gzip -9 -c > "mysql_backup_$(date +"%Y%m%d_%H%M%S").sql.gz"
echo "Done backing up MySQL"

echo "Backing up MongoDB"
docker exec ${MONGODB_DOCKER_IMAGE} mongodump --archive --gzip --db openedx > "mongo_backup_$(date +"%Y%m%d_%H%M%S").gz"
echo "Done backing up MongoDB"

echo "Pruning the local backup folder archive"
if [ -d ${BACKUPS_DIRECTORY} ]; then
  cd ${BACKUPS_DIRECTORY}
  ls -1tr | head -n -${NUMBER_OF_BACKUPS_TO_RETAIN} | xargs -d '\n' rm -f --
fi

echo "Done!"

@waveywhite This error can be resolved by disabling TTY allocation in Docker. To do so, simply pass the -T option to all tutor local exec commands.