从天蓝色的容器实例备份postgresql

时间:2020-07-02 18:28:30

标签: postgresql azure docker azure-container-instances

我创建了Azure容器实例并在其中运行了postgresql。挂载了一个天蓝色的容器实例存储帐户。我该如何开始备份工作,可能是由sheduler?

当我运行命令时

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

我收到一个错误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"

我读到了

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.

也许有机会作为一项任务来运行?谢谢。

1 个答案:

答案 0 :(得分:0)

很遗憾-正如您已经提到的-无法运行带有参数echo FOO的任何命令或将多个命令与&&链接在一起。
https://developer.apple.com/documentation/swiftui/lazyvgrid

您应该可以使用--exec-command /bin/bash运行交互式shell。
但这对您要以编程方式安排备份没有帮助。

pg_dumpall也可以由环境变量配置:
https://docs.microsoft.com/en-us/azure/container-instances/container-instances-exec#run-a-command-with-azure-cli

您可以使用正确的环境变量启动备份容器,以连接数据库服务:

  • PGHOST
  • PGPORT
  • PGUSER
  • PGPASSWORD

设置了这些变量后,简单的pg_dumpall应该完全可以满足您的要求。

希望有帮助。

更新:
抱歉,即使通过环境变量配置连接,您也无法声明所需的输出文件...对不起。

您可以使用用于转储PostgreSQL数据库的预配置脚本创建自己的Dockerimage。
这样,您可以在脚本中配置输出文件,然后只需使用--exec-command dump_my_db.sh执行脚本。
请注意,您的脚本必须位于默认$PATH中的某个位置,例如/usr/local/bin