CLI tool to archive a log directory into a timestamped tar.gz file.
Project reference: https://roadmap.sh/projects/log-archive-tool
Make the script executable:
chmod +x log-archiveRun the tool with a log directory:
./log-archive /var/log- Accepts a log directory as a command-line argument.
- Compresses the directory into
logs_archive_YYYYMMDD_HHMMSS.tar.gz. - Creates an
archives/directory in the current working directory if it does not exist. - Appends each archive event to
archives/archive_history.logwith the date and time.
archives/logs_archive_20240816_100648.tar.gz
You can schedule the script with cron. Example that runs every day at 2 AM:
0 2 * * * /path/to/log-archive /var/log