Created
March 9, 2019 23:37
-
-
Save iusmac/cdc945e0a728c09d75a49d11970c37da to your computer and use it in GitHub Desktop.
Ignore files in use (opened) while using rsync
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lsof_rsync() { | |
export source_path=$1 | |
local dest_path=$2 | |
find $source_path -type f -exec bash -c \ | |
'full_path=$(sed "s,\\\,,g" <<< $(readlink -f "{}")); if ! lsof "$full_path" > /dev/null; then tmp="{}"; echo ${tmp#$source_path}; fi' \; | \ | |
tr '\n' '\0' | \ | |
rsync -avuq --delete --from0 --files-from=- $source_path $dest_path | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
lsof_rsync "/path/to/source/" "/path/to/destination"