> 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/vi/bao-tri/s3-migration.md).

# Di chuyển S3

## Di chuyển sang S3

{% hint style="info" %}
Những hướng dẫn này dành cho v5.x trở lên. Nếu bạn đang theo dõi 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 nghe ý kiến từ bạn!** Nếu bạn muốn chia sẻ với chúng tôi về số lượng tệp bạn đã di chuyển, tổng dung lượng của chúng, và thời gian quá trình di chuyển mất bao lâu, hãy gửi email tới [`support@overleaf.com`](mailto:support@overleaf.com) .
{% endhint %}

Hướng dẫn này sẽ đưa bạn qua quá trình di chuyển từ lưu trữ trên đĩa sang một kho lưu trữ đối tượng tương thích 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 S3 để kết nối tớ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 sự
* 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 bạn không có đủ dung lượng đĩa trống trên máy chủ hiện tại, 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 đảm bảo rằng tất 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 vừa được tải lên.

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.

#### 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 các tệp theo bố cục thư mục mới.

Chúng ta có thể tận 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 các tệp lên

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

**aws cli**

{% hint style="info" %}

* Ở đây bạn nên thay thế `overleaf-user-files`, `overleaf-template-files`, `overleaf-project-blobs` và `overleaf-chunks` bằng tên các bucket S3 của bạn.
* Cũng hãy thay thế `/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 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 đang dùng bí danh máy chủ "s3", có thể bạn đã 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) phần trong [S3](https://docs.overleaf.com/on-premises/configuration/overleaf-toolkit/s3) hướng dẫn thiết lập.

Đối với 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ữ nguyên [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) tại chỗ.
{% endhint %}

Bây giờ bạn có thể khởi động phiên bản và xác thực quá trình 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

### Quay lui

Bạn có thể quay lui quá trình di chuyển một cách an toàn 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 biến đổi ngược`
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 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 loại bỏ thư mục cấp cao nhất. Phép biến đổi thứ hai thay đổi bố cục thư mục thành dạng phẳng. Các ký tự đại diện đảm bảo 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://ayakaleaf-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.
