본문 바로가기
개발환경/Tips

rclone을 활용하여 Microsoft OneDrive를 네트위크 드라이브로 마운트하는 방법

by Kibua20 2021. 2. 27.

Windows OS 에서는 Microsoft가 OneDrive Client를 '공식' 지원하고 있지만, 리눅스 계열에서는 Microsoft에서 공식 지원하는 OneDrive client는 없고 OneDrive와 호환 가능한 Client 설치를 사용해야 합니다. 필요한 기능은 OneDirve Cloud의 원격 저장소를 네트우크 드라이브로 마운트하는 것이였고 몇 가지 tool을 검토한 결과 rclone을 사용하기로 했습니다.

 

rclone은 구글의 Go 언어로 개발된 클라우드 저장소 sync 프로그램입니다. rclone은 Windows, Linux, Mac까지 모두 지원하면 기본적으로 command line interface이지만 GUI Frontend도 지원합니다.  또한 OneDrive 뿐 아니라 Google Drive, Photo, Amazon S3, FTP, sFTP, WebDAV 등 많은 저장소를 지원하고 있습니다. 

 

rclone 주요 기능은 다음과 같습니다 (출처: rclone.org)

  • Backup (and encrypt) files to cloud storage
  • Restore (and decrypt) files from cloud storage
  • Mirror cloud data to other cloud services or locally
  • Migrate data to cloud, or between cloud storage vendors
  • Mount multiple, encrypted, cached or diverse cloud storage as a disk
  • Analyse and account for data held on cloud storage using lsf, ljson, size, ncdu
  • Union file systems together to present multiple local and/or cloud file systems as one

 

rclone 설치

rclone 다운로드는 rclone.org/downloads/에 설명되어 있고, 터미널에서 아래래 명령어를 실행합니다. 

 

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

 

install.sh 내용은 OS에 알맞은 실행 파일을 찾아 압축을 풀어 시스템에 설치합니다.  아래 예제에서는 rclone-current-linux-amd64.zip 파일입니다.  Windows에서는 rclone.exe를 복사해서 설치합니다.  본 글 작성 시점에서는 rclone v1.54.0이 최신 버전입니다. 

 

 

rclone 설치: sudo curl  https://rclone.org/install.sh   sudo bash

 

 

rclone config 설정

rclone은 아래와 같으 다양한 저장소를 지원하기 때문에 이에 맞는 config를 설정해야 합니다.  rclone.org/docs/ 에서 Microsoft One driver을 config 설명을 참고해서 설정할 수 있습니다.

 

$ rclone config

 

rclone config 설정

 

rclone config 설정 - Microsoft OneDrive

rclone.org/onedrive/에서 설명한 것 처럼  각각의 단계를 설정합니다.  붉은 색 표시가 선택이 필요한 항목입니다.

 

$ rclone config

 

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   

→원격 저장소를 새로 생성

 

name> onedrive   

원격 저장소의 이름으로 원하는 이름을 추가하면 됩니다.

 

 

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

[snip]

XX / Microsoft OneDrive​

   \ "onedrive"

[snip]

Storage> onedrive

원격 저장 종류를 선택 (onedrive를 입력하거나, 앞에 번호를 입력합니다.)

Microsoft App Client Id

Leave blank normally.

Enter a string value. Press Enter for the default ("").

client_id>​

→ client_id를 빈 공간으로 유지합니다. 추후 설정 예정입니다.

 

Microsoft App Client Secret

Leave blank normally.

Enter a string value. Press Enter for the default ("").

client_secret>​

 → client_secret를 빈 공간으로 유지합니다.  추후 설정 예정입니다.

 

Edit advanced config? (y/n)

y) Yes

n) No​

y/n> n

 → client_id와 secret를 직접 설정할 수 있고, 서버 인증에 필요한 값을 직접 설정 가능합니다.  OneDrive는 굳이 추가 설정할 필요는 없습니다. 

Remote config

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

If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth

Log in and authorize rclone for access

Waiting for code...

Got code

Choose a number from below, or type in an existing value

1 / OneDrive Personal or Business​

   \ "onedrive"

2 / Sharepoint site

   \ "sharepoint"

