inital
This commit is contained in:
commit
bea5ae340a
83
archive_logs.sh
Executable file
83
archive_logs.sh
Executable file
@ -0,0 +1,83 @@
|
||||
#!/bin/bash
|
||||
|
||||
function usage {
|
||||
echo -n "Usage: ${0}"
|
||||
echo -n " -L <log directory>"
|
||||
echo -n " [ -A <archive_logs_dir> (default /works/archive/logs)]"
|
||||
echo -n " [-D <older than time criteria> (default: '2 days ago')]"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo Starting $0 $*
|
||||
|
||||
LogDir=${1}
|
||||
LogArchiveDir=/works/archive/logs
|
||||
DateCriteria="2 days ago"
|
||||
|
||||
|
||||
# ---------------- cmdline
|
||||
while getopts "A:L:D:" opt; do
|
||||
case ${opt} in
|
||||
A )
|
||||
LogArchiveDir=$OPTARG
|
||||
;;
|
||||
L )
|
||||
LogDir=$OPTARG
|
||||
;;
|
||||
D )
|
||||
DateCriteria=$OPTARG
|
||||
;;
|
||||
\? )
|
||||
echo "Invalid option: -$OPTARG" >&2
|
||||
usage
|
||||
;;
|
||||
: )
|
||||
echo "Option -$OPTARG requires an argument." >&2
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
# ---------------- cmdline
|
||||
|
||||
|
||||
if [ "${LogDir}" == "" ]
|
||||
then
|
||||
usage
|
||||
fi
|
||||
|
||||
Cmd="mkdir -p ${LogArchiveDir}"
|
||||
echo ${Cmd} && eval ${Cmd}
|
||||
|
||||
echo "Looking for log files older than '${DateCriteria}' in ${LogDir}"
|
||||
|
||||
Oldest=$(date -d "${DateCriteria}" '+%Y-%m-%d %H:%M:%S')
|
||||
|
||||
Cmd="find ${LogDir}/ '(' -name '*.log' -o -name '*.log.*' ')' -type f -not -newermt \"${Oldest}\""
|
||||
echo $Cmd
|
||||
|
||||
files=$(eval ${Cmd})
|
||||
if [ "$files" == "" ]
|
||||
then
|
||||
echo "No files found older than ${Oldest} in ${LogDir}"
|
||||
else
|
||||
echo Archiving files:
|
||||
echo -----------------
|
||||
echo ${files}
|
||||
|
||||
oldest_file=$(ls -t ${files} | tail -1)
|
||||
youngest_file=$(ls -tr ${files} | tail -1)
|
||||
|
||||
tstmp1=$(stat --printf '%y' ${oldest_file})
|
||||
tstmp2=$(stat --printf '%y' ${youngest_file})
|
||||
tmsig="$(date -d "${tstmp1}" +"%Y%m%d_%H%M%S")-$(date -d "${tstmp2}" +"%Y%m%d_%H%M%S")"
|
||||
echo $tmsig
|
||||
|
||||
Cmd="tar zcvf ${LogArchiveDir}/${tmsig}.logs.tgz ${files}"
|
||||
echo $Cmd
|
||||
eval $Cmd
|
||||
|
||||
rm $files
|
||||
fi
|
||||
echo Done ${0} ${*}
|
||||
|
||||
91
move_archives.sh
Executable file
91
move_archives.sh
Executable file
@ -0,0 +1,91 @@
|
||||
#!/bin/bash
|
||||
# FOR hosts with limited disk space - move to storage server
|
||||
|
||||
function usage {
|
||||
echo -n "Usage: ${0}"
|
||||
echo -n " -H <host_label>"
|
||||
echo -n " [ -A <archive_dir> (default /works/archive)]"
|
||||
echo -n " [-D <older than time criteria> (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
|
||||
|
||||
TargetHost=cloud21.cvtt.vpn
|
||||
TargetRootDir=/opt/store/cvtt/archive
|
||||
|
||||
Oldest=$(date -d "${DateCriteria}" '+%Y-%m-%d %H:%M:%S')
|
||||
|
||||
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" == "" ]
|
||||
then
|
||||
echo "No files found older than ${Oldest} in ${ArchiveDir}"
|
||||
else
|
||||
Target="${TargetHost}:${TargetRootDir}/${FromHost}/"
|
||||
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
|
||||
echo Done ${0} ${*}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user