Backup

mariabackup 失敗並出現錯誤:cannot mkdir 2: /data/backups/mariadb/

  • February 8, 2022

嘗試使用 mariabackup 備份我們所有的數據庫。首先創建的備份目錄為

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

並繼續做備份

# 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/

嘗試了護目鏡和各種選項它沒有工作所以最後嘗試沒有 –target-directory 選項並再次進行備份,它成功執行並得到了這個

# 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

我做錯了什麼或如何使用 —-target-directory 執行它

您的命令中有錯字。命令

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

創建了目錄 /mnt/data/backup/mariadb 但命令

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

要求mariabackup寫入 /mnt/data/backup s /mariadb。該目錄的父目錄 /mnt/data/backup可能不存在。由於mariabackup根據其手冊頁僅在必要時創建目標目錄本身,而不是通向它的路徑,因此它出錯了。

引用自:https://serverfault.com/questions/1092819