> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Di chuyển sang S3

## Di chuyển sang S3

<Info>
  Các hướng dẫn này dành cho v5.x trở về sau. Nếu bạn làm 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à tiền tố `SHARELATEX_` thay vì `OVERLEAF_` cho các biến môi trường. Đối với v6 trở về sau, hãy bỏ qua các lệnh `user_files` cũ (legacy).
</Info>

<Check>
  <strong>Chúng tôi rất muốn nghe ý kiến từ bạn!</strong> 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 bao lâu, hãy gửi email đến [`ayaka-notes@outlook.com`](mailto:support@overleaf.com) .
</Check>

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 một object storage tương thích S3. Hướng dẫn có tham chiếu đến các phần của tài liệu giới thiệu về [Thiết lập S3](/vi/on-premises/configuration/overleaf-toolkit/s3).

### Yêu cầu

* Một object storage tương thích S3 để kết nối, xem [#s3-setup](/vi/on-premises/configuration/overleaf-toolkit/s3#s3-setup "mention") để biết các lựa chọn
* Dung lượng đĩa trống để di chuyển dữ liệu hiện có, xấp xỉ bằng dung lượng 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
* Một bản sao lưu đầy đủ, bao gồm cả cấu hình, để có thể khôi phục khi cần

### Ước tính dung lượng đĩa cần thiết cho việc di chuyển

Chúng ta có thể dùng `du` để tính dung lượng đĩa hiện đang sử dụng:

```shell theme={null}
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 trống, hãy thử gắn thêm một ổ đĩa khác vào máy chủ.

<Info>
  Các thư mục history đã có sẵn cấu trúc đúng. Bạn có thể tải lên trực tiếp từ thư mục nguồn được bind-mount mà không cần thêm dung lượng đĩa.
</Info>

### 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ả các tệp người dùng/mẫu đều được di chuyển. Tốt nhất là tắt phiên bản để tránh bỏ sót các tệp mới đượ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 để biết quy trình tắt.

#### Bước 1: viết lại cấu trúc thư mục

Chúng ta cần viết lại cấu trúc thư mục của các tệp dự án để tải chúng lên S3. Cấu trúc thư mục cho lưu trữ cục bộ trong filestore là `<project-id>_<file-id>` và cấu trú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 cấu trúc thư mục mới. Thay `/srv/overleaf-bind-mount` bằng thư mục trên host được mount tại `/var/lib/overleaf`. Chạy các lệnh sao chép trên host với quyền đọc và ghi các thư mục này; container vẫn ở trạng thái dừng.

Chúng ta có thể dùng `tar` để viết lại cấu trúc:

```shell theme={null}
mkdir -p /srv/overleaf-s3-migration/user_files \
         /srv/overleaf-s3-migration/template_files
tar --create --directory /srv/overleaf-bind-mount/data/user_files . \
| tar --extract --directory /srv/overleaf-s3-migration/user_files \
  --transform=sx_x/x
tar --create --directory /srv/overleaf-bind-mount/data/template_files . \
| tar --extract --directory /srv/overleaf-s3-migration/template_files \
  --transform=sx_x/xg
```

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

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

**aws cli**

<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 bind-mount `/var/lib/overleaf`. Theo mặc định, đường dẫn này là `~/overleaf_data` trong bản triển khai docker-compose.yml và `<toolkit-checkout>/data/overleaf` khi sử dụng Toolkit.
</Info>

```shell wrap theme={null}
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
```

**minio mc**

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

```shell wrap theme={null}
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
```

#### Bước 3: khởi động phiên bản trỏ đến 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 phần [Tổng quan về các biến](/vi/on-premises/configuration/overleaf-toolkit/s3#overview-of-variables) trong hướng dẫn thiết lập [S3](https://docs.overleaf.com/on-premises/configuration/overleaf-toolkit/s3).

Hãy giữ lại bind-mount của thư mục dữ liệu: thư mục này cũng có thể chứa các khóa mã hóa Zotero hoặc Mendeley không được di chuyển sang S3.

<Check>
  Vui lòng giữ nguyên [bind-mount của ổ đĩa tạm (scratch disk) cho các tệp tạm thời](/vi/on-premises/support/troubleshooting#running-overleaf-with-an-nfs-filesystem).
</Check>

Bây giờ bạn có thể khởi động phiên bản và kiểm tra 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 PDF có hình ảnh
* có thể tải lên tệp mới

### Hoàn tác (rollback)

Bạn có thể hoàn tác việc di chuyển một cách an toàn bằng cách thực hiện ngược lại các bước:

1. Tắt phiên bản
2. Sao chép ngược các tệp bằng cách đảo 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 `transform` ngược
4. Khởi động lại phiên bản với cấu hình cũ

```shell wrap theme={null}
# When using 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

# When using 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
```

```shell theme={null}
# Write files into local Server CE/Server Pro
tar --create --directory /srv/overleaf-s3-migration/user_files . \
| tar \
      --extract \
      --keep-old-files \
      --directory /srv/overleaf-bind-mount/data/user_files \
      --transform=sx./xx --transform=sx/x_x \
      --wildcards '*/*/*'

tar --create --directory /srv/overleaf-s3-migration/template_files . \
| tar \
      --extract \
      --keep-old-files \
      --directory /srv/overleaf-bind-mount/data/template_files \
      --transform=sx./xx --transform=sx/x_xg \
      --wildcards '*/*/*/*/pdf-converted-cache/*' \
      --wildcards '*/*/*/*/pdf' \
      --wildcards '*/*/*/*/zip'
```

<Info>
  Transform đầu tiên loại bỏ thư mục cấp cao nhất. Transform thứ hai chuyển cấu trúc thư mục sang dạng phẳng. Các wildcard đảm bảo rằng chỉ các tệp được giải nén, không bao gồm các thư mục cha (thư mục dự án) của chúng.
</Info>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.