MariaDB : バックアップ2020/05/09 |
MariaDB のデータベースを バックアップ/リストア する際は付属のツールで実行可能です。
|
|
[1] | バックアップツールをインストールします。 |
root@www:~# apt -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] 2020-05-09 16:47:33 Executing UNLOCK TABLES [00] 2020-05-09 16:47:33 All tables unlocked [00] 2020-05-09 16:47:33 Copying ib_buffer_pool to /home/mariadb_backup/ib_buffer_pool [00] 2020-05-09 16:47:33 ...done [00] 2020-05-09 16:47:33 Backup created in directory '/home/mariadb_backup/' [00] 2020-05-09 16:47:33 Writing backup-my.cnf [00] 2020-05-09 16:47:33 ...done [00] 2020-05-09 16:47:33 Writing xtrabackup_info [00] 2020-05-09 16:47:33 ...done [00] 2020-05-09 16:47:33 Redo log (from LSN 1631383 to 1631392) was copied. [00] 2020-05-09 16:47:33 completed OK!root@www:~# ll /home/mariadb_backup total 12348 drwxr-xr-x 5 root root 4096 May 9 16:47 ./ drwxr-xr-x 4 root root 4096 May 9 16:47 ../ -rw-r----- 1 root root 16384 May 9 16:47 aria_log.00000001 -rw-r----- 1 root root 52 May 9 16:47 aria_log_control -rw-r----- 1 root root 324 May 9 16:47 backup-my.cnf -rw-r----- 1 root root 1004 May 9 16:47 ib_buffer_pool -rw-r----- 1 root root 12582912 May 9 16:47 ibdata1 -rw-r----- 1 root root 2560 May 9 16:47 ib_logfile0 drwx------ 2 root root 4096 May 9 16:47 mysql/ drwx------ 2 root root 4096 May 9 16:47 performance_schema/ drwx------ 2 root root 4096 May 9 16:47 test_database/ -rw-r----- 1 root root 77 May 9 16:47 xtrabackup_checkpoints -rw-r----- 1 root root 443 May 9 16:47 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 214745 May 9 16:59 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.3.22-MariaDB debian-linux-gnu (x86_64) [00] 2020-05-09 17:03:53 cd to /root/mariadb_backup/ [00] 2020-05-09 17:03:53 This target seems to be not prepared yet. [00] 2020-05-09 17:03:53 mariabackup: using the following InnoDB configuration for recovery: [00] 2020-05-09 17:03:53 innodb_data_home_dir = . [00] 2020-05-09 17:03:53 innodb_data_file_path = ibdata1:12M:autoextend [00] 2020-05-09 17:03:53 innodb_log_group_home_dir = . [00] 2020-05-09 17:03:53 InnoDB: Using Linux native AIO [00] 2020-05-09 17:03:53 Starting InnoDB instance for recovery. [00] 2020-05-09 17:03:53 mariabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter) 2020-05-09 17:03:53 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2020-05-09 17:03:53 0 [Note] InnoDB: Uses event mutexes 2020-05-09 17:03:53 0 [Note] InnoDB: Compressed tables use zlib 1.2.11 2020-05-09 17:03:53 0 [Note] InnoDB: Number of pools: 1 2020-05-09 17:03:53 0 [Note] InnoDB: Using SSE2 crc32 instructions 2020-05-09 17:03:53 0 [Note] InnoDB: Initializing buffer pool, total size = 100M, instances = 1, chunk size = 100M 2020-05-09 17:03:53 0 [Note] InnoDB: Completed initialization of buffer pool 2020-05-09 17:03:53 0 [Note] InnoDB: page_cleaner coordinator priority: -20 2020-05-09 17:03:53 0 [Note] InnoDB: Starting crash recovery from checkpoint LSN=1631383 [00] 2020-05-09 17:03:54 Last binlog file , position 0 [00] 2020-05-09 17:03:54 completed OK! # リストア実行 root@node01:~# mariabackup --copy-back --target-dir /root/mariadb_backup mariabackup based on MariaDB server 10.3.22-MariaDB debian-linux-gnu (x86_64) [01] 2020-05-09 17:04:31 Copying ibdata1 to /var/lib/mysql/ibdata1 [01] 2020-05-09 17:04:31 ...done [01] 2020-05-09 17:04:31 Copying ./performance_schema/db.opt to /var/lib/mysql/performance_schema/db.opt [01] 2020-05-09 17:04:31 ...done [01] 2020-05-09 17:04:31 Copying ./mysql/plugin.MYI to /var/lib/mysql/mysql/plugin.MYI [01] 2020-05-09 17:04:31 ...done ..... ..... [01] 2020-05-09 17:04:31 ...done [01] 2020-05-09 17:04:31 Copying ./xtrabackup_info to /var/lib/mysql/xtrabackup_info [01] 2020-05-09 17:04:31 ...done [01] 2020-05-09 17:04:31 Copying ./aria_log.00000001 to /var/lib/mysql/aria_log.00000001 [01] 2020-05-09 17:04:31 ...done [00] 2020-05-09 17:04:31 completed OK!root@node01:~# chown -R mysql. /var/lib/mysql root@node01:~# systemctl start mariadb |
Sponsored Link |
|