3 / Type in driveID

   \ "driveid"

4 / Type in SiteID

   \ "siteid"

5 / Search a Sharepoint site

   \ "search"

Your choice> 1

 

 →  이 과정은 client_id, client_screte를 가지고 access_token과 refresh token을 얻는 과정입니다. 

 →  각 계정에 맞는 one drive URL을 표시합니다. 계정이 여러 개 있거나 인증에 문제가 있는 경우에는  onedrive.live.com/에 sign in 해야합니다.  아래와 같이 Onedrive의 계정을 선택하고 rclone이 사용 여부를 확인하고 SUCCESS 가 나와야 합니다. 

 →   개인용 One drive 계정은 정상동작하나, Business 계정인  sharepoint.com는 인증 에러가 나네요. (해결책을 찾고 있으면 찾으며 업데이트하도록 하겠습니다.)

 

rclone OAuth 인증 과정

 

Found 1 drives, please select the one you want to use:

0: OneDrive (business) id=b!Eqwertyuiopasdfghjklzxcvbnm-7mnbvcxzlkjhgfdsapoiuytrewqk

Chose drive to use:> 0

 

Found drive 'root' of type 'business', URL: https://org-my.sharepoint.com/personal/you/Documents​

Is that okay?

y) Yes​

n) No

y/n> y

--------------------

[onedrive]

type = onedrive

token = {"access_token":"youraccesstoken","token_type":"Bearer","refresh_token":"yourrefreshtoken","expiry":"2018-08-26T22:39:52.486512262+08:00"}

drive_id = b!Eqwertyuiopasdfghjklzxcvbnm-7mnbvcxzlkjhgfdsapoiuytrewqk

drive_type = business

--------------------

y) Yes this is OK​

e) Edit this remote

d) Delete this remote

y/e/d> y

 →  One drive 인증 결과입니다.  access_token과 refresh_token이 token이 사용자 ID와 Password 대신 사용하는 비밀번호로 이해면 됩니다. OAuth 2.0에 대한 이해가 있어야 합니다.  링크를 참고를 해주세요.

 → 인증 결과는 ~/.config/rclone/rclone.conf 파일에 저장되어 있습니다.

 → $ cat  ~/.config/rclone/rclone.conf 

 

rclone 명령어 사용

$ rclone --help를 통해서 명령어 리스트를 확인할 수 있습니다.  또는 rclone.org/commands/ 에서 명령어 리스트를 확인합니다. 원격 저장소의 mkdir, rmdir, sync, copy, ls, lsd, delet, mount를 할 수 있습니다. 

 

 

 

rclone 명령어

 

 

 

rclone 명령어

 

아래 그림은 One Drive를  Web에서 확인한 예제입니다. 

$ rclone ls ondrive:

 

$ rclone ls ondrive

 

rclone 명령어로 원격 저장소 Mount

rclone mount 명령어를 파일 시스템으로 마운트 합니다.  Windows와 리눅스에 따라서 각각 다른 명령어를 사용해야 합니다. 상세한 내용은 $ rclone mount --help 명령어로 확인할 수 있습니다. 

 

Usage:

     # 리눅스 
     rclone mount remote:path /path/to/mountpoint [flags]

 

      #Windows 

      $ rclone mount remote:path/to/files X:

      $ rclone mount remote:path/to/files X: --network-mode

 

 

본인 계정의 onedrive의 mount point의 폴더를 만들고 $ rclone mount  <remote name>: /path/to/mount 명령어를 실행합니다.  

 

$ mkdir ~/onedrive

$ rclone mount onedrive: ~/onedrive 

 

 

네트워크에 있는 저장소 One drive를 마운트 해서 nautilus에서도 해당 폴더를 확인할 수 있으면, 읽기/쓰기 명령어가 모두 가능합니다. 

 

nautilus 에서 One dirve 파일 확인

 

 

Mount 해제는 아래 명령어를 사용합니다. 

$ fusermount -uz ~/onedrive

 

rclone 저장소를 부팅 시 Mount

시작 프로그램 기본 설정에서 rclone 명령어를 추가합니다. 여기서 주의해야 할 점은  mount Point를 절대 경로로 입력하세요.  다른 방법으로 ~/.bashrc  파일에 아래 명령어를 추가해도 무방합니다. 

 

# 시작 프로그램 실행  

$ gnome-session-properties

 

# 시작 프로그램 → 추가 메뉴 

* 이름: onedrive (임의의 이름도 무방함)

* 명령어: rclone mount onedrive: /home/kibua20/onedrive 

 

rclone 저장소를 부팅 시 Mount

 

rclone 저장소를 sync 

원격 저장소와 Local 저장소의 폴더를 동기화하는 것입니다. Mount는 파일을 네트워크 상태에서 가지고 있는 것이고, rclone sync 명령어를 사용하는 원격의 파일을 Local로 다운로드하여  동기화 합니다.  

 

$  rclone sync onedirve:/  ~/mnt/onedrive_sync 

 

rclone Web GUI Front-end

rclone에서 Command line 뿐 아니라 Web interface도 지원합니다. $ rclone rcd --rc-web-gui 명령어를 실행하면 원격 저장소의 config, 파일 탐색, Backend (DLNA 또는 ftp), Mount point까지 설정할 수 있습니다. 

 

$ rclone rcd --rc-web-gui

 

rclone Web GUI Front-end

 

rclone 과 OneDrive 활용 예

클라우드의 OneDrive를 ~/onedrive로 mount  상태에서 youtube-dl으로 뮤직 비디오를 저장할 수 있습니다. 기존에는 Local PC의 SSD에 저장하고 이를 다시 OneDrive Cloud를 옮기는 과정을 거쳐야 하나 지금은 실시간으로 업로드 가능하고 다른 PC나 Device에서도 바로 활용할 수 있습니다. 

 

  • 기존: Youtube에서 음악 다운로드 → 로컬 PC의 SSD로 저장 → OneDrive Cloud 로 upload 
  • 현재: Youtube에서 음악 다운로드 → 로컬 PC의 SSD로 저장 → OneDrive Cloud 로 upload 

 

rclone 과 OneDrive 활용 예: 로컬 PC의 저장소를 거치지 않고 바로 Cloud로 upload가 가능함

 

 

관련 글:

[개발환경/Tips] - OneDrive를 활용한 파일 공유 방법: URL 생성 및 삭제 방법

[개발환경/Tips] - Microsoft Office 365 '무료'로 사용하기: 우분투 환경에서 학생/교사용으로 무료 등록

[개발환경/Tips] - 네이버 동영상 다운로드 방법 (동영상과 설명 포함)

[모바일 SW 개발/REST API] - 자주 사용하는 curl 명령어 옵션과 예제

[모바일 SW 개발/REST API] - 라이딩 앱 STRAVA API 연동 방법 (Sample code)

[모바일 SW 개발/REST API] - 외부 망에서 Localhost를 접속하기: localtunnel (무료, domain제공)

[개발환경/Web Server] - Website 전체 백업 방법: HTTrack (티스토리 백업에 활용)

[개발환경/우분투] - Docker 개념과 명령어 사용 방법 및 예제

[개발환경/Google Cloud Platform] - GCP에서 Squid를 이용한 Proxy 서버 설정 방법

[개발환경/Oracle Cloud] - Oracle Cloud SSH Key 여러 개 등록하기 (여러 PC에서 Cloud Access)

[개발환경/Oracle Cloud] - Oracle Cloud 블록 스토리지 추가 방법 (HDD 추가 가이드)

[개발환경/Oracle Cloud] - 오라클 클라우드 '평생' 무료 VM 만들기 (Google Cloud 무료 조건 비교)

[개발환경/Google Cloud Platform] - GCP(Google Cloud) 원격 데스크 톱(RDP) 연결: Linux 용 Chrome RDP

[개발환경/Google Cloud Platform] - GCP(Google Cloud) 방화벽 설정: 프로토콜과 포트를 사용 허용 또는 거부하기

[모바일 SW 개발/REST API] - Google Gmail API 사용 방법 (1) - Sample code

[개발환경/Tips] - Microsoft Office 365 '무료'로 사용하기: 우분투 환경에서 학생/교사용으로 무료 등록




댓글