- 投稿日:2022-02-25T17:13:19+09:00
[OCI]Azure Blob Storage上にあるMySQLのバックアップファイルを直接MySQL DBシステムにリストアしてみた
はじめに こちらの記事では、goofysを使用してAWS S3のバケットをファイルシステムとしてマウントし、S3バケット内にあるバックアップを直接OCIのMySQL DBシステムにリストアしました。 今回は、Microsoftから提供されているblobfuseというAzure Blob Storage用の仮想ファイルシステムドライバーを使用して、Azure Blob Storageのコンテナ内にあるバックアップファイルを直接OCIのMySQL DBシステムにリストアしてみました。 1. blobfuseのインストール Microsoftパッケージリポジトリを構成します。 [opc@compute1 ~]$ sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm Retrieving https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm warning: /var/tmp/rpm-tmp.TtGT9F: Header V4 RSA/SHA256 Signature, key ID be1229cf: NOKEY Preparing... ################################# [100%] Updating / installing... 1:packages-microsoft-prod-1.0-1.el7################################# [100%] [opc@compute1 ~]$ yumコマンドでblobfuse をインストールします。 [opc@compute1 ~]$ sudo yum install -y blobfuse Loaded plugins: langpacks, ulninfo <略> Resolving Dependencies --> Running transaction check ---> Package blobfuse.x86_64 0:1.3.6-1.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved =================================================================================================================== Package Arch Version Repository Size =================================================================================================================== Installing: blobfuse x86_64 1.3.6-1.el7 packages-microsoft-com-prod 3.5 M Transaction Summary =================================================================================================================== Install 1 Package Total download size: 3.5 M Installed size: 15 M Downloading packages: warning: /var/cache/yum/x86_64/7Server/packages-microsoft-com-prod/packages/blobfuse-1.3.6-RHEL-7.5-x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID be1229cf: NOKEY Public key for blobfuse-1.3.6-RHEL-7.5-x86_64.rpm is not installed blobfuse-1.3.6-RHEL-7.5-x86_64.rpm | 3.5 MB 00:00:01 Retrieving key from https://packages.microsoft.com/keys/microsoft.asc Importing GPG key 0xBE1229CF: Userid : "Microsoft (Release signing) <gpgsecurity@microsoft.com>" Fingerprint: bc52 8686 b50d 79e3 39d3 721c eb3e 94ad be12 29cf From : https://packages.microsoft.com/keys/microsoft.asc Running transaction check Running transaction test Transaction test succeeded Running transaction Warning: RPMDB altered outside of yum. Installing : blobfuse-1.3.6-1.el7.x86_64 1/1 Verifying : blobfuse-1.3.6-1.el7.x86_64 1/1 Installed: blobfuse.x86_64 0:1.3.6-1.el7 Complete! [opc@compute1 ~]$ 2. blobfuse利用のための準備 バッファのための一時パスのディレクトリを作成します。 [opc@compute1 ~]$ sudo mkdir /mnt/resource/blobfusetmp -p マウントポイントを作成します。 [opc@compute1 ~]$ sudo mkdir /mnt_azureblob -p ストレージ アカウントの資格情報ファイルを作成します。 Azureコンソールのストレージアカウントのアクセスキーのページで、ストレージアカウント名とキーを確認します。 今回は、hogehoge1というストレージアカウントのazureblobというコンテナをマウントします。 [opc@compute1 ~]$ sudo vi /root/fuse_connection.cfg txt /root/fuse_connection.cfg accountName hogehoge1 accountKey ストレージアカウントのキー containerName azureblob 他のユーザーが読み取れないように資格情報ファイルのパーミッションを変更します。 [opc@compute1 ~]$ sudo chmod 600 /root/fuse_connection.cfg 3. blobfuseによるコンテナのマウント blobfuseコマンドでコンテナazureblobをマウントポイント/mnt_azureblobにマウントします。 [opc@compute1 ~]$ sudo blobfuse /mnt_azureblob --tmp-path=/mnt/resource/blobfusetmp --config-file=/root/fuse_connection.cfg -o attr_timeout=240 -o entry_timeout=240 -o negative_timeout=120 -o allow_other マウントできたようです。 /mnt_azureblob内にファイルを作成してみます。 [opc@compute1 ~]$ touch /mnt_azureblob/test.txt Azureのコンソールから確認してみます。 コンテナazureblob内にtest.txtが作成されていることが確認できました。 4. MySQLの準備 mysqlコマンドでadminユーザとしてMySQL DBシステムに接続します。 [opc@compute1 ~]$ mysql -u admin -p -h mysqlds1.subnet1.vcn1.oraclevcn.com Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 8.0.28-u1-cloud MySQL Enterprise - Cloud Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> リストア先のデータベース"employees"を作成します。 mysql> CREATE DATABASE employees;yees; Query OK, 1 row affected (0.01 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | employees | | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec) mysql> mysqlを終了します。 mysql> exit Bye [opc@compute1 ~]$ 5. バックアップファイルの準備 mysqldumpで取得したバックアップファイル"employees.dmp"をAzure Blobのコンテナにアップロードします。 こちらのバックアップファイルは、こちらで公開されているサンプルデータを一度MySQLに取り込み、mysqldumpでデータベースのバックアップとして取得したものです。 Azure Blob Storageコンテナのマウントポイントの内容を確認します。 [opc@compute1 ~]$ ls -l /mnt_azureblob/ total 164430 -rw-r--r--. 1 root root 168375940 Feb 24 05:32 employees.dmp -rw-r--r--. 1 root root 0 Feb 24 01:18 test.txt [opc@compute1 ~]$ employees.dmpがあることが確認できました。 6. Azure Blobコンテナにあるバックアップファイルのリストア Azure Blobコンテナのマウントポイント/mnt_azureblobにあるバックアップファイルemployees.dmpをmysqlコマンドでMySQL DBシステムにリストアします。 opc@compute1 ~]$ time mysql -u admin -p -h mysqlds1.subnet1.vcn1.oraclevcn.com -t employees < /mnt_azureblob/employees.dmp Enter password: real 1m26.789s user 0m1.999s sys 0m0.147s [opc@compute1 ~]$ mysqlコマンドでadminユーザとしてMySQL DBシステムに接続して、バックアップファイルが正しくリストアされているか確認します。 [opc@compute1 ~]$ mysql -u admin -p -h mysqlds1.subnet1.vcn1.oraclevcn.com Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 18 Server version: 8.0.28-u1-cloud MySQL Enterprise - Cloud Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> データベースをemployeesに切り替えます。 mysql> use employees; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> データベースemployees内のテーブルを確認します。 mysql> show tables; +----------------------+ | Tables_in_employees | +----------------------+ | current_dept_emp | | departments | | dept_emp | | dept_emp_latest_date | | dept_manager | | employees | | salaries | | titles | +----------------------+ 8 rows in set (0.00 sec) mysql> テーブル内のデータを確認します。 mysql> SELECT COUNT(*) FROM employees; +----------+ | COUNT(*) | +----------+ | 300024 | +----------+ 1 row in set (0.02 sec) mysql> SELECT COUNT(*) FROM departments; +----------+ | COUNT(*) | +----------+ | 9 | +----------+ 1 row in set (0.01 sec) mysql> mysqlを終了します。 mysql> exit Bye [opc@compute1 ~]$ blobfuseを使用してAzure Blob Storageコンテナをファイルシステムにマウントし、コンテナ内のバックアップファイルを直接MySQL DBシステムにリストアすることができました。 参考情報 blobfuse を使用して Blob Storage をファイル システムとしてマウントする方法 [OCI]AWS S3上にあるMySQLのバックアップファイルを直接MySQL DBシステムにリストアしてみた