มาเพิ่มพื้นที่ในคอมด้วย Google Drive + Rclone
ใครเคยประสบปัญหาพื้นที่ในฮาร์ดดิสก์เหลือน้อยเต็มที โดยเฉพาะคนที่ใช้เครื่อง Mac แต่ไม่ได้อัพเกรดขนาดของฮาร์ดดิสก์ เราพอจะมีวิธีแก้ปัญหานี้หรือเปล่า?
Rclone คืออะไร?
Rclone คือแอปพลิเคชันสำหรับ create และ mount สิ่งที่เรียกว่า Virtual File System บน Linux แบบ locally ซึ่งใช้งานได้ฟรี และรองรับ type of storage มากถึง 27 แบบ โดยในบทความนี้จะยกตัวอย่างเป็น Google Drive
โหลดแอปพลิเคชัน Google Drive, Dropbox หรือ OneDrive มาติดตั้งไม่ได้เหรอ?
โดยปกติแล้วแอปพลิเคชันเหล่านี้มันจะโหลดไฟล์มาเก็บไว้ในเครื่องทำให้เราสามารถใช้งานได้กรณีที่เราออฟไลน์ (ก็แหงล่ะ โหลดมาไว้ในเครื่องแล้วหนิ) แต่ข้อเสียคือ “มันใช้เนื้อที่ของฮาร์ดดิสก์ของเราด้วยไง” มันมีไว้เพื่อ sync ข้อมูลระหว่างเครื่องเรากับบนเซิร์ฟเวอร์เท่านั้น ซึ่งบางเจ้าก็จะมีฟีเจอร์ที่ไม่โหลดไฟล์ลงมาเก็บบนเครื่องแต่ก็ต้องแลกมาด้วยเงิน (ต้องซื้อ package เพื่อ upgrade)
หมายเหตุ: ความเร็วในการอ่านเขียนข้อมูลขึ้นอยู่กับ bandwidth ของ internet ที่ใช้ อย่าเอาเกมหนักๆ มาใส่ในนี้ ถึงแม้มันจะโหลดเข้าไปในแรมก่อนก็เถอะ
แล้วทำยังไงดีล่ะ?
ก็ใช้ Rclone ไง
วิธีติดตั้ง Rclone
สำหรับ Linux, Mac OS และ BSD systems ติดตั้งโดยวิธีนี้จะง่ายที่สุด
$ curl https://rclone.org/install.sh | sudo bash
วิธี config
รันคำสั่ง
$ rclone config
ตอบ n แล้วกด enter เพื่อเพิ่ม remote ใหม่
Current remotes:
Name Type
==== ====
ku-google-drive drive
e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> n
ตั้งชื่อ remote
name> googledrive
เลือก 12 (Google Drive)
Type of storage to configure.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
1 A stackable unification remote, which can appear to merge the contents of several remotes
2 Alias for an existing remote
3 Amazon Drive
4 Amazon S3 Compliant Storage Provider (AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, etc)
5 Backblaze B2
6 Box
7 Cache a remote
8 Dropbox
9 Encrypt/Decrypt a remote
10 FTP Connection
11 Google Cloud Storage (this is not Google Drive)
12 Google Drive
13 Hubic
14 JottaCloud
15 Koofr
16 Local Disk
17 Mega
18 Microsoft Azure Blob Storage
19 Microsoft OneDrive
20 OpenDrive
21 Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
22 Pcloud
23 QingCloud Object Storage
24 SSH/SFTP Connection
25 Webdav
26 Yandex Disk
27 http Connection
Storage> 12
หลังจากนี้มันจะให้ config ค่าต่างๆ ซึ่งผมกด Enter รัวๆ เพื่อใช้ค่า default value (แต่ละ storage ใช้ parameter ไม่เหมือนกันน๊า)
เลือก scope ว่าให้ทำอะไรได้บ้าง (ในที่นี้จะเลือก Full access คือเบอร์ 1)
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
1 / Full access all files, excluding Application Data Folder.
2 / Read-only access to file metadata and file contents.
/ Access to files created by rclone only.
3 | These are visible in the drive website.
| File authorization is revoked when the user deauthorizes the app.
/ Allows read and write access to the Application Data folder.
4 | This is not visible in the drive website.
/ Allows read-only access to file metadata but
5 | does not allow any access to read or download file content.
scope> 1
จะ config แบบ advanced หรือไม่ ผมตอบ No!! ด้วยความเร่งรีบ
Edit advanced config? (y/n)
y) Yes
n) No
y/n> n
อะไรที่ auto ได้ก็จัดมาจ้า ตอบ Yes อย่างไว
Use auto config?
* Say Y if not sure
* Say N if you are working on a remote or headless machine
y) Yes
n) No
y/n>y
allow permission
success แล้วก็ปิดมันไป
ตอบ “n” ไม่มีทีมครับผม
Configure this as a team drive?
y) Yes
n) No
y/n>n
ตอบ “y” เพื่อ confirm เอาตามนี้แหละ
--------------------
[googledrive]
type = drive
scope = drive
token = {"access_token":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX","expiry":"2019-07-29T21:14:49.910599+07:00"}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d>y
ที่นี้เราจะได้
Name Type
==== ====
googledrive drive
เพียงเท่านี้ก็จะมี volume เพิ่มเข้ามาในเครื่องแล้ว ปรบมือ 👏🏻
ตอบ “q” เพื่อนออกจาก rclone
e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q
แต่เดี๋ยวก่อน!! มันต้อง mount volume นี้ด้วยนะถึงจะใช้งานได้
สร้าง directory เพื่อเก็บข้อมูล
$ mkdir ~/googledrive
mount volume
$ rclone mount googledrive: ~/googledrive/
เป็นอันเสร็จพิธี
หมายเหตุ: คำสั่งนี้จะไม่มีการ return ค่าออกมา ต้องส่ง interrupt signal หรือ ctrl+c เพื่อหยุดการทำงาน
ไหนลองตรวจดูซิ
$ df -h
โอ้โห เพิ่มมาตั้ง 15 Gibibytes
ข้อจำกัดของการใช้ Rclone
หากไม่มีการใช้ “— vfs-cache-mode” (ซึ่งเราไม่ได้กำหนดตอน config) จะเขียนไฟล์ได้แบบ sequentially เท่านั้น และมันสามารถค้นหาได้เมื่ออ่านเท่านั้น หมายความว่าบางโปรแกรมจะทำงานบน rclone ไม่ได้ ถ้าไม่ได้กำหนด “ — vfs-cache-mode write” หรือ“ — vfs-cache-mode full” ดูข้อมูลการ cache ไฟล์เพิ่มเติมได้ที่ https://rclone.org/commands/rclone_mount/#file-caching
Mount on Boot
มีหลายวิธีที่จะรัน RClone ขึ้นมาตอน reboot แต่ในที่นี้เราจะเสนอให้ใช้ crontab ในการรันมันขึ้นมา
$ crontab -e
เพิ่มข้อความนี้ด้านล่างสุดของไฟล์ และทำการบันทึก
@reboot /usr/local/bin/rclone mount googledrive: ~/googledrive/ &