Bash - Rotate Log w/AWS S3 Backup

timestamp=`date +%Y%m%d` # goto log location cd /path/to/logs printf "\nArchiving custom log...\n\n" # the log filename log=custom.log # the archive filename nlog=$log.$timestamp.log # copy the data sudo cp $log $nlog # archive log sudo gzip -f -9 $nlog printf "\n\t Archive of "$nlog" complete.\n" # refs the_log=$log the_log_archive=$nlog.gz # copy to AWS S3 Bucket aws s3 cp $the_log_archive s3://bucket-name/folder/for/backups/ # empty the old log sudo truncate -s0 $the_log
Creates a compressed log file, empties the original and copies the archive to an AWS S3 Bucket folder.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.