[3] MariaDB – Backup
26 stycznia 2022Możliwe jest wykonywanie kopii zapasowych oraz ich odtworzenie za pomocą [mariabackup].
[1] Domyślnie [mariabackup] jest instalowana jako pakiety zależne do instalacji serwera MariaDB. Jednak jeśli nie została zainstalowana zainstaluj ją najpierw.
[root@vlsr01 ~]# dnf -y install mariadb-backup
[2] Uruchom backup. W tym przykładzie kopia będzie wykonana do katalogu [/home/maria_backup].
[root@vlsr01 ~]# mkdir /home/mariadb_backup [root@vlsr01 ~]# mariabackup --backup --target-dir /home/mariadb_backup -u root [00] 2022-01-26 18:25:15 Connecting to MySQL server host: localhost, user: root, password: not set, port: not set, socket: not set [00] 2022-01-26 18:25:15 Using server version 10.5.9-MariaDB mariabackup based on MariaDB server 10.5.9-MariaDB Linux (x86_64) [00] 2022-01-26 18:25:17 Writing xtrabackup_info [00] 2022-01-26 18:25:17 ...done [00] 2022-01-26 18:25:17 Redo log (from LSN 951569 to 951581) was copied. [00] 2022-01-26 18:25:17 completed OK! [root@vlsr01 ~]# ll /home/mariadb_backup/ razem 12352 -rw-r-----. 1 root root 32768 01-26 18:25 aria_log.00000001 -rw-r-----. 1 root root 52 01-26 18:25 aria_log_control -rw-r-----. 1 root root 297 01-26 18:25 backup-my.cnf -rw-r-----. 1 root root 2193 01-26 18:25 ib_buffer_pool -rw-r-----. 1 root root 12582912 01-26 18:25 ibdata1 -rw-r-----. 1 root root 2560 01-26 18:25 ib_logfile0 drwx------. 2 root root 4096 01-26 18:25 mysql drwx------. 2 root root 20 01-26 18:25 performance_schema drwx------. 2 root root 182 01-26 18:25 SampleApp_development drwx------. 2 root root 20 01-26 18:25 SampleApp_test drwx------. 2 root root 4096 01-26 18:25 wordpress -rw-r-----. 1 root root 75 01-26 18:25 xtrabackup_checkpoints -rw-r-----. 1 root root 430 01-26 18:25 xtrabackup_info #skompresuj wszystkie pliki do jednego archiwum [root@vlsr01 home]# tar -czvf mariadb_backup.tar.gz mariadb_backup
[3] Aby przywrócić dane z kopii zapasowej na innym hoście, wykonaj następujące czynności. Przed przywróceniem przenieś dane kopii zapasowej na host docelowy za pomocą [rsync] lub [scp] lub w jakikolwiek inny sposób.
#zatrzymaj MariaDB i usuń wszystkie dane [root@vlsr02 ~]# systemctl stop mariadb [root@vlsr02 ~]# rm -rf /var/lib/mysql/* #przetransportowany backup [root@vlsr02 ~]# ll mariadb_backup.tar.gz -rw-r--r--. 1 root root 514803 01-26 20:03 mariadb_backup.tar.gz [root@vlsr02 ~]# tar zxvf mariadb_backup.tar.gz #uruchom przygotowanie do odtworzenia danych: OK gdy pokaże się [completed OK] [root@vlsr02 ~]# mariabackup --prepare --target-dir /root/mariadb_backup mariabackup based on MariaDB server 10.5.9-MariaDB Linux (x86_64) [00] 2022-01-26 20:10:24 cd to /root/mariadb_backup/ [00] 2022-01-26 20:10:24 open files limit requested 0, set to 1024 [00] 2022-01-26 20:10:24 This target seems to be not prepared yet. [00] 2022-01-26 20:10:24 mariabackup: using the following InnoDB configuration for recovery: [00] 2022-01-26 20:10:24 innodb_data_home_dir = . [00] 2022-01-26 20:10:24 innodb_data_file_path = ibdata1:12M:autoextend [00] 2022-01-26 20:10:24 innodb_log_group_home_dir = . [00] 2022-01-26 20:10:24 InnoDB: Using Linux native AIO [00] 2022-01-26 20:10:24 Starting InnoDB instance for recovery. [00] 2022-01-26 20:10:24 mariabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter) 2022-01-26 20:10:24 0 [Note] InnoDB: Uses event mutexes 2022-01-26 20:10:24 0 [Note] InnoDB: Compressed tables use zlib 1.2.11 2022-01-26 20:10:24 0 [Note] InnoDB: Number of pools: 1 2022-01-26 20:10:24 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions 2022-01-26 20:10:24 0 [Note] InnoDB: Using Linux native AIO 2022-01-26 20:10:24 0 [Note] InnoDB: Initializing buffer pool, total size = 104857600, chunk size = 104857600 2022-01-26 20:10:24 0 [Note] InnoDB: Completed initialization of buffer pool 2022-01-26 20:10:24 0 [Note] InnoDB: Starting crash recovery from checkpoint LSN=951569,951569 [00] 2022-01-26 20:10:24 Last binlog file , position 0 [00] 2022-01-26 20:10:24 completed OK! #uruchom odtworzenie [root@vlsr02 ~]# mariabackup --copy-back --target-dir /root/mariadb_backup mariabackup based on MariaDB server 10.5.9-MariaDB Linux (x86_64) [01] 2022-01-26 20:11:23 Copying ibdata1 to /var/lib/mysql/ibdata1 . . . . . [01] 2022-01-26 20:11:24 ...done [00] 2022-01-26 20:11:24 completed OK! [root@vlsr02 ~]# chown -R mysql. /var/lib/mysql [root@vlsr02 ~]# systemctl restart mariadb [root@vlsr02 ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 10.5.9-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> show databases; +-----------------------+ | Database | +-----------------------+ | SampleApp_development | | SampleApp_test | | information_schema | | mysql | | performance_schema | | wordpress | +-----------------------+ 6 rows in set (0.000 sec)