mLog Version
Version : 0.0.6
Release Date : 12-Feb-22
What is mlog ?
mlog is small script to manage your application logs like nginx, apache, tomcat, laravel, or any other application. it will help you to take backup of your logs file on periodically and will upload in target s3 bucket. it is fully safe and automated. you can use this tool with fully trust and without any data loss.
Dependancy
- aws cli - you need to install and configure aws cli to upload logs in s3 bucket.
Notes:
- it is recommended to run this script as root. it required root privilage to compress logs and write in log directory
/var/log/mlog
.
Step 1: Install Script.
sudo curl -sL "https://github.com/HarryTheDevOpsGuy/mlog/raw/master/$(uname -p)/mlog" -o /usr/bin/mlog
sudo chmod +x /usr/bin/mlog
# Verify installation
mlog --version
Getting Start with help
## mlog -h
mlog [OPTION] src s3
-X, --delete Delete older than 10 days (e.g. -X 30-40)
-v, --verbose Enable verbose output (include multiple times for more
verbosity, e.g. -vvv)
-u, --s3upload disable to upload backup on s3 (default: true)
-h, --help display this help
-V, --version display version
example
#mlog [OPTIONS] "source/file/pattern*.gz" "/other/source/logs/application-*.log" "s3://target-bucket/folder"
mlog /var/log/nginx/access.log-$(date --date='1 days ago' +'%Y-%m-%d').gz s3://mylog-bucket/logs
example 2
if we want to push last 10 days logs in s3 bucket. We can use mlog within for loop.
export LOGDAY=$i
Don’t forget to use this variable.
#mlog [OPTIONS] "source/file/pattern*.gz" "/other/source/logs/application-*.log" "s3://target-bucket/folder"
for (( i = 1; i < 10; i++ )); do
export LOGDAY=$i
mlog /var/log/tomcat-app*/app*.log.$(date --date="$i days ago" +'%Y-%m-%d')* s3://mylog-bucket/logs
done
s3 log path
all log file will upload in below format and destination in your s3 bucket.
${S3_BUCKET_PATH}/${HOST_IP}/${APP_NAME}/${YEAR}/${MONTH}/${TODAY}/${DST_FILE_NAME}
s3://bucketName/your_dir/172.31.16.2/nginx/2021/01/2021-01-29/access.log-2021-01-29
s3://bucketName/your_dir/172.31.16.2/nginx/2021/01/2021-01-29/error.log-2021-01-29
NEXTExamples