0

I created Azure Container Instance and ran postgresql in it. Mounted an azure container instance storage account. How can I start backup work, possibly by sheduler?

When I run the command

az container exec --resource-group Vitalii-demo --name vitalii-demo --exec-command "pg_dumpall -c -U postgrace > dump.sql"

I get an error error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused "exec: \ "pg_dumpall -c -U postgrace > dump.sql\": executable file not found in $PATH"

I read that

Azure Container Instances currently supports launching a single process with az container exec, and you cannot pass command arguments. For example, you cannot chain commands like in sh -c "echo FOO && echo BAR", or execute echo FOO.

Perhaps there is an opportunity to run as a task? Thanks.

  • what about this command `docker exec -it sad_brown bash -c "pg_dumpall -c -U postgrace > dump.sql"`? – Adiii Jul 02 '20 at 18:39
  • Hi, can you provide some details on how did you tried to mount the volume in postgressql container, I am trying to deploy postgresql in ACI but volume mount is failing in fileshare (azure storage account). – yatharth meena Dec 11 '20 at 11:49

1 Answers1

0

Unfortunately - and as you already mentioned - it's not possible to run any commands with arguments like echo FOO or chain multiple commands together with &&.
https://learn.microsoft.com/en-us/azure/container-instances/container-instances-exec#run-a-command-with-azure-cli

You should be able to run an interactive shell by using --exec-command /bin/bash.
But this will not help if you want to schedule the backups programatically.

pg_dumpall can also be configured by environment variables:
https://www.postgresql.org/docs/9.3/libpq-envars.html

You could launch your backup-container with the correct environment variables in order to connect your database service:

  • PGHOST
  • PGPORT
  • PGUSER
  • PGPASSWORD

When having these variables set, a simple pg_dumpall should totally do what you want.

Hope that helps.

UPDATE:
Yikes, even when configuring the connection via environment-variables you won't be able to state the desired output file... Sorry.

You could create your own Dockerimage with a pre-configured script for dumping your PostgreSQL-database.
Doing it that way, you can configure the output-file in your script and then simply execute the script with --exec-command dump_my_db.sh.
Keep in mind that your script has to be located somewhere in the default $PATH - e.g. /usr/local/bin.

Hermsi1337
  • 241
  • 2
  • 9