Skip to content

Instantly share code, notes, and snippets.

@mikedemers
Created March 20, 2013 18:39
Show Gist options
  • Save mikedemers/5207277 to your computer and use it in GitHub Desktop.
Save mikedemers/5207277 to your computer and use it in GitHub Desktop.
Shell script that compresses log files and uses archiver.rb to send them to an S3 bucket. I run this from cron.
#!/bin/bash
# TODO: this needs to be updated to work with logrotate...
BUDIR="/home/mike/backup/logs"
BUCKET="APPNAME-full-logs"
ARCHIVER="/home/mike/backup/bin/archiver.rb"
GZIP="/bin/gzip"
LOGDIR="/var/www/apps/APPNAME/shared/log"
DATETAG=`date +'%Y%m%d-%H%M%S'`
ALOGBU="${BUDIR}/access-${DATETAG}.log.gz"
PLOGBU="${BUDIR}/production-${DATETAG}.log.gz"
${GZIP} < ${LOGDIR}/access.log > "${ALOGBU}"
${GZIP} < ${LOGDIR}/production.log > "${PLOGBU}"
${ARCHIVER} "${BUCKET}" "${ALOGBU}"
${ARCHIVER} "${BUCKET}" "${PLOGBU}"
rm "${ALOGBU}"
rm "${PLOGBU}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment