MariaDB – How to Fix mariabackup Error: cannot mkdir 2: /data/backups/mariadb/

backupmariadbrocky-linux

Trying to use mariabackup to take backup of all our databases. First created backup directory as

mkdir -p /mnt/data/backup/mariadb
chown -R mysql:mysql /mnt/data/backup/mariadb

And proceed to do backup

# mariabackup --backup --target-dir=/mnt/data/backups/mariadb/ --user=root --password=xxxxxxxx
[00] 2022-02-06 11:28:46 Connecting to MySQL server host: localhost, user: root, password: set, port: not set, socket: /mnt/data/mysql/mysql.sock
[00] 2022-02-06 11:28:46 Using server version 10.3.28-MariaDB
mariabackup based on MariaDB server 10.3.28-MariaDB Linux (x86_64)
[00] 2022-02-06 11:28:46 uses posix_fadvise().
[00] 2022-02-06 11:28:46 cd to /mnt/data/mysql/
[00] 2022-02-06 11:28:46 open files limit requested 0, set to 1024
[00] 2022-02-06 11:28:46 mariabackup: using the following InnoDB configuration:
[00] 2022-02-06 11:28:46 innodb_data_home_dir = 
[00] 2022-02-06 11:28:46 innodb_data_file_path = ibdata1:12M:autoextend
[00] 2022-02-06 11:28:46 innodb_log_group_home_dir = ./
[00] 2022-02-06 11:28:46 InnoDB: Using Linux native AIO
2022-02-06 11:28:46 0 [Note] InnoDB: Number of pools: 1
[00] 2022-02-06 11:28:46 Error: cannot mkdir 2: /mnt/data/backups/mariadb/

tried goggling and various options it did not worked so finally tried without –target-directory option and did backup again and it worked successfully and got this

# ls -ld /mnt/data/backup
drwxr-xr-x 3 mysql mysql 21 Feb  6 11:41 /mnt/data/backup

# pwd
/mnt/data/mysql

# ll
total 8
drwxr-xr-x  3 mysql mysql   21 Feb  6 11:41 backup
drwxr-xr-x 27 mysql mysql 4096 Feb  4 19:07 mysql
drwx------ 27 root  root  4096 Feb  6 11:22 xtrabackup_backupfiles

What did I do wrong or how do I run this with —-target-directory

Best Answer

You've got a typo in your commands. The commands

mkdir -p /mnt/data/backup/mariadb
chown -R mysql:mysql /mnt/data/backup/mariadb

created the directory /mnt/data/backup/mariadb but the command

mariabackup --backup --target-dir=/mnt/data/backups/mariadb/ ...

asked mariabackup to write to /mnt/data/backups/mariadb. The parent directory /mnt/data/backups of that directory probably does not exist. Since mariabackup as per its manpage only creates the target directory itself if necessary, but not the path leading to it, it errored out.

Related Topic