Fedora 38
Sponsored Link

MariaDB 10.9 : バックアップ2023/04/28

 
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] 2023-04-28 09:52:46 Connecting to MariaDB server host: localhost, user: root, password: not set, port: not set, socket: not set
[00] 2023-04-28 09:52:46 Using server version 10.9.4-MariaDB
mariabackup based on MariaDB server 10.9.4-MariaDB Linux (x86_64)
[00] 2023-04-28 09:52:46 uses posix_fadvise().
[00] 2023-04-28 09:52:46 cd to /var/lib/mysql/
[00] 2023-04-28 09:52:46 Loading plugins
[00] 2023-04-28 09:52:46 open files limit requested 0, set to 1024
[00] 2023-04-28 09:52:46 mariabackup: using the following InnoDB configuration:
[00] 2023-04-28 09:52:46 innodb_data_home_dir =
.....
.....
[00] 2023-04-28 09:52:47 Writing backup-my.cnf
[00] 2023-04-28 09:52:47         ...done
[00] 2023-04-28 09:52:47 Writing xtrabackup_info
[00] 2023-04-28 09:52:47         ...done
[00] 2023-04-28 09:52:47 Redo log (from LSN 49181 to 49197) was copied.
[00] 2023-04-28 09:52:47 completed OK!

[root@www ~]#
ll /home/mariadb_backup

total 12744
-rw-r-----. 1 root root   417792 Apr 28 09:52 aria_log.00000001
-rw-r-----. 1 root root       52 Apr 28 09:52 aria_log_control
-rw-r-----. 1 root root      391 Apr 28 09:52 backup-my.cnf
-rw-r-----. 1 root root 12582912 Apr 28 09:52 ibdata1
-rw-r-----. 1 root root    12304 Apr 28 09:52 ib_logfile0
drwx------. 2 root root     4096 Apr 28 09:52 mysql
drwx------. 2 root root       20 Apr 28 09:52 performance_schema
drwx------. 2 root root     8192 Apr 28 09:52 sys
drwx------. 2 root root       64 Apr 28 09:52 test_database
-rw-r-----. 1 root root       73 Apr 28 09:52 xtrabackup_checkpoints
-rw-r-----. 1 root root      429 Apr 28 09:52 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 685843 Apr 28 10:00 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.9.4-MariaDB Linux (x86_64)
[00] 2023-04-28 10:01:52 cd to /root/mariadb_backup/
[00] 2023-04-28 10:01:52 open files limit requested 0, set to 1024
[00] 2023-04-28 10:01:52 Loading plugins from provider_lz4=provider_lz4;provider_lzma=provider_lzma
[00] 2023-04-28 10:01:52 Loading plugins
[00] 2023-04-28 10:01:52         Plugin parameter :  '--plugin_load=provider_lz4=provider_lz4;provider_lzma=provider_lzma'
[00] 2023-04-28 10:01:52         Plugin parameter :  '--prepare'
[00] 2023-04-28 10:01:52         Plugin parameter :  '--target-dir'
[00] 2023-04-28 10:01:52         Plugin parameter :  '/root/mariadb_backup'
[00] 2023-04-28 10:01:52 This target seems to be not prepared yet.
[00] 2023-04-28 10:01:52 mariabackup: using the following InnoDB configuration for recovery:
[00] 2023-04-28 10:01:52 innodb_data_home_dir = .
[00] 2023-04-28 10:01:52 innodb_data_file_path = ibdata1:12M:autoextend
[00] 2023-04-28 10:01:52 innodb_log_group_home_dir = .
[00] 2023-04-28 10:01:52 InnoDB: Using Linux native AIO
[00] 2023-04-28 10:01:52 Starting InnoDB instance for recovery.
[00] 2023-04-28 10:01:52 mariabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
2023-04-28 10:01:52 0 [Note] InnoDB: Compressed tables use zlib 1.2.12
2023-04-28 10:01:52 0 [Note] InnoDB: Number of transaction pools: 1
2023-04-28 10:01:52 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
2023-04-28 10:01:52 0 [Note] InnoDB: Using Linux native AIO
2023-04-28 10:01:52 0 [Note] InnoDB: Initializing buffer pool, total size = 100.000MiB, chunk size = 100.000MiB
2023-04-28 10:01:52 0 [Note] InnoDB: Completed initialization of buffer pool
2023-04-28 10:01:52 0 [Note] InnoDB: Buffered log writes (block size=512 bytes)
[00] 2023-04-28 10:01:52 Last binlog file , position 0
[00] 2023-04-28 10:01:52 completed OK!

# リストア実行

[root@node01 ~]#
mariabackup --copy-back --target-dir /root/mariadb_backup

mariabackup based on MariaDB server 10.9.4-MariaDB Linux (x86_64)
[01] 2023-04-28 10:02:15 Copying ib_logfile0 to /var/lib/mysql/ib_logfile0
[01] 2023-04-28 10:02:15         ...done
[01] 2023-04-28 10:02:15 Copying ibdata1 to /var/lib/mysql/./ibdata1
[01] 2023-04-28 10:02:15         ...done
[01] 2023-04-28 10:02:15 Copying ./mysql/innodb_table_stats.ibd to /var/lib/mysql/mysql/innodb_table_stats.ibd
[01] 2023-04-28 10:02:15         ...done
[01] 2023-04-28 10:02:15 Copying ./mysql/innodb_index_stats.ibd to /var/lib/mysql/mysql/innodb_index_stats.ibd
[01] 2023-04-28 10:02:15         ...done
.....
.....
[01] 2023-04-28 10:02:16 Copying ./aria_log.00000001 to /var/lib/mysql/aria_log.00000001
[01] 2023-04-28 10:02:16         ...done
[01] 2023-04-28 10:02:16 Copying ./xtrabackup_info to /var/lib/mysql/xtrabackup_info
[01] 2023-04-28 10:02:16         ...done
[00] 2023-04-28 10:02:16 completed OK!

[root@node01 ~]#
chown -R mysql:mysql /var/lib/mysql

[root@node01 ~]#
systemctl start mariadb

関連コンテンツ