Open aonurdemir opened 3 years ago
Hi, I'm also trying to backup a mysql database but I have another issue.
labels:
- docker-volume-backup.exec-pre-test=mysqldump -u root -p'XXXX' dbname > /tmp/dump/dbname.sql
I have no issue with the ">" character
When I run the ./backup command from the backup container console I get something like :
Pre-exec command: d261578e6e82 mysqldump -u root -p'XXXXX' dbname > /tmp/dump/dbname.sql
mysqldump: Got error: 1045: Access denied for user 'root'@'localhost' (using password: YES) when trying to connect
I tried to run the mysqldump command from the db container's console : it's fine.
Thanks for your help.
Did you try to pass your password without single quotes?
I suppose I am having problems about preventing my shell to interpret '>' instead of passing it to inner shell. The behaviour still continues on both Amazon Linux AMI and MacOS.
Indeed, I suspect the backup container fails to pass the '>' character to the db container while running this: Pre-exec command: 49dcdc0e5875 /usr/bin/mysqldump -u root --password=***** --all-databases > /tmp/mysql.sql
. I thnik it is not related to my docker host machine. However @platanax says the command works well. So, I am confused here.
I appreciate any help!
Digging...
Did you try to pass your password without single quotes?
Yes but I have some special chars in the password and it does not work without those :-(
I suppose I am having problems about preventing my shell to interpret '>' instead of passing it to inner shell. The behaviour still continues on both Amazon Linux AMI and MacOS.
Indeed, I suspect the backup container fails to pass the '>' character to the db container while running this:
Pre-exec command: 49dcdc0e5875 /usr/bin/mysqldump -u root --password=***** --all-databases > /tmp/mysql.sql
. I thnik it is not related to my docker host machine. However @platanax says the command works well. So, I am confused here.I appreciate any help!
Digging...
Silly suggestion but did you try without the path ?
Thanks anyway :) Yes, I tried. No luck :(
I removed --all-databases
and give database name and the problem changed to this:
Pre-exec command: 4a907b4efb38 mysqldump -u root --password=123456* wordpress > /tmp/mysql.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
mysqldump: Couldn't find table: ">"
It seems like it interprets >
as table name rather than stdout direction. Actually, this explains --all-databases
behaviour since it sees >
as an argument after--all-databases
argument which is a bad usage.
PS: My password contains *
. Above is an example of real password.
UPDATE I think we are having this kind of problem:
Redirecting the output of a command running inside the docker container would require setting the interactive flag on the docker exec
command. I believe the issue is explained on StackOverflow.
You are almost there, you just need to add the -i flag to make the pipe work:
-i, --interactive Keep STDIN open even if not attached
docker exec -i container-name mysqldump [options] database > database.sql.xz
I replaced the pipe by a file redirection but it will work the same with a Pipe. Just make sure to don't use the -t option as this will break it.
I'm looking for a way to pg_dump
a PostGreSQL database in a similar way:
labels:
- docker-volume-backup.exec-pre-backup=pg_dump --dbname=$POSTGRES_DB > /tmp/backup/recipes.pgsql
- docker-volume-backup.exec-pre-backup=pg_dump --dbname=$POSTGRES_DB > /tmp/backup/recipes.pgsql
But it is throwing "file not found" errors. This is expected, as the path /tmp/backup
does not exist on the host but only as a mounted volume inside the container.
Well, now I feel stupid. I should have read the link above to the end. š
Here's a working configuration:
labels:
- docker-volume-backup.exec-pre-backup=sh -c "pg_dump --dbname=$POSTGRES_DB > /tmp/backup/recipes.pgsql"
- docker-volume-backup.exec-post-backup=rm -rfv /tmp/backup/recipes.pgsql
The trick is to wrap the command in sh -c "{COMMAND}"
. šš»
docker-compose.yml (simplified for clearity):
When I run this command:
docker compose exec backup ./backup.sh
I get this:
When I change pre-backup command by removing ">" character and the file, it dumps all sql to stdout and works well. However, it is useless to print all sql to stdout.
I am not sure this a bug of this repository or docker.
I appreciate any help. Thanks in advance.