I have a Docker container with PostgreSQL and I want to do a pg_dump
of my database. I tried with the following code:
client = docker.from_env()
postgres = client.containers.get('my_postgres')
command = 'pg_dump --dbname=postgresql://my_user:mypassword@localhost:5432/my_db -Fc > /var/lib/postgresql/data/dumps/test.sql'
log = postgres.exec_run(command, stdout=True, stderr=True)
print(log[1])
But I get this error:
b'pg_dump: too many command-line arguments (first is ">")\nTry "pg_dump --help" for more information.\n'
Any thoughts?
CodePudding user response:
You probably need to make a shell command your executable and then pass your whole command to that shell, like this:
command = "sh -c 'pg_dump --dbname .....'"
See this question