docker container의 파일을 Google Drive에 올리는 방법 (rclone)

Sieun·2025년 1월 2일
2

Data Engineering

목록 보기
5/5
post-thumbnail

진행 환경

  • vscode를 활용한 서버 접속 (Docker Container)

Rclone Official Doc

https://rclone.org/

1. rclone 설치

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

2. rclone.conf 파일 생성

1. n) New remote 선택

2. name> {원하는 remote 저장소 이름 입력. ex) gdrive}

3. Type of storage to configure.
Storage> drive 입력

4. Google Application Client Id
client_id> Press Enter (필수 입력 값 아님.)
client_secret> Press Enter (필수 입력 값 아님.)

5. Scope that rclone should use when requesting access from drive.
scope> drive

6. 이후 옵션 모두 공란으로 두고 Press Enter

7. 브라우저로 연결되면 드라이브를 사용하고자 하는 구글 계정으로 로그인

8. Configure this as a team drive? 라는 질문이 나오면
n) No (default) 선택

9. 설정 값 확인 후
y) Yes this is OK (default) 선택

3. remote 저장소 접속 확인

rclone lsd gdrive:

위 명령어를 입력하면 remote 저장소 (이 경우에는 설정한 google drive) 내에 있는 폴더가 출력됨.

4. google drive 마운트

1) 마운트할 폴더 생성

sudo mkdir /mnt/{저장소 이름 ex) gdrive}

2) user 권한 부여

sudo chown [USER]:[GROUP] [TARGET_PATH]
예시) sudo chown user:user /mnt/gdrive
  • USER 확인 명령어
cat /etc/passwd | grep {사용자 이름(id)}

*작업 환경이 Docker container인 경우,
사용자 이름은 터미널에서 바로 확인 가능 - 사용자 이름@컨테이너 id
  • GROUP 확인 명령어
groups {사용자 이름(id)}

3) 마운트한 폴더(/mnt/gdrive)의 소유자가 변경되었는지 확인

ls -ld /mnt/gdrive

위 명령어 입력 시 GROUP USER 출력되면 성공.

5. rclone으로 업로드

1) 업로드 명령 실행

rclone copy {업로드 대상 로컬 디렉토리 경로} {rclone config에 설정한 remote name}:/{Google Drive의 대상 디렉토리 명} -P
예시) rclone copy /home/user/mydata gdrive:/mydata -P

2) 업로드 확인

rclone ls {rclone config에 설정한 remote name}:/{Google Drive의 대상 디렉토리 명}
예시) rclone ls gdrive:/mydata

위 명령어를 실행하여 터미널에서 Google Drive에 업로드된 파일과 디렉토리를 확인할 수 있음.

To-Do

내 드라이브가 아닌 공유 문서함을 remote로 설정하여 rclone 명령으로 파일을 업로드하는 방법 알아내기


ref
https://data-science.tistory.com/380

profile
Studying AI/ML with a focus on Multimodal Learning 👩🏻‍💻

0개의 댓글