> For the complete documentation index, see [llms.txt](https://overleaf-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://overleaf-pro.ayaka.space/on-premises/vi/bao-tri/s3-migration.md).

# Di chuyển sang S3

## Di chuyển sang S3

{% hint style="info" %}
Các hướng dẫn này dành cho v5.x trở lên. Nếu bạn đang theo hướng dẫn này cho một phiên bản cũ hơn, vui lòng dùng `sharelatex` thay vì `overleaf` trong tên đường dẫn và `SHARELATEX_` tiền tố thay vì `OVERLEAF_` cho các biến môi trường.
{% endhint %}

{% hint style="warning" %}
Khách hàng Server Pro: Vui lòng liên hệ bộ phận hỗ trợ trước khi bạn di chuyển dữ liệu của mình sang S3.
{% endhint %}

{% hint style="success" %}
**Chúng tôi rất muốn nhận phản hồi từ bạn!** Nếu bạn muốn chia sẻ với chúng tôi số lượng tệp bạn đã di chuyển, tổng dung lượng của chúng, và thời gian di chuyển đã mất, hãy gửi email tới [`support@overleaf.com`](mailto:support@overleaf.com) .
{% endhint %}

Hướng dẫn này sẽ dẫn bạn qua quá trình di chuyển từ lưu trữ trên đĩa sang kho lưu trữ đối tượng tương thích với S3. Nó tham chiếu đến các phần của tài liệu giới thiệu về [Thiết lập S3](/on-premises/vi/cau-hinh/overleaf-toolkit/s3.md).

### Yêu cầu

* Một kho lưu trữ đối tượng tương thích với S3 để kết nối, xem [S3](/on-premises/vi/cau-hinh/overleaf-toolkit/s3.md#s3-setup) để xem các tùy chọn
* Dung lượng đĩa trống để di chuyển dữ liệu hiện có, khoảng bằng kích thước hiện tại trên đĩa
* Một khoảng thời gian bảo trì để thực hiện việc di chuyển thực tế
* Một bản sao lưu đầy đủ, bao gồm cả cấu hình, để có thể khôi phục từ đó

### Ước tính dung lượng đĩa cần cho quá trình di chuyển

Chúng ta có thể dùng `du` để tính mức sử dụng đĩa hiện tại:

```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
```

Trong trường hợp máy chủ hiện tại không có đủ dung lượng đĩa, hãy thử gắn thêm một đĩa khác vào máy chủ.

{% hint style="info" %}
Các thư mục lịch sử đã có bố cục đúng. Bạn có thể tải lên trực tiếp từ thư mục nguồn được bind-mount, việc này không cần thêm dung lượng đĩa nào.
{% endhint %}

### Các bước di chuyển

#### Bước 0: tắt phiên bản

Chúng ta cần bảo đảm rằng tất cả các tệp người dùng/mẫu sẽ được di chuyển. Tốt nhất là tắt phiên bản để tránh bỏ sót các tệp được tải lên mới.

Vui lòng xem hướng dẫn của chúng tôi về việc thực hiện sao lưu nhất quán cho quy trình tắt máy.

#### Bước 1: viết lại bố cục thư mục

Chúng ta cần viết lại bố cục thư mục của các tệp dự án để tải chúng lên S3. Bố cục thư mục cho lưu trữ cục bộ trong filestore là `<project-id>_<file-id>` và bố cục thư mục trong S3 là `<project-id>/<file-id>`.

Trong phần sau, `/srv/overleaf-s3-migration` được dùng để lưu trữ các tệp theo bố cục thư mục mới.

Chúng ta có thể sử dụng `tar` để viết lại bố cục:

```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
```

#### Bước 2: tải lên các tệp

Tùy theo sở thích của bạn, bạn có thể dùng trình khách minio mc S3 hoặc aws cli để tải các tệp lên kho lưu trữ đối tượng tương thích với S3 của bạn.

**aws cli**

{% hint style="info" %}

* Tại đây bạn nên thay `overleaf-user-files`, `overleaf-template-files`, `overleaf-project-blobs` và `overleaf-chunks` bằng tên các bucket S3 của bạn.
* Đồng thời thay `/srv/overleaf-bind-mount` bằng đường dẫn cục bộ của `/var/lib/overleaf` bind-mount. Theo mặc định, đó là `~/overleaf_data` trong một triển khai docker-compose.yml và `<toolkit-checkout>/data/overleaf` khi sử dụng 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**

Ở đây chúng tôi dùng bí danh máy chủ "s3", bạn có thể đã chọn một tên khác.

{% 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 %}

#### Bước 3: khởi động phiên bản trỏ tới S3

Thêm tất cả các biến liên quan đến S3 vào cấu hình của bạn, như được mô tả chi tiết trong [Tổng quan về các biến](/on-premises/vi/cau-hinh/overleaf-toolkit/s3.md#overview-of-variables) mục trong [S3](https://docs.overleaf.com/on-premises/configuration/overleaf-toolkit/s3) hướng dẫn thiết lập.

Đối với các triển khai Docker Compose, bạn cũng có thể xóa bind-mount cho thư mục dữ liệu khỏi phần volumes.

{% hint style="success" %}
Vui lòng giữ [bind-mount của một đĩa tạm cho các tệp tạm thời](/on-premises/vi/ho-tro/troubleshooting.md#running-overleaf-with-an-nfs-filesystem) nguyên trạng.
{% endhint %}

Bây giờ bạn có thể khởi động phiên bản và xác minh việc di chuyển:

* có thể xem trước các tệp nhị phân trong trình soạn thảo
* có thể biên dịch một PDF có hình ảnh
* có thể tải lên các tệp mới

### Hoàn tác

Bạn có thể hoàn tác việc di chuyển một cách êm thấm bằng cách đảo ngược các bước:

1. Tắt phiên bản
2. Đồng bộ ngược các tệp bằng cách đảo ngược thứ tự nguồn/đích
3. Ghi các tệp mới trở lại thư mục cục bộ bằng một phép nghịch `biến đổi`
4. Khởi động lại phiên bản với cấu hình cũ

{% code overflow="wrap" %}

```shell
# Khi dùng 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

# Khi dùng 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
# Ghi các tệp vào Server CE/Server Pro cục bộ
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" %}
Phép biến đổi đầu tiên xóa thư mục cấp cao nhất. Phép biến đổi thứ hai chuyển bố cục thư mục thành dạng phẳng. Các ký tự đại diện bảo đảm rằng chỉ các tệp được giải nén, không phải các thư mục cha (dự án) của chúng.
{% 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://overleaf-pro.ayaka.space/on-premises/vi/bao-tri/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.
