Mysql
MariaDB 在使用 mariabackup 恢復增量備份後不啟動
作業系統:CentOS 7
MariaDB:mariadb Ver 15.1 Distrib 10.4.12-MariaDB,適用於 Linux (x86_64),使用 readline 5.1
我每 7 天在複製從站上創建一次完整備份,並在此基礎上每小時創建一次增量備份。
此腳本用於創建備份:run-mariabackup.sh
要恢復備份,我正在使用此過程。
但是,在恢復備份之後 MariaDB 不會啟動。
systemd: Starting MariaDB 10.4.12 database server... mysqld: [Note] /usr/sbin/mysqld (mysqld 10.4.12-MariaDB) starting as process 11363 ... mysqld: [ERROR] mysqld: File '/var/lib/mysql/aria_log_control' not found (Errcode: 13 "Permission denied") mysqld: [ERROR] mysqld: Got error 'Can't open file' when trying to use aria control file '/var/lib/mysql/aria_log_control' mysqld: [ERROR] Plugin 'Aria' init function returned error. mysqld: [ERROR] Plugin 'Aria' registration as a STORAGE ENGINE failed. mysqld: [Note] InnoDB: Using Linux native AIO mysqld: [ERROR] InnoDB: Operating system error number 13 in a file operation. mysqld: [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory. mysqld: [ERROR] InnoDB: os_file_get_status() failed on './ibdata1'. Can't determine file permissions mysqld: [ERROR] Plugin 'InnoDB' init function returned error. mysqld: [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed. mysqld: [Note] Plugin 'FEEDBACK' is disabled. mysqld: [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded mysqld: [ERROR] Failed to initialize plugins. mysqld: [ERROR] Aborting systemd: mariadb.service: main process exited, code=exited, status=1/FAILURE
當然我
chown -R mysql:mysql /var/lib/mysql
之前已經做過了,所以這個錯誤讓我感到困惑。在此錯誤之後,我嘗試chmod -R 777 /var/lib/mysql
查看是否缺少某些權限,但再次啟動 MariaDB 時,我遇到了同樣的錯誤。以下是我恢復備份的具體步驟:
cd /home/mysqlbackup/ for i in $(find . -name backup.stream.gz | grep '2020-03-12_12-08-44' | xargs dirname); do mkdir -p $i/backup; zcat $i/backup.stream.gz | mbstream -x -C $i/backup/; done mariabackup --prepare --target-dir base/2020-03-12_12-08-44/backup/ --user backup --password mypass mariabackup --prepare --target-dir base/2020-03-12_12-08-44/backup/ --user backup --password mypass --incremental-dir incr/2020-03-12_12-08-44/2020-03-12_13-24-20/backup/ mariabackup --prepare --target-dir base/2020-03-12_12-08-44/backup/ --user backup --password mypass --incremental-dir incr/2020-03-12_12-08-44/2020-03-12_13-54-25/backup/ mariabackup --prepare --target-dir base/2020-03-12_12-08-44/backup/ --user backup --password mypass --incremental-dir incr/2020-03-12_12-08-44/2020-03-12_14-00-02/backup/ mariabackup --prepare --target-dir base/2020-03-12_12-08-44/backup/ --user backup --password mypass --incremental-dir incr/2020-03-12_12-08-44/2020-03-12_15-00-01/backup/ mariabackup --prepare --target-dir base/2020-03-12_12-08-44/backup/ --user backup --password mypass --incremental-dir incr/2020-03-12_12-08-44/2020-03-12_16-00-01/backup/ systemctl stop mariadb mv /var/lib/mysql/ /var/lib/mysql_bak/ mariabackup --copy-back --target-dir base/2020-03-12_12-08-44/backup/ --user backup --password mypass --datadir /var/lib/mysql/ chown -R mysql:mysql /var/lib/mysql/ systemctl start mariadb
當權限看起來正確,但您仍然獲得
Errcode: 13 "Permission denied"
時,接下來要檢查的是安全系統是否導致了問題。在 CentOS 上,該系統是 SELinux。要檢查它是否在強制模式下執行,請執行以下命令:sestatus
您可以
setenforce 0
暫時將其更改為許可模式。為避免該問題:
最初安裝 MariaDB 時,應為所有文件正確設置 SELinux 安全上下文。但是,當您這樣做時
mv /var/lib/mysql/ /var/lib/mysql_bak/
,您將其刪除。我認為您可以通過簡單地執行restorecon -Rv /var/lib/mysql
.如需參考,請閱讀 MariaDB 知識庫中的此頁面:Security-Enhanced Linux with MariaDB