rclone으로 리눅스(우분투)와 구글드라이브 연동하기

2021. 3. 1. 15:45설치법/시스템

 

 


시작하면서

 

주 사용 데스크탑은 리눅스고, 문서나 이미지들은 모두 윈도우에 있는데.

키보드나 마우스는 barrier를 통해 공유하기 때문에 편집 상의 어려움은 없으나

파일을 공유할 때에는 명령어를 쓰거나 깃허브 cli를 이용하는 게 너무 귀찮았네요.

 

구글 드라이브에는 윈도우나 안드로이드에서는 파일 내용을 자동으로 동기화해주는 서비스를 진행하는데

 

다운로드 - Google 드라이브

어느 기기에서나 콘텐츠에 액세스하고 콘텐츠를 동기화하세요.

www.google.com

정작 우분투는 없네요.

 

그래서 대안으로 깃허브를 찾아봤는데 아니나 다를까 저와 똑같은 귀찮음을 가진 사람들이 가상 파일 시스템으로 마운트하도록 해주는 프로젝트가 눈에 띄었습니다.

 

 

rclone/rclone

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Yandex Files - rclone/rclone

github.com

 

 

astrada/google-drive-ocamlfuse

FUSE filesystem over Google Drive. Contribute to astrada/google-drive-ocamlfuse development by creating an account on GitHub.

github.com

어차피 둘 다 구글 드라이브 API를 사용하는 건 똑같을 것 같고... 둘 중 뭐를 사용할까 고민하다가, 특정 폴더만 마운트하고 싶기 때문에 rclone을 선택하게 되었습니다.

 

아래는 가상 파일 시스템으로 마운트해주는 프로젝트들을 소개한 포스트입니다.

 

How To Mount Google Drive Locally As Virtual File System In Linux

This guide explains how to mount Google drive locally as a virtual file system and access your drive files in your Linux box.

ostechnix.com

 

참고로 아래를 방문하면 구글 드라이브 API에 대해 알아볼 수 있어요.

 

Introduction to Google Drive API  |  Google Developers

The Drive REST API lets you create web apps that access files stored in Google Drive.

developers.google.com

만약 한번 연습삼아 해보고 싶다면, credentials.json 파일을 받고 아래와 같이 루트 내 파일 리스트를 볼 수 있는 예제를 실행해보세요.

# Google drive apis
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request

# Full, permissive scope to access all of a user's files, excluding the Application Data folder.
SCOPES = ['https://www.googleapis.com/auth/drive']

# Set authentication and start the service
flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
service = build('drive', 'v3', credentials=creds)

# Call Drive v3 API 
# @ List-up whole files at root
params = {
    "list":{
        "orderBy":"modifiedByMeTime",
        "fields":"files(id, name, mimeType)",
        "q":"'root' in parents"
    }
}

results = service.files().list(**params['list']).execute()
print(results)

 

 

 


rclone 설치

 

저는 Ubuntu 20.04 LTS 운영체제 환경에서 수행했습니다.

 

설치법은 공식 가이드를 참고했는데, 매우 간단합니다. 그냥 아래 명령어를 수행하면 알아서 설치해줍니다.

curl https://rclone.org/install.sh | sudo bash

 

 

 


마운트하기

 

저는 Blog 디렉터리만 동기화하고 싶으므로 해당 디렉터리 위주로 소개하겠습니다.

루트 아래에 위치해 있어요.

드라이브를 설정하는 건 공식 가이드에서 정말 쉽게 따라할 수 있습니다.

 

다만 몇 가지 팁을 드리면, client_id와 client_secret은 credentials.json 파일 내에서 찾거나 발급 당시에 제공했던 것을 이용해야 하며 아래처럼 고급 설정을 묻는 경우에는 n을 입력해서 스킵하면 됩니다.

Edit advanced config? (y/n)
y) Yes
n) No (default)
y/n> n

 

마지막으로 드라이브 설정이 완료되면 q를 눌러 나오고, 맨 밑줄처럼 마운트 명령어를 작성하면 됩니다.

--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y
Current remotes:

Name                 Type
====                 ====
remote               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> q

$ rclone mount remote:Blog /마운트하고 싶은 디렉토리 경로

그럼 동기화가 진행됩니다.

만약 백그라운드로 실행하고 싶다고 하면 맨 뒤에 &를 붙이면 됩니다.

$ rclone mount remote:Blog /마운트하고 싶은 디렉토리 경로 &

 

 

 


끝내면서

 

역시 훨씬 편하네요.

 

현재는 컴퓨터를 다시 시작하면 다시 켜야하는 불편함이 있는데, 이는 시작프로그램에 등록하면 되니까 문제 없겠어요.