Use case – auto-syncing folders
A really common use case is keeping data in sync between the persistent disk of a VM and a specific GCS location, or two GCS locations. The gsutil rsync
function is what we need here.
The source and destination URLs can either be a cloud storage bucket or a local directory. So, for example, if you want to sync data between two buckets, you can simply use the following:
gsutil rsync gs://loonycorn-bucket-00 loonycorn-bucket-01
Note
Careful on the order of the arguments! If you reverse source and destination with a -d
argument, all of your updates will be deleted forever unless you have an archival enabled. The rsync
command makes the destination match the source. So rsyncing with an empty source directory makes the destination directory also empty.
It is also possible to specify various additional optional arguments, as follows:
gsutil rsync [-VARIABLE ARGUMENT] src_url dst_urlVARIABLE ARGUMENTS (OPTIONAL):-a = also copies ACL channel-c = computes checksum-C = copies...