이야기박스

gsutil ; change directory path 본문

Computer & Data/Cloud Platform

gsutil ; change directory path

박스님 2020. 6. 11. 12:28
반응형

 

gsutil로 GCS 경로 이동하면서 생겼던 일들을 짧은 포스팅으로 담아 보려고 합니다.

 

# 목적

gs://storyparks_bucket/dir_a 라는 경로의 폴더를 gs://storyparks_bucket/dir_b 로 옮기자!

즉, 폴더 이름을 변경 혹은 dir_a의 파일들을 dir_b로 옮기는 것이 되겠네요

 

# Solution 1. mv 명령어 사용

hdfs 명령어에서는 mv에 wildcard(*)를 사용하여 다음과 같이 손쉽게 파일들을 옮길 수 있었습니다. 

hdfs dfs -mv hdfs://storyparks_datalake/dir_a/* hdfs://storyparks_datalake/dir_b/

 

하지만 gsutil에서는 mv 명령어에 wildcard(*) 사용이 불가능 하더라고요!

gsutil -mv gs://storyparks_bucket/dir_a/* gs://storyparks_bucket/dir_b/
아쉽게도 제가 로그를 따로 기록해두지는 않았습니다...

 

그리하여 wildcard를 사용하지 않고 명령어를 실행해 보았습니다.

gsutil -mv gs://storyparks_bucket/dir_a gs://storyparks_bucket/dir_b

 

하지만 위 명령어로 실행하니 다른 문제가 생겼습니다..

gs://storyparks_bucket/dir_b/dir_a

위와 같은 경로로 dir_a의 데이터들이 이동되었습니다. 구글링을 열심히 하다 보니 subdir를 생성되지 않게 하려면 "-p" 옵션을 지정해주면 된다고 합니다.

gsutil -mv -p gs://storyparks_bucket/dir_a gs://storyparks_bucket/dir_b

하지만 저는 다른 방법으로 문제를 풀었기 때문에, 위 테스트를 해보지는 못했습니다.

 

# Solution 2. cp , rm 명령어 사용

gsutil cp에서는 wildcard(*)를 지원하기 때문에 복사 후 삭제라는 아주 고전적인 방법으로 문제를 풀었습니다.

gsutil -cp -r gs://storyparks_bucket/dir_a/* gs://storyparks_bucket/dir_b/

 

이렇게 데이터를 복사한 후, dir_a의 데이터를 삭제해주는 작업으로 문제를 해결하였습니다.

 

# 추가 내용

제가 옮기려는 데이터가 워낙 대용량이라.. 병렬 처리가 필요하여 다음 gsutil 옵션을 추가하여 사용하였습니다. 

gsutil -m -cp -r gs://storyparks_bucket/dir_a/* gs://storyparks_bucket/dir_b/
 -m          Causes supported operations (acl ch, acl set, cp, mv, rm, rsync,
              and setmeta) to run in parallel. This can significantly improve
              performance if you are performing operations on a large number of
              files over a reasonably fast network connection.

              gsutil performs the specified operation using a combination of
              multi-threading and multi-processing, using a number of threads
              and processors determined by the parallel_thread_count and
              parallel_process_count values set in the boto configuration
              file. You might want to experiment with these values, as the
              best values can vary based on a number of factors, including
              network speed, number of CPUs, and available memory.

              Using the -m option may make your performance worse if you
              are using a slower network, such as the typical network speeds
              offered by non-business home network plans. It can also make
              your performance worse for cases that perform all operations
              locally (e.g., gsutil rsync, where both source and destination
              URLs are on the local disk), because it can "thrash" your local
              disk.

              If a download or upload operation using parallel transfer fails
              before the entire transfer is complete (e.g. failing after 300 of
              1000 files have been transferred), you will need to restart the
              entire transfer.

              Also, although most commands will normally fail upon encountering
              an error when the -m flag is disabled, all commands will
              continue to try all operations when -m is enabled with multiple
              threads or processes, and the number of failed operations (if any)
              will be reported as an exception at the end of the command's
              execution.

 

# 참고

Google Cloud gsutil mv 명령어 문서

 

mv - Move/rename objects  |  Cloud Storage  |  Google Cloud

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trade

cloud.google.com

 

반응형

'Computer & Data > Cloud Platform' 카테고리의 다른 글

GCP. Dataproc 간단한 리뷰  (0) 2022.05.19
AWS SNS & AWS Athena  (0) 2019.08.14
AWS Glue 실전  (0) 2019.08.13
GCP; App Engine  (0) 2019.05.30
GCP; Cloud Pub/Sub  (0) 2019.05.23