LoginSignup
0
1

More than 1 year has passed since last update.

Drupal のバックアップ

Posted at

こちらの続きになります。

Backup and Migrate

を使って、バックアップを取ろうとしましたが、

Cannot connect to the database because the MySQLi extension is missing.

というエラーが発生しているので、対応します。

MySQLi

MySQLi エクステンションを有効にすれば良いのか?
そのためには、php.ini に、記述を追加する必要がありそうです。

では、php.ini はどこにあるのか。

drupal では、管理画面から、phpinfo の情報を確認することができるようになってます。

サイト/admin/reports/status/php

この中の、「Configuration File (php.ini) Path」の項目に、パスが書かれています。

Dockerコンテナのシェルに入って見てみます。

# ls /usr/local/etc/php
conf.d  php.ini-development  php.ini-production

むむ・・・php.ini がない。

# php --ini
Configuration File (php.ini) Path: /usr/local/etc/php
Loaded Configuration File:         (none)
Scan for additional .ini files in: /usr/local/etc/php/conf.d
Additional .ini files parsed:      /usr/local/etc/php/conf.d/docker-php-ext-gd.ini,
/usr/local/etc/php/conf.d/docker-php-ext-opcache.ini,
/usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini,
/usr/local/etc/php/conf.d/docker-php-ext-pdo_pgsql.ini,
/usr/local/etc/php/conf.d/docker-php-ext-sodium.ini,
/usr/local/etc/php/conf.d/docker-php-ext-zip.ini,
/usr/local/etc/php/conf.d/opcache-recommended.ini

単一 php.ini を読むのではなく、/usr/local/etc/php/conf.d フォルダの各ファイルを統合して読む。

その一つ、

# cat /usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini
extension=pdo_mysql.so

では、mysqli を有効化するファイルをも追加してみる。

# cp /usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini /usr/local/etc/php/conf.d/docker-php-ext-mysqli.ini

# sed -i -e "s|extension=pdo_mysql.so|extension=mysqli|" /usr/local/etc/php/conf.d/docker-php-ext-mysqli.ini

# cat /usr/local/etc/php/conf.d/docker-php-ext-mysqli.ini
/extension=mysqli

apache 再起動は、httpd ではなく、apache2

# service httpd restart
httpd: unrecognized service

# service apache2 restart
[....] Restarting Apache httpd web server: apache2Terminated

しかし、変わらない。
コンテナ再起動しても変わらない。

そもそも、このエクステンションがインストールされていない。

# php -i | grep extension_dir
extension_dir => /usr/local/lib/php/extensions/no-debug-non-zts-20190902 => /usr/local/lib/php/extensions/no-debug-non-zts-20190902
sqlite3.extension_dir => no value => no value

# ls /usr/local/lib/php/extensions/no-debug-non-zts-20190902
gd.so  opcache.so  pdo_mysql.so  pdo_pgsql.so  sodium.so  zip.so

インストールするには?Docker コンテナ内では、これが使える。

# docker-php-ext-install mysqli
・・・

# ls /usr/local/lib/php/extensions/no-debug-non-zts-20190902
gd.so  mysqli.so  opcache.so  pdo_mysql.so  pdo_pgsql.so  sodium.so  zip.so

入ったけど、まだ有効になっていない。

# service apache2 restart

来た!

image.png

バックアップファイルのダウンロードができました。

image.png

private

しかしサーバ内へのバックアップはできません。

image.png

The backup file could not be saved to 'private://backup_migrate/' because your private files system path has not been set.

上記 Backup and Migrate のページでは、

Bug fixes. Please upgrade to 5.0.0, the 8.x-4.x releases will not be supported any further.

と書かれているので、5.0.1 をインストールしました。
Documentation は
Backup and Migrate 7.x
Backup and Migrate 8.x
となっていますが、きっと 8.x を見れば良いのだろうと考えます。

その中の、Backup to Server のところを参考に、サーバを設定します。

Create a directory, writable by the server, but outside the Drupal installation and not accessible over the web.

Drupal インストールの外側ということなので、

# ls /opt
drupal
# mkdir /opt/drupal_private
# ls /opt           
drupal  drupal_private

In the Drupal settings file, add the absolute path to this directory for the file_private_path variable.

Drupal settings file は

cat /var/www/html/sites/default/settings.php

・・・
/**
 * Private file path:
 *
 * A local file system path where private files will be stored. This directory
 * must be absolute, outside of the Drupal installation directory and not
 * accessible over the web.
 *
 * Note: Caches need to be cleared when this value is changed to make the
 * private:// stream wrapper available to the system.
 *
 * See https://www.drupal.org/documentation/modules/file for more information
 * about securing private files.
 */
# $settings['file_private_path'] = '';

なので、

sed -i -e "s|# \$settings\['file_private_path'\] = '';|\$settings\['file_private_path'\] = '/opt/drupal_private/';|" /var/www/html/sites/default/settings.php

Navigate to Configuration > File system (or Administration > Configuration > Media > File system to confirm that the settings are correct.

上記は、URLとしては
サイト/admin/config/media/file-system

特にサービス再起動等せずに即時反映されました。

プライベートファイルシステムパス
/opt/drupal_private/
プライベートファイルを格納する、既存のローカルファイルシステムパス。Drupal から書き込み可能で、ウェブからアクセス不可能でなくてはなりません。settings.php で変更する必要があります。

Navigate to Configuration > Performance (or Administration > Configuration > Development > Performance) and click Clear all caches so the file streams are updated.

サイト/admin/config/development/performance
「すべてのキャッシュをクリアー」

image.png

Navigate to Configuration > Development > Backup and Migrate > Settings > Destinations. Click Edit to edit the Private files directory destination, or create a new destination. Enter the directory you want to use for backups, such as private://backup_migrate (if it is within the private file system), or the full path to the directory you want to use and save.

サイト/admin/config/development/backup_migrate/settings/destination

この時点で「private://backup_migrate」はセットされているので、このままでよいと思われたが、エラー。ただし、メッセージは変わった。

The backup file could not be saved to 'private://backup_migrate/' because the directory could not be created or cannot be written to. Please make sure your private files directory is writable by the web server.

フォルダも作って、権限も作る。

# mkdir /opt/drupal_private/backup_migrate
# chmod 777 /opt/drupal_private/backup_migrate
# ls -l /opt/drupal_private
total 0
drwxrwxrwx. 2 root root 6 Oct 17 14:37 backup_migrate

image.png

できた!

スケジューリング

サイト/admin/config/development/backup_migrate/schedule

初期状態
image.png

毎日実行、3世代保存に変更。有効化のチェックも忘れず。

image.png

image.png

環境設定 > cron から「cron を実行」してみる。
サイト/admin/config/system/cron

image.png

「保存済みバックアップ」で確認できる。

image.png

以上!

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1