我的网络应用程序是通过
docker compose
部署的。为了备份数据,我添加了一个 xtrabackup 容器,如下所示:
mysql_backup:
image: perconalab/percona-xtrabackup:8.4.0-1
container_name: mysql_backup
volumes:
- './mysql/db:/var/lib/mysql'
- './backup:/tmp/backup'
depends_on:
- ferry_mysql
ferry_mysql:
image: mysql:8
container_name: ferry_mysql
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: 'xxx'
MYSQL_DATABASE: 'app'
MYSQL_USER: 'app'
MYSQL_PASSWORD: 'xxx'
volumes:
- './mysql/db:/var/lib/mysql'
然后我用容器打开 bash 并开始使用以下命令进行备份:
docker compose run mysql_backup bash
xtrabackup --backup --host=ferry_mysql --target-dir=/tmp/backup/data --data-dir=/var/lib/mysql --user=root --password=xxx
然后我收到以下错误
2024-11-05T07:25:23.460993-00:00 0 [ERROR] [MY-012592] [InnoDB] Operating system error number 13 in a file operation.
2024-11-05T07:25:23.461034-00:00 0 [ERROR] [MY-012595] [InnoDB] The error means mysqld does not have the access rights to the directory.
2024-11-05T07:25:23.461043-00:00 0 [ERROR] [MY-013861] [InnoDB] Failed to list redo log files in the redo log directory ./#innodb_redo/
原来是用户权限问题。
/var/lib/mysql
中的文件归用户999
所有,id $(whami)
显示当前用户是mysql(1001)
。
为了解决此问题,我将
-u
选项添加到 docker run
以以用户 999 身份运行 bash:
docker compose run -u 999 mysql_backup bash