> For the complete documentation index, see [llms.txt](https://ayakaleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ayakaleaf-pro.ayaka.space/on-premises/ja/mentenansu/s3-migration.md).

# S3 への移行

## S3移行

{% hint style="info" %}
この手順は v5.x 以降向けです。以前のバージョンでこのガイドに従っている場合は、次を使用してください `sharelatex` の代わりに `Overleaf` パス名および `SHARELATEX_` の代わりにプレフィックス `OVERLEAF_` 環境変数には。
{% endhint %}

{% hint style="warning" %}
Server Pro のお客様: データを S3 に移行する前にサポートへご連絡ください。
{% endhint %}

{% hint style="success" %}
**ぜひご意見をお聞かせください！** 移行したファイル数、総容量、移行にかかった時間を共有していただける場合は、メールで [`support@overleaf.com`](mailto:support@overleaf.com) .
{% endhint %}

このガイドでは、オンディスクストレージから S3 互換のオブジェクトストレージへの移行手順を説明します。これは、導入ドキュメントの次のセクションを参照しています。 [S3 セットアップ](/on-premises/ja/she-ding/overleaf-toolkit/s3.md).

### 要件

* 接続先となる S3 互換オブジェクトストレージについては、次を参照してください [S3](/on-premises/ja/she-ding/overleaf-toolkit/s3.md#s3-setup) オプションについて
* 既存データを移行するための空きディスク容量。現在のディスク使用量のおよそ
* 実際の移行を行うためのメンテナンス時間帯
* 設定を含む完全バックアップ。そこから復元できるようにするため

### 移行に必要なディスク容量を見積もる

次を使えます `du` 現在のディスク使用量を計算するために:

```shell
docker exec sharelatex \\
  du --human-readable --max-depth=0 /var/lib/overleaf/data/user_files

docker exec sharelatex \\
  du --human-readable --max-depth=0 /var/lib/overleaf/data/template_files
```

現在のサーバーで十分なディスク容量がない場合は、別のディスクをサーバーに接続してみてください。

{% hint style="info" %}
history ディレクトリはすでに正しいレイアウトです。bind mount されたソースフォルダから直接アップロードでき、追加のディスク容量は不要です。
{% endhint %}

### 移行手順

#### 手順 0 インスタンスを停止する

すべての user/template ファイルが確実に移行されるようにする必要があります。新しくアップロードされたファイルの取りこぼしを防ぐため、インスタンスを停止するのが最善です。

シャットダウン手順については、一貫性のあるバックアップを作成するためのガイドをご覧ください。

#### 手順 1 ディレクトリレイアウトを書き換える

S3 にアップロードするために、プロジェクトファイルのディレクトリレイアウトを書き換える必要があります。filestore におけるローカルストレージのディレクトリレイアウトは `<project-id>_<file-id>` で、S3 でのディレクトリレイアウトは `<project-id>/<file-id>`.

以下では、 `/srv/overleaf-s3-migration` が、新しいディレクトリレイアウトでファイルを保存するために使用されます。

次を利用できます `tar` レイアウトを書き換えるために:

```shell
mkdir -p /srv/overleaf-s3-migration/user_files \\
         /srv/overleaf-s3-migration/template_files
docker exec sharelatex \\
  tar --create --directory /var/lib/overleaf/data/user_files . \\
| tar --extract --directory /srv/overleaf-s3-migration/user_files \\
  --transform=sx_x/x
docker exec sharelatex \\
  tar --create --directory /var/lib/overleaf/data/template_files . \\
| tar --extract --directory /srv/overleaf-s3-migration/template_files \\
  --transform=sx_x/xg
```

#### 手順 2 ファイルをアップロードする

お好みに応じて、minio mc の S3 クライアントまたは aws cli を使って、ファイルを S3 互換オブジェクトストレージにアップロードできます。

**aws cli**

{% hint style="info" %}

* ここでは `overleaf-user-files`, `overleaf-template-files`, `overleaf-project-blobs` および `overleaf-chunks` を、S3 バケット名に置き換えてください。
* また、次も置き換えてください `/srv/overleaf-bind-mount` を次のローカルパスに `/var/lib/overleaf` bind mount のローカルパスです。デフォルトでは、これは `~/overleaf_data` docker-compose.yml デプロイでは `<toolkit-checkout>/data/overleaf` Toolkit を使用する場合です。
  {% endhint %}

{% code overflow="wrap" %}

```shell
aws s3 sync /srv/overleaf-s3-migration/user_files s3://overleaf-user-files
aws s3 sync /srv/overleaf-s3-migration/template_files s3://overleaf-template-files

aws s3 sync /srv/overleaf-bind-mount/data/history/overleaf-project-blobs s3://overleaf-project-blobs
aws s3 sync /srv/overleaf-bind-mount/data/history/overleaf-chunks s3://overleaf-chunks
```

{% endcode %}

**minio mc**

ここではサーバーのエイリアスとして「s3」を使っていますが、別の名前を選んでいても構いません。

{% code overflow="wrap" %}

```shell
mc mirror /srv/overleaf-s3-migration/user_files s3/overleaf-user-files
mc mirror /srv/overleaf-s3-migration/template_files s3/overleaf-template-files

mc mirror /srv/overleaf-bind-mount/data/history/overleaf-project-blobs s3/overleaf-project-blobs
mc mirror /srv/overleaf-bind-mount/data/history/overleaf-chunks s3/overleaf-chunks
```

{% endcode %}

#### 手順 3 S3 を指すようにしてインスタンスを起動する

config に S3 関連の変数をすべて追加してください。詳細は [変数の概要](/on-premises/ja/she-ding/overleaf-toolkit/s3.md#overview-of-variables) の [S3](https://docs.overleaf.com/on-premises/configuration/overleaf-toolkit/s3) セットアップガイドのセクションを参照してください。

Docker Compose デプロイでは、volumes セクションから data ディレクトリの bind mount を削除することもできます。

{% hint style="success" %}
ただし、 [一時ファイル用の scratch ディスクの bind mount](/on-premises/ja/sapto/troubleshooting.md#running-overleaf-with-an-nfs-filesystem) はそのまま残してください。
{% endhint %}

これでインスタンスを起動し、移行を検証できます:

* エディタでバイナリファイルをプレビューできる
* 画像付きの PDF をコンパイルできる
* 新しいファイルをアップロードできる

### ロールバック

手順を逆に実行することで、移行を安全にロールバックできます:

1. インスタンスを停止する
2. ソース/宛先の順序を入れ替えてファイルをミラーリングし戻す
3. 逆の `変換`
4. 以前の設定でインスタンスを再起動する

{% code overflow="wrap" %}

```shell
# aws cli を使用する場合
aws s3 sync s3://overleaf-user-files /srv/overleaf-s3-migration/user_files
aws s3 sync s3://overleaf-template-files /srv/overleaf-s3-migration/template_files
aws s3 sync s3://overleaf-project-blobs /srv/overleaf-bind-mount/data/history/overleaf-project-blobs
aws s3 sync s3://overleaf-chunks /srv/overleaf-bind-mount/data/history/overleaf-chunks

# minio mc を使用する場合
mc mirror s3/overleaf-user-files /srv/overleaf-s3-migration/user_files
mc mirror s3/overleaf-template-files /srv/overleaf-s3-migration/template_files
mc mirror s3/overleaf-project-blobs /srv/overleaf-bind-mount/data/history/overleaf-project-blobs
mc mirror s3/overleaf-chunks /srv/overleaf-bind-mount/data/history/overleaf-chunks
```

{% endcode %}

```shell
# ローカルの Server CE/Server Pro にファイルを書き込む
tar --create --directory /srv/overleaf-s3-migration/user_files . \\
| docker exec --interactive sharelatex \\
    tar \\
      --extract \\
      --keep-old-files \\
      --directory /var/lib/overleaf/data/user_files \\
      --transform=sx./xx --transform=sx/x_x \\
      --wildcards '*/*/*'

tar --create --directory /srv/overleaf-s3-migration/template_files . \\
| docker exec --interactive sharelatex \\
    tar \\
      --extract \\
      --keep-old-files \\
      --directory /var/lib/overleaf/data/template_files \\
      --transform=sx./xx --transform=sx/x_xg \\
      --wildcards '*/*/*/*/pdf-converted-cache/*' \\
      --wildcards '*/*/*/*/pdf' \\
      --wildcards '*/*/*/*/zip'
```

{% hint style="info" %}
最初の変換は最上位フォルダを削除します。2つ目の変換はディレクトリレイアウトをフラットなものに変更します。ワイルドカードにより、親（プロジェクト）フォルダではなくファイルのみが展開されます。
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ayakaleaf-pro.ayaka.space/on-premises/ja/mentenansu/s3-migration.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
