Search code examples
mysqlbackuppercona

xtrabackup only performs a full back up if is executed with super user privileges


According to this link, I executed this command to backup my database:

 xtrabackup --backup --databases='database' --target-dir=/home/user/backups --datadir=/var/lib/mysql/

But I get the following error:

160520 02:00:54  version_check Done.
160520 02:00:54 Connecting to MySQL server host: localhost, user: root, password: set, port: 0, socket: /var/lib/mysql/mysql.sock
Using server version 5.5.44-MariaDB
xtrabackup version 2.4.2 based on MySQL server 5.7.11 Linux (x86_64) (revision id: 8e86a84)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /var/lib/mysql/
xtrabackup: open files limit requested 0, set to 1024
xtrabackup: using the following InnoDB configuration:
xtrabackup:   innodb_data_home_dir = .
xtrabackup:   innodb_data_file_path = ibdata1:10M:autoextend
xtrabackup:   innodb_log_group_home_dir = .
xtrabackup:   innodb_log_files_in_group = 2
xtrabackup:   innodb_log_file_size = 5242880
InnoDB: Number of pools: 1
InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to the directory.

I solved it by running the same command with sudo, the problem is that the backup directory gets created as root so my user doesn't have access to that directory so I always have to change the ownership recursively for that directory so I can be able to read it. This method isn't pretty efficient to me.

  • Is there any other alternative to do this?
  • Do I always have to execute this command with sudo?

Solution

  • The xtrabackup tool runs as the user invoking it and that user must be able to read the database files which are normally owned by mysql:mysql and mode 660.

    An easy fix is usually to add the user to the mysql group, for example:

    useradd -G mysql yves
    

    Then logout and re-open the session, it should work.