Google Certified Associate Cloud Engineer 2020

Sign Up Free or Log In to participate!

copy between buckets

How can we make sure that the folder structure is also preserved when we copy between buckets?

The gsutil cp -r option doesn’t work.

1 Answers

Hmmm… I’m interested to know more about what you’re doing, because the -R option has definitely worked for me.  It copies recursively and preserves the hierarchy as it does so.

It’s a quick-and-dirty script, but you can run this in your Cloud Shell to make a test hierarchy of directories and files and upload it recursively to a bucket:


#!/bin/bash

mkdir ~/hierarchy

cd ~/hierarchy/

mkdir 001

mkdir 002

mkdir 003

cd 001

mkdir a

mkdir b

mkdir c

cd a

touch aaa

echo Hello>bbb

echo Lalalalalalalalalalalalala>ccc

cp * ../b

cp * ../c

cd ..

cd ..

cp -R 001/* 002/

cp -R 001/* 003/

cd ..

gsutil cp -R ~/hierarchy gs://mytestbucket/
Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?