# Đồng bộ dữ liệu từ sử dụng tool s3sync

s3sync là công cụ giúp upload file từ local (server, máy tính bàn) lên dịch vụ lưu trữ đám mấy theo chuẩn S3. Công cụ này giúp upload file, download sync từ bucket này sang bucket khác của nhiều dịch vụ lưu trữ đám mấy khác nhau theo chuẩn S3.

Xem thêm tại <https://github.com/larrabee/s3sync>

Bài viết này hướng dẫn cách thiết lập việc replicate data/migrate data từ local sang Bizfly Simple Storage, download file về server.

**1. Cài đặt s3sync**

Các phiên bản của s3sync có thể được tìm thấy ở đây : <https://github.com/larrabee/s3sync/releases>. S3sync hỗ trợ nhiều hệ điều hành như FreeBSD, Linux, OpenBSD, MacOS.

s3sync là tool chạy trực tiếp nên chỉ cần download về là có thể chạy được. Ví dụ download với server linux

```s
wget https://github.com/larrabee/s3sync/releases/download/2.30/s3sync_2.30_Linux_x86_64.tar.gz
tar -xvzf s3sync_2.30_Linux_x86_64.tar.gz 
chmod +x s3sync
```

**2. Lấy thông tin xác thực của dịch vụ X-OR Cloud S3 Storage**

Vào phần **Quản lý User** -> **Bảo mật** -> **Simple Storage Access Keys**

Thông tin cần lấy: **Access key** và **Secret key**

**3. Thực hiện các câu lệnh sync dữ liệu**

s3sync sẽ cần truyền tham số cho source và target, source là nơi chứa dữ liệu cần được sync và target là nơi sẽ được sync dữ liệu đến.

Các tham số cơ bản

```s
sk : access-key của source
ss : secret-key của source
te : endpoint của source

tk : access-key của target
ts : secret-key của target
te : endpoint của target

w : số lượng worker để thực hiện việc sync
sync-progress : show quá trình thực hiện sync
s3-acl : quyền của file khi upload , danh sách các quyền  private, public-read, public-read-write, authenticated-read, mặc định là private

disable-http2 : disable mode http2 của client
```

Upload dữ liệu từ local lên s3

```s
./s3sync --tk <access-key> --ts <secret-key> --te "https://s3.xorcloud.net" -w 64 fs://<source-local> s3://<s3-bucket-target>  --sync-progress --s3-acl public-read
```

Download dữ liệu từ Simple Storage về local

```s
./s3sync --sk <access-key> --ss <secret-key> --se "https://s3.xorcloud.net" -w 64 s3://<s3-bucket-target> fs://<source-local>   --sync-progress --disable-http2
```

Copy dữ liệu từ bucket này sang bucket khác

```s
./s3sync --sk <access-key-source> --ss <secret-key-source> --se "https://s3.xorcloud.net" --tk <access-key-target> --ts <secret-key-target> --te "https://s3.xorcloud.net" -w 64 s3://<s3-bucket-source> s3://<s3-bucket-target> --sync-progress --s3-acl public-read --disable-http2
```

sync dữ liệu từ amazone về Simple Storage

```s
./s3sync --sk <access-key-amazon> --ss <secret-key-amazon> --tk <access-key-xor-s3-storage> --ts <secret-key-xor-s3-storage> --te "https://s3.xorcloud.net" -w 64 s3://<s3-bucket-amazon> s3://<s3-bucket-bizfly-simple-storage> --sync-progress --s3-acl public-read --disable-http2
```

Một số tham số hữu ích trong quá trình sử dụng

```s
-d : mode debug để có thêm thông tin khi bị lỗi
--sync-log : show log của quá trình sync
--ratelimit-objects : limit số lượng object được thực sync trong 1 giây
--ratelimit-bandwidth : limit số lượng băng thông trong quá trình sync, các đơn vị hỗ trợ K, M, G tương ứng với KB, MB, và GB
Ngoài ra còn có các tham số khác có thể tham khảo ở link sau: https://github.com/larrabee/s3sync
```


---

# Agent Instructions: 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:

```
GET https://docs.x-or.cloud/san-pham/x-or-data/huong-dan/dong-bo-du-lieu-tu-su-dung-tool-s3sync.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
