Đồ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

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ụ Bizfly Simple 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 keySecret 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

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

./s3sync --tk <access-key> --ts <secret-key> --te "https://hn.ss.bfcplatform.vn" -w 64 fs://<source-local> s3://<s3-bucket-target>  --sync-progress --s3-acl public-read

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

./s3sync --sk <access-key> --ss <secret-key> --se "https://hn.ss.bfcplatform.vn" -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

./s3sync --sk <access-key-source> --ss <secret-key-source> --se "https://hn.ss.bfcplatform.vn" --tk <access-key-target> --ts <secret-key-target> --te "https://hn.ss.bfcplatform.vn" -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

./s3sync --sk <access-key-amazon> --ss <secret-key-amazon> --tk <access-key-bizfly-simple-storage> --ts <secret-key-bizfly-simple-storage> --te "https://hn.ss.bfcplatform.vn" -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

-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