-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
16 additions
and
9 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,38 @@ | ||
#!/bin/bash | ||
# Fetch files specified by path from remote site | ||
# set -x | ||
#set -x | ||
|
||
if [ ! -f "$1" ] || [ ! -f "$1" ]; then | ||
echo "Please provide host-named file with list of paths (or directory with such fiels) to rsync as command line argument." | ||
exit 1 | ||
fi | ||
|
||
host=$(basename $1) | ||
dir="./${host}_files_$(date +%Y-%m-%d)" | ||
dir="./${host}_files_$(date +%Y-%m-%d_%H-%M)" | ||
|
||
mkdir -p "${dir}/tree/" | ||
rm -f "${dir}/_paths.txt" | ||
mkdir -p "${dir}/_meta/" | ||
rm -f "${dir}/_meta/paths.txt" | ||
|
||
rsync -azh --files-from="$1" "${host}":/ "${dir}/tree/" | ||
|
||
function safecp() { | ||
idx=2 # set the copy index to 0 | ||
dfn=${file##*/} # destination file name (dfn) w/path stripped | ||
while [ -f "${dir}/${dfn}" ]; do # test if $dfn exist in output_dir | ||
dfn=${file##*/}_$((idx++)) # if so, add copy index "_#" (increment until unique) | ||
idx=1 # set the copy index to 1 | ||
fn="${file##*/}" # destination file name (dfn) w/path stripped | ||
dfn="$fn" | ||
|
||
while [ -f "${dir}/${dfn}" ]; do # test if $dfn exist in output_dir | ||
dfn="${fn%.*}_$((idx++)).${fn##*.}" # if so, add copy index "_#" before extenison (increment until unique) | ||
done | ||
|
||
cp "$file" "${dir}/${dfn}" | ||
echo "${dfn} - ${file}" >> "${dir}/_paths.txt" | ||
echo "${dfn} - ${file}" >> "${dir}/_meta/paths.txt" | ||
} | ||
|
||
while read -d '' file; do | ||
safecp </dev/null | ||
done < <(find "${dir}/tree/" -type f -print0) | ||
|
||
rm -rf "${dir}/tree/" | ||
|
||
mv "$1" "${dir}"/_meta/"$host" |