Study/Resource

[Drive] Linux 서버와 Google Drive 연동 (데이터 백업)

2021. 2. 8. 14:38

로컬 컴퓨터와 구글 드라이브는 Backup and Sync를 사용하여 백업 및 동기화를 하면 되지만,

 

[Backup and Sync from Google] Google Drive 백업 및 동기화

여러 대의 컴퓨터를 사용하면서 파일의 동기화가 필요하거나 데이터 백업이 필요할 때, Google Drive와 Backup and Sync를 사용할 수 있다. 이 포스트에서는 Google Drive와 로컬 컴퓨터를 연결해주는 Backup

bioinfoblog.tistory.com

위 프로그램은 Linux 시스템에 대해서는 기능을 제공하지 않기 때문에 다른 프로그램을 찾아야 한다.

 

검색해보니 Insync 프로그램이 Linux와 구글 드라이브의 연결을 지원한다고 하여 찾아봤지만, 서버와 연결을 하려면 매년 돈을 지불해야 한다고 하여 마음을 접었다.

 

Insync - Google Drive & OneDrive Syncing on Linux, Windows & Mac

Give all your computers & files the power of Google Drive & OneDrive. Sync, use & share your files directly from Explorer, Nautilus, Caja, Nemo & Finder.

www.insynchq.com

 

최종적으로 선택한 것은 구글 드라이브 팀의 개발자가 만들던 drive 프로그램이다.

 

odeke-em/drive

Google Drive client for the commandline. Contribute to odeke-em/drive development by creating an account on GitHub.

github.com

Backup and Sync처럼 자동 동기화는 지원하지 않지만, 개인적으로 그 기능은 꼭 필요하지 않았기 때문에 위 프로그램을 잘 쓰고 있는 중이다.

 

Installing

먼저 linux 서버에 drive를 설치하기 위해서 go가 필요하다.

 

Download and install - The Go Programming Language

Download and install Download and install Go quickly with the steps described here. For other content on installing, you might be interested in: 1. Go download. Click the button below to download the Go installer. Download Go Don't see your operating syste

golang.org

1. Root 계정으로 서버에 로그인한 이후, go를 다운로드하고 압축을 풀어준다.

wget https://golang.org/dl/go1.15.6.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.15.6.linux-amd64.tar.gz

2. /usr/local/go/bin를 환경변수에 등록한다.

export PATH=$PATH:/usr/local/go/bin

3. 설치한 go의 버전을 확인할 수 있다.

go version

4. Go를 이용하여 drive 설치를 할 수 있다.

go get -u github.com/odeke-em/drive/cmd/drive

Usage

Initializing

먼저 drive와 연결할 폴더를 정해야한다 (아래에서 server/.. 대신 원하는 폴더 경로).

주의해야할 점은 server 폴더를 백업하고 싶다면 server 폴더의 상위폴더에 대해 init을 진행해야 한다.

drive init server/..

그러면 Visit this URL to get an authorization code라고 안내를 해주는데,

URL로 들어가서 Authorization code를 확인한 후 붙여 넣어주면 연결이 완료된다.

 

Pull & Push

pull과 push는 Git과 마찬가지로 사용해주면 된다.

 

Pull

서버의 폴더를 구글 드라이브에 있는 폴더로 맞추어준다.

--exclude-ops "delete" 옵션으로 삭제 방지 가능.

drive pull server/
drive pull --exclude-ops "delete" server/

Push

구글 드라이브의 폴더를 서버에 있는 폴더로 맞추어준다.

--exclude-ops "delete" 옵션으로 삭제 방지 가능.

drive push server/
drive push --exclude-ops "delete" server/

 

De Initializing

다음 명령어로 연결을 해지할 수 있다.

drive deinit

 

혹은 서버에 직접적인 접근이 어렵다면, 구글 계정 내에서도 연결을 해지할 수 있다.

 

로그인 - Google 계정

하나의 계정으로 모든 Google 서비스를 Google 계정으로 로그인

accounts.google.com

구글 내 계정 > 보안 > 계정 액세스 권한을 가진 Google 앱 > drive for Google Drive 액세스 권한 삭제

하지만 위 방법은 모든 연결이 해지되니 주의가 필요하다.

728x90
반응형