How to include file in gsutil rsync?

There's currently no "include" option for gsutil rsync.


Or you could store the list of filenames in an array and exclude that array using python's negative lookahead assertion with filenames separated by |

https://ask.fedoraproject.org/en/question/92498/include-top-directory-files-in-a-backup/

I had a similar scenario where a line by line copy of files was working out to be too long. I approached it by creating an array with a list of files by running a

gsutil ls gs://<bucket_name>/<file_construct>

Followed by creating a single variable by delimiting the array elements with a |

gsutil -m rsync -c -x "^(?!${REGEX_INV_EXCLUSION_LST}$).*'" "gs://${source}/" "${dest}/"

If you know the name of a single file you want to sync you don't even need to perform an ls like Balajee suggests. Just specify that base file name in the reverse regex:

gsutil rsync -x '(?!^myfile\.txt$)' ./directory-with-desired-file gs://my-bucket

Example here: https://github.com/GoogleCloudPlatform/gsutil/issues/532#issuecomment-394039557