Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-38226

mariadb-dump --dir can not be run as root user

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Major
    • Resolution: Unresolved
    • 11.8, 12.1.2
    • 12.2, 11.8
    • Backup
    • None

    Description

      When trying to run mariadb-dump with the --dir flag as the root user a folder is created as the root user with several.txt files within.

      mysql then attempts to write into those files and an error is throw:

      root@HOST:~/sqldumps# ll
      total 8
      drwxr-xr-x 2 mysql mysql 4096 Nov 30 05:05 ./
      drwx------ 8 root  root  4096 Nov 30 05:05 ../
      root@HOST:~/sqldumps# mariadb-dump --dir=. --all-databases --dump-slave 
       
      --
      -- The following is the SQL position of the replication taken from SHOW SLAVE STATUS at the time of backup.
      -- Use this position when creating a clone of, or replacement server, from where the backup was taken.
      -- This new server will connects to the same primary server(s).
      --
       
      -- A corresponding to the below dump-slave CHANGE-MASTER settings to the slave gtid state is printed later in the file.
      CHANGE MASTER '' TO MASTER_LOG_FILE='host-bin.002051', MASTER_LOG_POS=310524976;
       
      mariadb-dump: Got error: 1: "Can't create/write to file '/root/sqldumps/mysql/column_stats.txt' (Errcode: 13 "Permission denied")" when executing 'SELECT INTO OUTFILE'
      root@HOST:~/sqldumps# ll
      total 12
      drwxr-xr-x 3 mysql mysql 4096 Nov 30 05:06 ./
      drwx------ 8 root  root  4096 Nov 30 05:05 ../
      drwx------ 2 root  root  4096 Nov 30 05:06 mysql/
      root@HOST:~/sqldumps# ll mysql/
      total 20
      drwx------ 2 root  root  4096 Nov 30 05:06 ./
      drwxr-xr-x 3 mysql mysql 4096 Nov 30 05:06 ../
      -rw-r--r-- 1 root  root  2022 Nov 30 05:06 column_stats.sql
      -rw-r--r-- 1 root  root  1707 Nov 30 05:06 general_log.sql
      -rw-r--r-- 1 root  root  1927 Nov 30 05:06 slow_log.sql
      root@HOST:~/sqldumps# 
      

      I was able to work around this by modifying /etc/passwd to allow the root user to switch to the mysql user:

      mysql:x:110:110:MariaDB Server,,,:/nonexistent:/bin/false
      # switched to
      mysql:x:110:110:MariaDB Server,,,:/nonexistent:/bin/bash
      

      After switching to the mysql user I was able to execute mariadb-dump with the --dir flag.

      mysql@HOST:/data/mysql_dumps$ mariadb-dump --dir=. --all-databases --dump-slave 
       
      --
      -- The following is the SQL position of the replication taken from SHOW SLAVE STATUS at the time of backup.
      -- Use this position when creating a clone of, or replacement server, from where the backup was taken.
      -- This new server will connects to the same primary server(s).
      --
       
      -- A corresponding to the below dump-slave CHANGE-MASTER settings to the slave gtid state is printed later in the file.
      CHANGE MASTER '' TO MASTER_LOG_FILE='host-bin.002051', MASTER_LOG_POS=320087919;
       
       
      -- The deferred gtid setting for slave corresponding to the dump-slave CHANGE-MASTER follows
      -- GTID position to start replication:
      -- SET GLOBAL gtid_slave_pos='0-1-1035443654';
      mysql@HOST:/data/mysql_dumps$ ls -alh
      total 60K
      drwxr-xr-x 5 mysql mysql 4.0K Nov 30 05:14 .
      drwxr-xr-x 5 mysql mysql 4.0K Nov 30 04:36 ..
      drwx------ 2 mysql mysql 4.0K Nov 30 05:14 db1
      drwx------ 2 mysql mysql  12K Nov 30 05:14 db2
      drwx------ 2 mysql mysql  36K Nov 30 05:15 db3
      

      I even tried changing ownership of the backup directory to user:mysql however the txt files created by mariadb-dump are owned only by the calling user:

      backups@HOST:/data/mysql_dumps$ mariadb-dump --dir=. --all-databases --dump-slave
       
      --
      -- The following is the SQL position of the replication taken from SHOW SLAVE STATUS at the time of backup.
      -- Use this position when creating a clone of, or replacement server, from where the backup was taken.
      -- This new server will connects to the same primary server(s).
      --
       
      -- A corresponding to the below dump-slave CHANGE-MASTER settings to the slave gtid state is printed later in the file.
      CHANGE MASTER '' TO MASTER_LOG_FILE='host-bin.002051', MASTER_LOG_POS=325744788;
       
      mariadb-dump: Got error: 1: "Can't create/write to file '/data/mysql_dumps/mysql/column_stats.txt' (Errcode: 13 "Permission denied")" when executing 'SELECT INTO OUTFILE'
      backups@HOST:/data/mysql_dumps$ ll
      total 12
      drwxr-xr-x 3 backups mysql   4096 Nov 30 05:20 ./
      drwxr-xr-x 5 mysql   mysql   4096 Nov 30 04:36 ../
      drwx------ 2 backups backups 4096 Nov 30 05:20 mysql/
      backups@HOST:/data/mysql_dumps$ cd mysql/
      backups@HOST:/data/mysql_dumps/mysql$ ll
      total 20
      drwx------ 2 backups backups 4096 Nov 30 05:20 ./
      drwxr-xr-x 3 backups mysql   4096 Nov 30 05:20 ../
      -rw-rw-r-- 1 backups backups 2022 Nov 30 05:20 column_stats.sql
      -rw-rw-r-- 1 backups backups 1707 Nov 30 05:20 general_log.sql
      -rw-rw-r-- 1 backups backups 1927 Nov 30 05:20 slow_log.sql
      
      

      Attachments

        Issue Links

          Activity

            People

              wlad Vladislav Vaintroub
              TheAnnihilator Ben Gnoinski
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.