Skip to content

Instantly share code, notes, and snippets.

@rojenzaman
Created June 16, 2021 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rojenzaman/9d077bdc091a7467879eed6928f875ad to your computer and use it in GitHub Desktop.
Save rojenzaman/9d077bdc091a7467879eed6928f875ad to your computer and use it in GitHub Desktop.
Compress NGINX logs as ZSTANDART.
#!/bin/bash
# Run with find command:
#
# find /var/log/nginx -name "*.log" -exec /usr/bin/log2zst "{}" \;
#
if [ "$#" -lt 1 ]; then
echo "Usage: `basename $0` <filename>"
exit 1
fi
zstd --rm -c "$1" > "$1-`date +%Y%m%d`.zst"
touch $1
@rojenzaman
Copy link
Author

log2zst.service

[Unit]
Description=Compress NGINX logs as ZSTANDART.
Wants=log2zst.timer

[Service]
User=root
CPUWeight=40
CPUQuota=40%
IOWeight=40
ExecStart=/usr/bin/find /var/log/nginx -name "*.log" -exec /usr/bin/log2zst "{}" \;

[Install]
WantedBy=multi-user.target

log2zst.timer

[Unit]
Description=Compress NGINX logs as ZSTANDART.
Wants=log2zst.service

[Timer]
Unit=log2zst.service
OnCalendar=weekly

[Install]
WantedBy=timers.target

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment