Skip to content

Pre Backup Command for MySQL with ">" character does not work #32

@aonurdemir

Description

@aonurdemir

docker-compose.yml (simplified for clearity):

version: "3"

services:
  ... other services
  database:
    image: mysql:8.0
    container_name: db
    volumes:
      - dbdata:/var/lib/mysql
      - dbtemp:/tmp/mysql
    labels:
      # These commands will be exec'd (in the same container) before/after the backup starts:
      - docker-volume-backup.exec-pre-backup=/usr/bin/mysqldump -u root --password=$MYSQL_ROOT_PASSWORD --all-databases > /tmp/mysql.sql
      - docker-volume-backup.exec-post-backup=rm -rfv /tmp/mysql.sql

  backup:
    image: futurice/docker-volume-backup:2.0.0
    container_name: backup
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro # Allow use of the "pre/post exec" feature
      - dbtemp:/backup/mysql.sql:ro       # Mount the temp space so it gets backed up
      - ./backups:/archive                      # Mount a local folder as the backup archive

volumes:
  dbdata:
  dbtemp:

When I run this command: docker compose exec backup ./backup.sh

I get this:

[INFO] Pre-exec command: 49dcdc0e5875 /usr/bin/mysqldump -u root --password=***** --all-databases > /tmp/mysql.sql

mysqldump: [Warning] Using a password on the command line interface can be insecure.
Usage: mysqldump [OPTIONS] database [tables]
OR     mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR     mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions