MariaDB 10.5 : バックアップ2021/06/25 |
MariaDB のデータベースを バックアップ/リストア する際は付属のツールで実行可能です。
|
|
[1] | バックアップツールは通常 MariaDB Server と同時にインストールされますが、もしをインストールされていない場合は以下のようにしてインストールします。 |
[root@www ~]# dnf -y install mariadb-backup
|
[2] | バックアップを実行します。 例として、[/home/mariadb_backup] ディレクトリ配下にバックアップを取得します。 |
[root@www ~]# mkdir /home/mariadb_backup [root@www ~]# mariabackup --backup --target-dir /home/mariadb_backup -u root [00] 2021-06-24 02:43:16 uses posix_fadvise(). [00] 2021-06-24 02:43:16 cd to /var/lib/mysql/ [00] 2021-06-24 02:43:16 open files limit requested 0, set to 1024 [00] 2021-06-24 02:43:16 mariabackup: using the following InnoDB configuration: [00] 2021-06-24 02:43:16 innodb_data_home_dir = [00] 2021-06-24 02:43:16 innodb_data_file_path = ibdata1:12M:autoextend [00] 2021-06-24 02:43:16 innodb_log_group_home_dir = ./ [00] 2021-06-24 02:43:16 InnoDB: Using Linux native AIO 2021-06-24 2:43:16 0 [Note] InnoDB: Number of pools: 1 ..... ..... [00] 2021-06-24 02:43:18 ...done [00] 2021-06-24 02:43:18 Writing xtrabackup_info [00] 2021-06-24 02:43:18 ...done [00] 2021-06-24 02:43:18 Redo log (from LSN 47598 to 47610) was copied. [00] 2021-06-24 02:43:18 completed OK![root@www ~]# ll /home/mariadb_backup total 12340 -rw-r-----. 1 root root 24576 Jun 24 02:43 aria_log.00000001 -rw-r-----. 1 root root 52 Jun 24 02:43 aria_log_control -rw-r-----. 1 root root 297 Jun 24 02:43 backup-my.cnf -rw-r-----. 1 root root 992 Jun 24 02:43 ib_buffer_pool -rw-r-----. 1 root root 12582912 Jun 24 02:43 ibdata1 -rw-r-----. 1 root root 2560 Jun 24 02:43 ib_logfile0 drwx------. 2 root root 4096 Jun 24 02:43 mysql drwx------. 2 root root 20 Jun 24 02:43 performance_schema drwx------. 2 root root 64 Jun 24 02:43 test_database -rw-r-----. 1 root root 73 Jun 24 02:43 xtrabackup_checkpoints -rw-r-----. 1 root root 429 Jun 24 02:43 xtrabackup_info |
[3] | バックアップしたデータを、他ホスト上の MariaDB サーバーへリストアします。 事前にバックアップしたデータを [tar] でまとめるなり [rsync] でそのまま転送する等して、バックアップデータをリストア先サーバーに転送しておいてください。 |
# MariaDB を停止して既存データは削除 [root@node01 ~]# systemctl stop mariadb [root@node01 ~]# rm -rf /var/lib/mysql/*
# 転送したバックアップデータ [root@node01 ~]# ll mariadb_backup.tar.gz -rw-r--r--. 1 root root 409339 Jun 24 02:53 mariadb_backup.tar.gz [root@node01 ~]# tar zxvf mariadb_backup.tar.gz # リストア事前タスク実行 : [completed OK] であれば OK [root@node01 ~]# mariabackup --prepare --target-dir /root/mariadb_backup mariabackup based on MariaDB server 10.5.9-MariaDB Linux (x86_64) [00] 2021-06-24 02:54:22 cd to /root/mariadb_backup/ [00] 2021-06-24 02:54:22 open files limit requested 0, set to 1024 [00] 2021-06-24 02:54:22 This target seems to be not prepared yet. [00] 2021-06-24 02:54:22 mariabackup: using the following InnoDB configuration for recovery: [00] 2021-06-24 02:54:22 innodb_data_home_dir = . [00] 2021-06-24 02:54:22 innodb_data_file_path = ibdata1:12M:autoextend [00] 2021-06-24 02:54:22 innodb_log_group_home_dir = . [00] 2021-06-24 02:54:22 InnoDB: Using Linux native AIO [00] 2021-06-24 02:54:22 Starting InnoDB instance for recovery. [00] 2021-06-24 02:54:22 mariabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter) 2021-06-24 2:54:22 0 [Note] InnoDB: Uses event mutexes 2021-06-24 2:54:22 0 [Note] InnoDB: Compressed tables use zlib 1.2.11 2021-06-24 2:54:22 0 [Note] InnoDB: Number of pools: 1 2021-06-24 2:54:22 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions 2021-06-24 2:54:22 0 [Note] InnoDB: Using Linux native AIO 2021-06-24 2:54:22 0 [Note] InnoDB: Initializing buffer pool, total size = 104857600, chunk size = 104857600 2021-06-24 2:54:22 0 [Note] InnoDB: Completed initialization of buffer pool 2021-06-24 2:54:22 0 [Note] InnoDB: Starting crash recovery from checkpoint LSN=47598,47598 [00] 2021-06-24 02:54:22 Last binlog file , position 0 [00] 2021-06-24 02:54:22 completed OK! # リストア実行 [root@node01 ~]# mariabackup --copy-back --target-dir /root/mariadb_backup mariabackup based on MariaDB server 10.5.9-MariaDB Linux (x86_64) [01] 2021-06-24 02:54:40 Copying ibdata1 to /var/lib/mysql/ibdata1 [01] 2021-06-24 02:54:40 ...done [01] 2021-06-24 02:54:40 Copying ./mysql/innodb_table_stats.ibd to /var/lib/mysql/mysql/innodb_table_stats.ibd [01] 2021-06-24 02:54:40 ...done [01] 2021-06-24 02:54:40 Copying ./mysql/innodb_index_stats.ibd to /var/lib/mysql/mysql/innodb_index_stats.ibd [01] 2021-06-24 02:54:40 ...done ..... ..... [01] 2021-06-24 02:54:40 Copying ./ib_buffer_pool to /var/lib/mysql/ib_buffer_pool [01] 2021-06-24 02:54:40 ...done [01] 2021-06-24 02:54:40 Copying ./xtrabackup_info to /var/lib/mysql/xtrabackup_info [01] 2021-06-24 02:54:40 ...done [00] 2021-06-24 02:54:40 completed OK![root@node01 ~]# chown -R mysql. /var/lib/mysql [root@node01 ~]# systemctl start mariadb |
Sponsored Link |