Migrate file S3 AWS to S3 NIPA
ในกรณีที่ลูกค้าต้องการย้ายข้อมูลจาก Amazon S3 มาใช้งาน S3 Bucket ของ Nipa Cloud สามารถดำเนินการ โดยใช้ s3fs และ rsync ได้ตามขั้นตอนต่อไปนี้
ข้อกำหนด
a. ต้องจัดเตรียม S3 Bucket, Access ID และ Secret Key ของ AWS และ Nipa cloud เพื่อใช้สำหรับ mount s3fs (สำหรับ AWS สามารถเตรียมโดยรายละเอียดเพิ่มเติมตาม link :https://www.nakivo.com/blog/mount-amazon-s3-as-a-drive-how-to-guide/)
b. เตรียม instance สำหรับ mount s3fs (ตัวอย่างในเอกสารใช้ Ubuntu 22.04)
ขั้นตอนการ sync file จาก S3 AWS มายัง S3 Nipa cloud รายละเอียดดังนี้
ดำเนินการสร้าง S3 bucket บน Nipa Cloud Space ขั้นตอนการสร้างรายละเอียดตาม link ด้านล่าง
#สร้าง bucket เพื่อใช้เป็น container เก็บ object ต่างๆ สำหรับ object storage
https://docs-epc.gitbook.io/ncs-documents/object-storage/create-an-object-storage-bucket
#ในการ authen เข้าใช้งาน bucket ที่สร้างบน Nipa Cloud Space จะทำโดยใช้ access ID และ secret key ที่อยู่ใน sub-user
https://docs-epc.gitbook.io/ncs-documents/object-storage/create-object-storage-sub-user
#สร้าง policy เพื่อจำกัดการเข้าใช้งาน bucket
https://docs-epc.gitbook.io/ncs-documents/object-storage/create-bucket-policy
เมื่อสร้าง S3 Bucket Nipa และ user Access-ID, Secret Key เรียบร้อย ให้ SSH ไปยัง instance ที่สร้างไว้
ติดตั้ง dependency สำหรับใช้งาน s3fs
apt update
apt-get -y install automake autotools-dev fuse g++ git libcurl4-gnutls-dev libfuse-dev libssl-dev libxml2-dev make pkg-config
# ติดตั้ง s3fs-fuse
git clone https://github.com/s3fs-fuse/s3fs-fuse.git
cd s3fs-fuse/
./autogen.sh
./configure --prefix=/usr --with-openssl
make
make install
#ตรวจสอบว่าติดตั้ง s3fs สำเร็จหรือไม่
which s3fs

ดำเนินการสร้างไฟล์สำหรับเก็บ Access ID, Secret Key
# Access ID สำหรับ mount S3 AWS
echo "ACCESS_KEY:SECRET_KEY" | sudo tee /etc/passwd-s3fs-aws
# Access ID สำหรับ mount S3 NIPA
echo "ACCESS_KEY:SECRET_KEY" | sudo tee /etc/passwd-s3fs-nipa
# เปลี่ยน Permission ของไฟล์
chmod 600 /etc/passwd-s3fs-aws
chmod 600 /etc/passwd-s3fs-nipa
ดำเนินการสร้าง Path สำหรับ mount S3 AWS และ mount S3 NIPA
mkdir -p /mnt/s3aws
mkdir -p /mnt/s3nipacloud
ดำเนินการ mount S3 Bucket AWS ไปยัง /mnt/s3aws โดยมีรายละเอียด option ดังนี้
sudo s3fs {bucketname} {/mountpoint} -o passwd_file=/etc/passwd-s3fs-aws
{bucketname} = ชื่อของ bucket ที่สร้าง ตัวอย่างเช่น my-bucket
{/mountpoint} = path ที่ต้องการ mount ไฟล์จาก s3 bucket aws ตัวอย่างเช่น /mnt/s3aws
# ตัวอย่าง Command
sudo s3fs my-bucket /mnt/s3aws -o passwd_file=/etc/passwd-s3fs-aws
ดำเนินการ mount S3 Bucket NIPA ไปยัง /mnt/s3nipacloud
sudo s3fs {bucketname} {/mountpoint} -o passwd_file=/etc/passwd-s3fs-nipa -o allow_other -o url=https://s3-bkk.nipa.cloud
{bucketname} = ชื่อของ bucket ที่สร้าง ตัวอย่างเช่น my-bucket
{/mountpoint} = path ที่ต้องการ mount ไฟล์จาก s3 bucket aws ตัวอย่างเช่น /mnt/s3aws
# ตัวอย่าง Command
sudo s3fs my-bucket /mnt/s3nipacloud -o passwd_file=/etc/passwd-s3fs-nipa -o allow_other -o url=https://s3-bkk.nipa.cloud
ตรวจสอบว่าสามารถ mount S3 Bucket สำเร็จหรือไม่ โดย run command
df -h

ดำเนินการ sync file จาก S3 Bucket AWS ไปยัง S3 Bucket NIPA
rsync -av --progress {/path/to/source/} {/path/to/destination/}
# ตัวอย่าง Command
rsync -av --progress /mnt/s3aws/ /mnt/s3nipacloud/
10. เมื่อ sync ไฟล์เสร็จเรียบร้อย ให้ตรวจสอบไฟล์ใน S3 Bucket NIPA ว่าครบหรือไม่โดยสามารถ run command
diff -r {/path/to/source} {/path/to/destination}
# คำสั่ง diff จะแสดงความแตกต่างระหว่างไฟล์ในไดเรกทอรีต้นทางและไดเรกทอรีปลายทาง ถ้าไม่มีผลลัพธ์ที่แสดงออกมา แสดงว่าไฟล์ต้นทางและปลายทางเท่ากัน
#ตัวอย่าง Command
diff -r /mnt/s3aws /mnt/s3nipacloud
Last updated
Was this helpful?