MariaDB 10.11 : バックアップ2023/07/05 |
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 ..... ..... [01] 2023-07-04 19:06:33 Copying /var/lib/mysql//aria_log.00000001 to /home/mariadb_backup/aria_log.00000001 [01] 2023-07-04 19:06:33 ...done [00] 2023-07-04 19:06:33 Waiting for log copy thread to read lsn 49898 [00] 2023-07-04 19:06:33 Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS... [00] 2023-07-04 19:06:33 mariabackup: The latest check point (for incremental): '49882' mariabackup: Stopping log copying thread [00] 2023-07-04 19:06:33 Executing BACKUP STAGE END [00] 2023-07-04 19:06:33 All tables unlocked [00] 2023-07-04 19:06:33 Backup created in directory '/home/mariadb_backup/' [00] 2023-07-04 19:06:33 Writing backup-my.cnf [00] 2023-07-04 19:06:33 ...done [00] 2023-07-04 19:06:33 Writing xtrabackup_info [00] 2023-07-04 19:06:33 ...done [00] 2023-07-04 19:06:33 Redo log (from LSN 49882 to 49898) was copied. [00] 2023-07-04 19:06:33 completed OK!root@www:~# ll /home/mariadb_backup total 12752 -rw-r----- 1 root root 417792 Jul 4 19:06 aria_log.00000001 -rw-r----- 1 root root 52 Jul 4 19:06 aria_log_control -rw-r----- 1 root root 475 Jul 4 19:06 backup-my.cnf -rw-r----- 1 root root 12582912 Jul 4 19:06 ibdata1 -rw-r----- 1 root root 12304 Jul 4 19:06 ib_logfile0 drwx------ 2 root root 4096 Jul 4 19:06 mysql drwx------ 2 root root 4096 Jul 4 19:06 performance_schema drwx------ 2 root root 12288 Jul 4 19:06 sys drwx------ 2 root root 4096 Jul 4 19:06 test_database -rw-r----- 1 root root 73 Jul 4 19:06 xtrabackup_checkpoints -rw-r----- 1 root root 434 Jul 4 19:06 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 debian debian 704177 Jul 4 19:07 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.11.3-MariaDB debian-linux-gnu (x86_64) [00] 2023-07-04 19:15:31 cd to /root/mariadb_backup/ [00] 2023-07-04 19:15:31 open files limit requested 0, set to 1024 [00] 2023-07-04 19:15:31 Loading plugins from provider_bzip2=provider_bzip2;provider_lz4=provider_lz4;provider_lzma=provider_lzma;provider_lzo=provider_lzo;provider_snappy=provider_snappy [00] 2023-07-04 19:15:31 Loading plugins [00] 2023-07-04 19:15:31 Plugin parameter : '--plugin_load=provider_bzip2=provider_bzip2;provider_lz4=provider_lz4;provider_lzma=provider_lzma;provider_lzo=provider_lzo;provider_snappy=provider_snappy' [00] 2023-07-04 19:15:31 Plugin parameter : '--prepare' [00] 2023-07-04 19:15:31 Plugin parameter : '--target-dir' [00] 2023-07-04 19:15:31 Plugin parameter : '/root/mariadb_backup' [00] 2023-07-04 19:15:31 This target seems to be not prepared yet. [00] 2023-07-04 19:15:31 mariabackup: using the following InnoDB configuration for recovery: [00] 2023-07-04 19:15:31 innodb_data_home_dir = . [00] 2023-07-04 19:15:31 innodb_data_file_path = ibdata1:12M:autoextend [00] 2023-07-04 19:15:31 innodb_log_group_home_dir = . [00] 2023-07-04 19:15:31 InnoDB: Using liburing [00] 2023-07-04 19:15:31 Starting InnoDB instance for recovery. [00] 2023-07-04 19:15:31 mariabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter) 2023-07-04 19:15:31 0 [Note] InnoDB: Compressed tables use zlib 1.2.13 2023-07-04 19:15:31 0 [Note] InnoDB: Number of transaction pools: 1 2023-07-04 19:15:31 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions 2023-07-04 19:15:31 0 [Note] InnoDB: Using liburing 2023-07-04 19:15:31 0 [Note] InnoDB: Initializing buffer pool, total size = 100.000MiB, chunk size = 100.000MiB 2023-07-04 19:15:31 0 [Note] InnoDB: Completed initialization of buffer pool 2023-07-04 19:15:31 0 [Note] InnoDB: Buffered log writes (block size=512 bytes) [00] 2023-07-04 19:15:31 Last binlog file , position 0 [00] 2023-07-04 19:15:31 completed OK! # リストア実行 root@node01:~# mariabackup --copy-back --target-dir /root/mariadb_backup ..... ..... [01] 2023-07-04 19:16:04 Copying ./sys/x@0024ps_schema_table_statistics_io.frm to /var/lib/mysql/sys/x@0024ps_schema_table_statistics_io.frm [01] 2023-07-04 19:16:04 ...done [01] 2023-07-04 19:16:04 Copying ./sys/sys_config.MAI to /var/lib/mysql/sys/sys_config.MAI [01] 2023-07-04 19:16:04 ...done [01] 2023-07-04 19:16:04 Copying ./sys/x@0024user_summary_by_file_io.frm to /var/lib/mysql/sys/x@0024user_summary_by_file_io.frm [01] 2023-07-04 19:16:04 ...done [01] 2023-07-04 19:16:04 Copying ./sys/x@0024ps_digest_avg_latency_distribution.frm to /var/lib/mysql/sys/x@0024ps_digest_avg_latency_distribution.frm [01] 2023-07-04 19:16:04 ...done [00] 2023-07-04 19:16:04 completed OK!root@node01:~# chown -R mysql:mysql /var/lib/mysql root@node01:~# systemctl start mariadb |
Sponsored Link |
|