Nextcloudのバージョンを29.05に上げたところ、以下のメッセージが出てきました。

One or more mimetype migrations are available. Occasionally new mimetypes are added to better handle certain file types. Migrating the mimetypes take a long time on larger instances so this is not done automatically during upgrades. Use the command occ maintenance:repair --include-expensive to perform the migrations.

「1つ以上のMIMEタイプの移行が利用可能です。特定のファイルタイプをより適切に処理するために、新しいMIMEタイプが追加されることがあります。大規模なインスタンスではMIMEタイプの移行に時間がかかるため、アップグレード時に自動的には行われません。移行を実行するには、occ maintenance:repair --include-expensiveコマンドを使用してください。」

とあるので、この警告に対処していきます。

自環境

  • Ubuntu 20.04
  • PHP 8.1
  • Apache 2.4
    • (www-dataとして実行)
  • Nextcloudを29.04→29.05にアップデート直後

1回目の手順:occ実行 → 失敗

Nextcloudがインストールされているサーバにログインしての作業です。

ディレクトリに移動します。

cd /var/www/html/nextcloud && pwd

自分の環境に合わせます。

occコマンドを実行します。 → 失敗

sudo -u www-data php occ maintenance:repair --include-expensive

Nextcloudの実行ユーザー(www-data)を付与した上でoccを実行します。

ですが、以下のエラーが出てきて問題は解決しませんでした。

WARNING: Failed to create filecache trigger (compatibility mode will be used): An exception occurred while executing a query: SQLSTATE[HY000]: General error: 1419 You do not have the SUPER privilege and binary logging is enabled (you might want to use the less safe log_bin_trust_function_creators variable)
- exiftool binary is configured: /var/www/html/nextcloud/apps/memories/bin-ext/exiftool-amd64-glibc
- go-vod binary is configured: /var/www/html/nextcloud/apps/memories/bin-ext/go-vod-amd64
- WARNING: ffmpeg binary could not be configured

調査の結果、バグと判明

そこで、このエラーメッセージで探したところ、そのものズバリのバグが報告されていました。

[Bug]: Warning: One or more mimetype migrations are available #47359

どうやら、RepairMimeTypes.phpファイルがver29.0.5を正しく読んでいないようです。

そこで、改めての対処です。

2回目の手順:パッチ作成と適用 → ○

パッチファイルを作成します。

  • 任意の作業ディレクトリに移動
cd /hoge && pwd

自分の環境に合わせます。

  • 修正前のファイルをバックアップ
sudo cp -pi /var/www/html/nextcloud/lib/private/Repair/RepairMimeTypes.php /hoge/RepairMimeTypes.php.$(date +%Y%m%d)

Nextcloudのルートディレクトリ (自分の環境に合わせます)から作業ディレクトリにコピーします。

  • 修正されたファイルを取得
wget https://raw.githubusercontent.com/nextcloud/server/stable29/lib/private/Repair/RepairMimeTypes.php -O RepairMimeTypes.php.fixed
  • パッチを作成
sudo -u www-data diff -u /var/www/html/nextcloud/lib/private/Repair/RepairMimeTypes.php RepairMimeTypes.php.fixed > RepairMimeTypes.patch
  • 作成したファイルの確認
cat RepairMimeTypes.patch
--- /var/www/html/nextcloud/lib/private/Repair/RepairMimeTypes.php      2024-08-20 17:56:22.000000000 +0900
+++ RepairMimeTypes.php.fixed   2024-08-26 14:14:11.568462741 +0900
@@ -424,7 +424,7 @@
                        $out->info('Fixed ReStructured Text mime type');
                }

-               if (version_compare($mimeTypeVersion, '30.0.0.0', '<') && $this->introduceExcalidrawType()) {
+               if (version_compare($mimeTypeVersion, '29.0.5.0', '<') && $this->introduceExcalidrawType()) {
                        $out->info('Fixed Excalidraw mime type');
                }

差分(プラスマイナス)が2行のみを確認します。

パッチを適用します。

  • パッチ適用
sudo patch -d /var/www/html/nextcloud/lib/private/Repair  < /hoge/RepairMimeTypes.patch 

/hogeはパッチを作成したディレクトリをフルパスで指定します。

  • 差分確認
sudo -u diff -u /hoge/RepairMimeTypes.php.$(date +%Y%m%d) /var/www/html/nextcloud/lib/private/Repair

以下のような差分を確認します。

-               if (version_compare($mimeTypeVersion, '30.0.0.0', '<') && $this->introduceExcalidrawType()) {
+               if (version_compare($mimeTypeVersion, '29.0.5.0', '<') && $this->introduceExcalidrawType()) {
  • 権限確認
ls -l /var/www/html/nextcloud/lib/private/Repair/RepairMimeTypes.php

念のため、パッチを当てても所有者が変わっていない(www-data)ことを確認します。

改めてoccを実行し、Webサービス再起動の上で修正を確認します。

ディレクトリに移動します。

cd /var/www/html/nextcloud && pwd

自分の環境に合わせます。

occコマンドを実行します。 → 成功

sudo -u www-data php occ maintenance:repair --include-expensive

今度は通ります。

  • Webサービス(apahce)再起動
sudo systemctl restart apache2.service
  • 再起動後のステータス確認
systemctl status apache2.service

active(running)を確認します。

  • 事象の解消を確認
  1. 作業を行ったサーバで稼働するNextcloudに管理者権限でログインします。
  2. 管理者メニューで以下の通りWarningが解消されていることを確認します。