Skip to content

Instantly share code, notes, and snippets.

@iusmac
Created March 9, 2019 23:37
Show Gist options
  • Save iusmac/cdc945e0a728c09d75a49d11970c37da to your computer and use it in GitHub Desktop.
Save iusmac/cdc945e0a728c09d75a49d11970c37da to your computer and use it in GitHub Desktop.
Ignore files in use (opened) while using rsync
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
}
@iusmac
Copy link
Author

iusmac commented Mar 9, 2019

Usage

lsof_rsync "/path/to/source/" "/path/to/destination"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment