Skip to content

Instantly share code, notes, and snippets.

@DmitriyLyalyuev
Created April 23, 2021 08:51
Show Gist options
  • Save DmitriyLyalyuev/940877ab56de1497b339af61c74ad2f2 to your computer and use it in GitHub Desktop.
Save DmitriyLyalyuev/940877ab56de1497b339af61c74ad2f2 to your computer and use it in GitHub Desktop.
#!/bin/bash
## Start and end months
MONTHS='1 2 3 4'
YEAR='2021'
### Downloading logs
echo "Making logs directory..."
mkdir -p logs && echo "...Success"
for i in ${MONTHS}; do
if [[ $i -lt 10 ]]; then
i="0${i}"
fi
for day in {1..31}; do
if [[ $day -lt 10 ]]; then
day="0${day}"
fi
echo "Dowloading logs from " s3://managebac-ca-prod-logs/${YEAR}${i}${day}/ "..."
list=`aws s3 ls --recursive s3://managebac-ca-prod-logs/${YEAR}${i}${day}/ | awk '{print $4}' | grep lograge_production.log`
count=1
for x in $list; do
mkdir -p logs/${YEAR}${i}${day}/${count}
aws s3 cp s3://managebac-ca-prod-logs/${x} logs/${YEAR}${i}${day}/${count}/
if [ -f logs/${YEAR}${i}${day}/${count}/lograge_production.log.tar.gz ]; then
cd logs/${YEAR}${i}${day}/${count}
echo "Unpacking archive..."
tar -vxzf lograge_production.log.tar.gz
mv ./srv/managebac/shared/log/* ./
rm -f lograge_production.log.tar.gz
rm -rf ./srv
cd -
fi
((count=count+1))
done
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment