Skip to content

Instantly share code, notes, and snippets.

@tskrynnyk
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save tskrynnyk/6cd51e6a623dcc87e30f to your computer and use it in GitHub Desktop.

Select an option

Save tskrynnyk/6cd51e6a623dcc87e30f to your computer and use it in GitHub Desktop.
#! /bin/bash
#
LC_ALL=C
#DIR_SRC=/var/www/squid-reports
DIR_SRC=/mnt/arch/squid-reports
DIR_DSC=/mnt/arch/squid-reports
# ------------------------------------------------------------------------------
# Daily
cd ${DIR_SRC}/daily
for y in 2011; do
for m in $(seq -w 12); do
my=$(date --date="$y-$m-01" +%b%Y)
for d in `ls -d *${my}-* 2>/dev/null`; do
if [ -d "$d" ]; then
DIR_BACKUP="${DIR_DSC}/${y}/Daily/Daily-${my}"
[ -d "${DIR_BACKUP}" ] || mkdir -p $DIR_BACKUP
mv -v $d $DIR_BACKUP
fi
done
cd ${DIR_DSC}/${y}/Daily
for i in `ls -d */ 2>/dev/null`; do
if [ -d "$i" ]; then
DIR=`basename $i /`
echo $DIR
(tar cf - $DIR | bzip2 -f > "$DIR.tar.bz2") && rm -rf $DIR
fi
done
cd - 1>/dev/null
done
done
# ------------------------------------------------------------------------------
# Weekly
# ------------------------------------------------------------------------------
# Monthly
# EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment