Xtrabackup in Docker FROM percona/percona-xtrabackup:8.0 for MySQL 8.33 on docker fails with "[ERROR] [MY-012592] [InnoDB] Operating system error number 13 in a file operation."

MySQL Server 8.0.33 runs in docker container (FROM mysql:8-debian).
Xtrabackup 8.0 runs in docker container (FROM percona/percona-xtrabackup:8.0)
The command
sudo docker run --rm --name xtrabackup80-container --user 1001 --cap-add=sys_nice
–volumes-from v2_db
percona/percona-xtrabackup:latest
xtrabackup
–host=localhost
–port=3306
–socket=/run/mysqld/mysqld.sock
–backup
–datadir=/var/lib/mysql
–target-dir=/home/backups/xtrabackup
–user=root
–password=[pssword]
generates error :
[ERROR] [MY-012592] [InnoDB] Operating system error number 13 in a file operation.
[ERROR] [MY-012595] [InnoDB] The error means mysqld does not have the access rights to the directory.
[ERROR] [MY-013861] [InnoDB] Failed to list redo log files in the redo log directory ./#innodb_redo/

Here is the whole xtrabackup output:
[Note] [MY-011825] [Xtrabackup] recognized server arguments: --datadir=/var/lib/mysql
[Note] [MY-011825] [Xtrabackup] recognized client arguments: --host=localhost --port=3306 --socket=/run/mysqld/mysqld.sock --backup=1 --target-dir=/home/backups/xtrabackup --user=root --password=*
xtrabackup version 8.0.33-27 based on MySQL server 8.0.33 Linux (x86_64) (revision id: 6743d8c7)
[Note] [MY-011825] [Xtrabackup] perl binary not found. Skipping the version check
[Note] [MY-011825] [Xtrabackup] Connecting to MySQL server host: localhost, user: root, password: set, port: 3306, socket: /run/mysqld/mysqld.sock
[Note] [MY-011825] [Xtrabackup] Using server version 8.0.33
[Note] [MY-011825] [Xtrabackup] Executing LOCK INSTANCE FOR BACKUP …
[Note] [MY-011825] [Xtrabackup] uses posix_fadvise().
[Note] [MY-011825] [Xtrabackup] cd to /var/lib/mysql
[Note] [MY-011825] [Xtrabackup] open files limit requested 0, set to 1048576
[Note] [MY-011825] [Xtrabackup] using the following InnoDB configuration:
[Note] [MY-011825] [Xtrabackup] innodb_data_home_dir = .
[Note] [MY-011825] [Xtrabackup] innodb_data_file_path = ibdata1:12M:autoextend
[Note] [MY-011825] [Xtrabackup] innodb_log_group_home_dir = ./
[Note] [MY-011825] [Xtrabackup] innodb_log_files_in_group = 2
[Note] [MY-011825] [Xtrabackup] innodb_log_file_size = 50331648
[Note] [MY-011825] [Xtrabackup] inititialize_service_handles suceeded
[ERROR] [MY-012592] [InnoDB] Operating system error number 13 in a file operation.
[ERROR] [MY-012595] [InnoDB] The error means mysqld does not have the access rights to the directory.
[ERROR] [MY-013861] [InnoDB] Failed to list redo log files in the redo log directory ./#innodb_redo/

Please help

Hello @geneva_nn

$ perror 13
OS error code  13:  Permission denied

You have a permissions issue between your docker container and the volume. Are you following some guide? I’m not seeing a volume:path mapping.

Additionally, please don’t use percona/percona-xtrabackup:latest. You should use the specific PXB version that matches your MySQL version.

Hello, @matthewb !
Thank you for the advices!
My volumes for MySQL container are:
- ${DATABASE_VOLUME}:/var/lib/mysql
- ${DATABASE_SOCK_DIR}:/run/mysqld
- ${DATABASE_LOG_DIR}:/var/log/mysql:rw
- ${DATABASE_BACKUP_DIR}:/home/backups
What particular volume permissions I should look at?
On the host side ${DATABASE_VOLUME} has 777 permission.
${DATABASE_BACKUP_DIR} has 777 permissions.
Even if I use FROM percona/percona-xtrabackup:8.0, the error is the same.
On the host side user:group systemd-coredump:systemd-coredump are used for /var/log/mysql, /var/run/mysqld, ${DATABASE_VOLUME}, ${DATABASE_BACKUP_DIR}.

I would do some basic diagnosis. Try mounting the mysql data volume into a plain container and see what the permissions look like from inside. That might give some insight.

Well, /var/lib/mysql should be user:group mysql:mysql

@matthewb Thank you for the reply! I found a solution for my own problem.
I did check permissions for the /var/lib/mysql folder. Inside of the mysql 8.0 docker container is is owner by ‘mysql’’ user. The volume on the host side for the /var/lib/mysql is owned by systemd-coredump:systemd-coredump.
After I looked inside of percona/percona-xtrabackup:8.0 image layers on DOcker, I discovered that the USER inside of the container has UID 1001:

35    USER 1001                            0 B
36   CMD ["/usr/bin/xtrabackup"]           0 B

On my server MySQL runs in docker also and a host machine has no user with UID 1001. I assumed the user with UID 1001 should be ‘mysql’ user, that is translated from docker ‘mysql’ user into host ‘systemd-coredump’ user. I found UID and GID of the ‘systemd-coredump’ user on a host machine (UID=999).
And when I start xtrabackup container in docker with “–user 999:999” option, everything starts working.
Here is my xtrabackup docker run command:

docker run --rm --name xtrabackup80-container \

–user 999:999 --cap-add=sys_nice \

–volumes-from MySQL80-container \

percona/percona-xtrabackup:8.0 \

xtrabackup \

–defaults-file=/etc/mysql/conf.d/my.cnf \

–host=localhost \

–port=3306 \

–socket=/run/mysqld/mysqld.sock \

–backup \

–datadir=/var/lib/mysql \

–target-dir=/home/backups/xtrabackup \

–user=[backup-user] \

–password=[password]

Thank you for giving me the inspiration