mariabackup of database running in docker I have MariaDB running in a Docker container with the container's data directory /var/lib/mysql/ mapped to the host directory /mnt/data/.

I want to run mariabackup from the host to create a physical backup of the data directory (which is /mnt/data as far as the host is concerned and /var/lib/mysql/ from the container's perspective).

I get an error, however, running mariabackup that says it cannot find the data directory:

$ mariabackup --backup --user=backup --stream=xbstream -h /mnt/data/ | gzip &gt; foo.gz
Connecting to MySQL server host: 127.0.0.1, user: backup, password: set, port: 3306 ...
Using server version 10.3.10-MariaDB-1:10.3.10+maria~bionic
Warning: MySQL variable 'datadir' points to nonexistent directory '/var/lib/mysql/'
Warning: option 'datadir' has different balues:
    '/mnt/data/' in defaults file
    '/var/lib/mysql/' in SHOW VARIABLES
mariabackup based on MariaDB server 10.1.29-MariaDB debian-linux-gnu (x86_54)
mariabackup: uses posix_fadvise().
mariabackup: Can't change dir to '/var/lib/mysql/ (Errcode: 2 "No such file or directory")
mariabackup: cannot my_setwd /var/lib/mysql/


Something similar happens when I don't specify the data directory with the -h flag. I expected mariabackup to cd to /mnt/data/, execute the commands it needs to run on the server, and everything to simply work because it doesn't seem like it should matter what SHOW VARIABLES says if there's a valid data directory at /mnt/data/.


I understand the warning that mariabackup sees two different paths for datadir, one that I provided via -h and another on the server.
Why, however, does mariabackup try using /var/lib/mysql/ when I explicity said (via the -h flag) that the data directory is /mnt/data/? Can I get mariabackup to ignore what the server says and cd to the directory I provided?
If my approach is all wrong, what's the best way to do physical backups of a server running in a container with data directory mapped to a host directory?
Create a symlink on your host so that Mariabackup thinks /var/lib/mysql exists. Then delete the symlink once you're done.

$ sudo ln -s /mnt/data /var/lib/mysql