#!/bin/bash # FOR cloud hosts with limited disk space - move to storage server function usage { echo "Usage: ${0} " exit 1 } echo Starting $0 $* FromHost=$(hostname -s) if [ "${FromHost}" == "" ] then usage fi ArchiveDir=${2} if [ "${ArchiveDir}" == "" ] then usage fi Days=${3} if [ "${Days}" == "" ] then Days=2 fi DateCriteria="${Days} days ago" TargeHost=cloudstore.cvtt.vpn Oldest=$(date -d "${DateCriteria}" '+%Y-%m-%d') Now=$(date '+%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 ${LogDir}" else Target="${TargetHost}:/home/cvtt/Archive/${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} ${*}