How to include a file in gsutil rsync?

Gsutil rsync has an exclude option (-x), but no include option. Is there a way to include the selected file without rsyncing the entire directory? Exclusion of everything except the desired file will not work, since random files will be saved in this directory.

https://cloud.google.com/storage/docs/gsutil/commands/rsync

+6
source share
5 answers

Or you can save a list of file names in an array and exclude that array using a negative python statement with file names separated |

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

, . , ,

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

, |

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

"" gsutil rsync.

+4

rsync_include_files . rsync rsync_include_files:

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

. , , . , .

+1

@wolfv - " ?"

, , :

fx=""
while read f; do
    if ! [[ "$f" = "thefileiwanttorsync" ]]; then
        [[ ${fx} = "" ]] || fx+="|" 
        fx+="^${f}\$"
    fi
done < <(ls -1 /directory/path) 

gsutil rsync -x "${fx[@]}" /directory/path  gs://bucket/some/directory/path

@wolfv - "Excluding all files except the necessary one will not work, since random files will be saved in this directory."

I understand the first sentence, but not the second.

0
source

If you know the name of the individual file you want to sync, you don’t even need to execute ls, as Balaji suggests. Just specify this base file name in the reverse regular expression:

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

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

0
source

Source: https://habr.com/ru/post/1618738/


All Articles