How to include file in gsutil rsync?

A work around is to create a rsync_include_files directory and fill it with symlinks to files. Then rsync the rsync_include_files directory:

$GSUTIL rsync -c -C $SOURCE/rsync_include_files/
$DESTINATION/rsync_include_files/

But there is a caveat. When data is restored from backup, files are where the symlinks were, and the symlinks are lost. To complete the restoration, the files need to be moved manually and the symlinks remade.


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


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