diff --git a/utils/archive_logs.sh b/utils/archive_logs.sh index 574ceeb..3bb4c33 100755 --- a/utils/archive_logs.sh +++ b/utils/archive_logs.sh @@ -11,9 +11,10 @@ function usage { echo Starting $0 $* -LogDir=${1} +# ---- D e f a u l t s LogArchiveDir=/works/archive/logs DateCriteria="2 days ago" +# ---- D e f a u l t s # ---------------- cmdline diff --git a/utils/move_archives.sh b/utils/move_archives.sh index 1c1c4ef..2162886 100755 --- a/utils/move_archives.sh +++ b/utils/move_archives.sh @@ -1,40 +1,57 @@ #!/bin/bash - -# FOR cloud hosts with limited disk space - move to storage server +# FOR hosts with limited disk space - move to storage server function usage { - echo "Usage: ${0} " + echo -n "Usage: ${0}" + echo -n " -H " + echo -n " [ -A (default /works/archive)]" + echo -n " [-D (default: '2 days ago')]" + echo exit 1 } echo Starting $0 $* - +# ---- D e f a u l t s +ArchiveDir=/works/archive +DateCriteria="2 days ago" FromHost=$(hostname -s) +# ---- D e f a u l t s + +# ---------------- cmdline +while getopts "A:H:D:" opt; do + case ${opt} in + A ) + ArchiveDir=$OPTARG + ;; + H ) + FromHost=$OPTARG + ;; + D ) + DateCriteria=$OPTARG + ;; + \? ) + echo "Invalid option: -$OPTARG" >&2 + usage + ;; + : ) + echo "Option -$OPTARG requires an argument." >&2 + usage + ;; + esac +done +# ---------------- cmdline + + if [ "${FromHost}" == "" ] then usage fi -ArchiveDir=${2} -if [ "${ArchiveDir}" == "" ] -then - usage -fi - -Days=${3} -if [ "${Days}" == "" ] -then - Days=2 -fi - -DateCriteria="${Days} days ago" - TargetHost=cloud21.cvtt.vpn TargetRootDir=/opt/store/cvtt/archive -Oldest=$(date -d "${DateCriteria}" '+%Y-%m-%d') -Now=$(date '+%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}" Cmd="find ${ArchiveDir}/" @@ -45,7 +62,7 @@ Cmd="${Cmd} -o -name '*.logs.*'" Cmd="${Cmd} -o -name '*.tgz'" Cmd="${Cmd} ')'" Cmd="${Cmd} -type f" -Cmd="${Cmd} -not -newermt ${Oldest}" +Cmd="${Cmd} -not -newermt \"${Oldest}\"" echo ${Cmd} files=$(eval ${Cmd})