progress
This commit is contained in:
+30
-43
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
function usage {
|
function usage {
|
||||||
echo -n "Usage: ${0}"
|
echo -n "Usage: ${0}"
|
||||||
echo -n " -H <host_label>"
|
|
||||||
echo -n " [ -A <archive_dir> (default /works/archive)]"
|
echo -n " [ -A <archive_dir> (default /works/archive)]"
|
||||||
echo -n " [-D <older than time criteria> (default: '2 days ago')]"
|
echo -n " [ -T <target (default hl-storage.cvtt.vpn:/works/archive)>]"
|
||||||
|
echo -n " [ -D <older than time criteria> (default: '2 days ago')]"
|
||||||
echo
|
echo
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
@@ -16,20 +16,24 @@ echo Starting $0 $*
|
|||||||
ArchiveDir=/works/archive
|
ArchiveDir=/works/archive
|
||||||
DateCriteria="2 days ago"
|
DateCriteria="2 days ago"
|
||||||
FromHost=$(hostname -s)
|
FromHost=$(hostname -s)
|
||||||
|
TargetRoot=hl-storage.cvtt.vpn:/works/archive
|
||||||
# ---- D e f a u l t s
|
# ---- D e f a u l t s
|
||||||
|
|
||||||
# ---------------- cmdline
|
# ---------------- cmdline
|
||||||
while getopts "A:H:D:" opt; do
|
while getopts "A:T:D:h" opt; do
|
||||||
case ${opt} in
|
case ${opt} in
|
||||||
A )
|
A )
|
||||||
ArchiveDir=$OPTARG
|
ArchiveDir=$OPTARG
|
||||||
;;
|
;;
|
||||||
H )
|
T )
|
||||||
FromHost=$OPTARG
|
TargetRoot=$OPTARG
|
||||||
;;
|
;;
|
||||||
D )
|
D )
|
||||||
DateCriteria=$OPTARG
|
DateCriteria=$OPTARG
|
||||||
;;
|
;;
|
||||||
|
h )
|
||||||
|
usage
|
||||||
|
;;
|
||||||
\? )
|
\? )
|
||||||
echo "Invalid option: -$OPTARG" >&2
|
echo "Invalid option: -$OPTARG" >&2
|
||||||
usage
|
usage
|
||||||
@@ -42,50 +46,33 @@ while getopts "A:H:D:" opt; do
|
|||||||
done
|
done
|
||||||
# ---------------- cmdline
|
# ---------------- cmdline
|
||||||
|
|
||||||
|
|
||||||
if [ "${FromHost}" == "" ]
|
|
||||||
then
|
|
||||||
usage
|
|
||||||
fi
|
|
||||||
|
|
||||||
TargetHost=cloud21.cvtt.vpn
|
|
||||||
TargetRootDir=/opt/store/cvtt/archive
|
|
||||||
|
|
||||||
Oldest=$(date -d "${DateCriteria}" '+%Y-%m-%d %H:%M:%S')
|
Oldest=$(date -d "${DateCriteria}" '+%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
echo "Looking for log files older than ${DateCriteria} in ${ArchiveDir}"
|
echo "Looking for log files older than ${DateCriteria} in ${ArchiveDir}"
|
||||||
Cmd="find ${ArchiveDir}/"
|
|
||||||
Cmd="${Cmd} '('"
|
|
||||||
Cmd="${Cmd} -name '*.log'"
|
|
||||||
Cmd="${Cmd} -o -name '*.log.*'"
|
|
||||||
Cmd="${Cmd} -o -name '*.logs.*'"
|
|
||||||
Cmd="${Cmd} -o -name '*.tgz'"
|
|
||||||
Cmd="${Cmd} ')'"
|
|
||||||
Cmd="${Cmd} -type f"
|
|
||||||
Cmd="${Cmd} -not -newermt \"${Oldest}\""
|
|
||||||
|
|
||||||
echo ${Cmd}
|
|
||||||
files=$(eval ${Cmd})
|
|
||||||
|
|
||||||
if [ "$files" == "" ]
|
# 1. First, check if any matching files exist using a quick find check
|
||||||
then
|
if ! find "${ArchiveDir}" -type f -not -newermt "${Oldest}" -print -quit | grep -q .; then
|
||||||
echo "No files found older than ${Oldest} in ${ArchiveDir}"
|
echo "No files found older than ${Oldest} in ${ArchiveDir}"
|
||||||
else
|
echo "Done ${0} ${*}"
|
||||||
Target="${TargetHost}:${TargetRootDir}/${FromHost}/"
|
exit 0
|
||||||
echo "Moving files to ${Target}:"
|
|
||||||
echo -----------------
|
|
||||||
for f in ${files}
|
|
||||||
do
|
|
||||||
echo ${f}
|
|
||||||
done
|
|
||||||
|
|
||||||
Cmd="rsync -ahvv"
|
|
||||||
Cmd="${Cmd} --remove-source-files"
|
|
||||||
Cmd="${Cmd} $files"
|
|
||||||
Cmd="${Cmd} ${Target}"
|
|
||||||
echo ${Cmd}
|
|
||||||
# exit
|
|
||||||
eval ${Cmd}
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Target="${TargetRoot}/${FromHost}/"
|
||||||
|
echo "Moving files to ${Target}:"
|
||||||
|
echo "-----------------"
|
||||||
|
|
||||||
|
# 2. Safely pipe find into rsync using relative paths from the ArchiveDir base
|
||||||
|
# This completely avoids "Argument list too long" errors and handles spaces perfectly
|
||||||
|
set -x
|
||||||
|
find "${ArchiveDir}" -type f -not -newermt "${Oldest}" -printf "%P\0" | \
|
||||||
|
rsync -ahvv \
|
||||||
|
--remove-source-files \
|
||||||
|
--mkpath \
|
||||||
|
--from0 \
|
||||||
|
--files-from=- \
|
||||||
|
"${ArchiveDir}/" \
|
||||||
|
"${Target}"
|
||||||
|
{ set +x; } 2>/dev/null
|
||||||
echo Done ${0} ${*}
|
echo Done ${0} ${*}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user