# Migrate file S3 AWS to S3 Nipa

ในกรณีที่ลูกค้าต้องการย้ายข้อมูลจาก Amazon S3 มาใช้งาน S3 Bucket ของ Nipa Cloud สามารถดำเนินการ โดยใช้ s3fs และ rsync ได้ตามขั้นตอนต่อไปนี้

ข้อกำหนด

&#x20;      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/>)

&#x20;      b. เตรียม instance สำหรับ mount s3fs (ตัวอย่างในเอกสารใช้ Ubuntu 22.04)

<br>

ขั้นตอนการ sync file จาก S3 AWS มายัง S3 Nipa cloud รายละเอียดดังนี้

1. ดำเนินการสร้าง 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>

<br>

2. เมื่อสร้าง S3 Bucket Nipa และ user Access-ID, Secret Key เรียบร้อย ให้ SSH ไปยัง instance ที่สร้างไว้
3. ติดตั้ง 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 s3fsCopy
```

![](https://t9003005656.p.clickup-attachments.com/t9003005656/02dd8814-09ba-4469-a62a-46ccbfc30119/image.png)

4. ดำเนินการสร้างไฟล์สำหรับเก็บ 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-nipaCopy
```

5. ดำเนินการสร้าง Path สำหรับ mount S3 AWS และ mount S3 Nipa

```
mkdir -p /mnt/s3aws
mkdir -p /mnt/s3nipacloudCopy
```

6. ดำเนินการ mount S3 Bucket AWS ไปยัง /mnt/s3aws โดยมีลายละเอียด option ดังนี้

```
sudo s3fs {bucketname} {/mountpoint} -o passwd_file=/etc/passwd-s3fs-awsCopy
```

{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-awsCopy
```

7. ดำเนินการ 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.cloudCopy
```

{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.cloudCopy
```

8. ตรวจสอบว่าสามารถ mount S3 Bucket สำเร็จหรือไม่ โดย run command

```
df -hCopy
```

![](https://t9003005656.p.clickup-attachments.com/t9003005656/92cbde96-9f03-4197-906a-b45f71d0a693/image.png)

9. ดำเนินการ 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/Copy
```

10\. เมื่อ sync ไฟล์เสร็จเรียบร้อย ให้ตรวจสอบไฟล์ใน S3 Bucket Nipa ว่าครบหรือไม่โดยสามารถ run command

```
diff -r {/path/to/source} {/path/to/destination}
# คำสั่ง diff จะแสดงความแตกต่างระหว่างไฟล์ในไดเรกทอรีต้นทางและไดเรกทอรีปลายทาง ถ้าไม่มีผลลัพธ์ที่แสดงออกมา แสดงว่าไฟล์ต้นทางและปลายทางเท่ากัน

#ตัวอย่าง Command
diff -r /mnt/s3aws /mnt/s3nipacloud
```
