Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip existing files in gsutil rsync

I want to copy files between a directory on my local computer disk and my Google Cloud Storage bucket with the below conditions:

1) Copy all new files and folders.

2) Skip all existing files and folders irrespective of whether they have been modified or not.

I have tried to implement this using the Google ACL policy, but it doesn't seem to be working.

I am using Google Cloud Storage admin service account to copy my files to the bucket.

like image 238
Jyotsna Avatar asked May 30 '18 05:05

Jyotsna


People also ask

Does gsutil CP overwrite?

gsutil cp gs://my-bucket/*.txt . You can use the -n option to prevent overwriting the content of existing files. The following example downloads text files from a bucket without clobbering the data in your directory: gsutil cp -n gs://my-bucket/*.txt .

What does gsutil rsync do?

The gsutil rsync command copies changed files in their entirety and does not employ the rsync delta-transfer algorithm to transfer portions of a changed file. This is because Cloud Storage objects are immutable and no facility exists to read partial object checksums or perform partial replacements.

How do I transfer files from one GCS bucket to another?

To copy any single object from one GCS location to another, you can use the copy command. This can be done from either of our public APIs, or by using the command-line client, gsutil.

How do I update gsutil?

When using the Cloud SDK, use gcloud components update . The gsutil update command downloads the latest gsutil release, checks its version, and offers to let you update to it if it differs from the version you're currently running.


1 Answers

As @A.Queue commented, the solution to skip existing files would be the use of the gsutil cp command with the -n option. This option means no-clobber, so that all files and directories already present in the Cloud Storage bucket will not be overwritten, and only new files and directories will be added to the bucket.

If you run the following command:

gsutil cp -n -r . gs://[YOUR_BUCKET]

You will copy all files and directories (including the whole directory tree with all files and subdirectories underneath) that are not present in the Cloud Storage bucket, while all of those which are already present will be skipped.

You can find more information related to this command in this link.

like image 165
Rodrigo C. Avatar answered Nov 08 '22 21:11

Rodrigo C.