Project from roadmap.sh
This project provides a simple command-line tool to archive logs on a set schedule. The tool compresses the logs and stores them in a new directory, which is useful for keeping the system clean while preserving logs in a compressed format for future reference.
The tool is designed to be run from the command line, accepts the log directory as an argument, and compresses the logs into .tar.gz files. The archive filenames are timestamped, and a log event is created each time the tool is executed.
- The tool should accept the log directory as an argument.
- It should compress the logs in a
.tar.gzfile. - The compressed file should be stored in a new directory,
archived_logs. - The tool should log the date and time of the archive creation to a file.
To use the tool, run the following command:
log-archive <log-directory>For example, to archive logs from the /var/log directory, run:
log-archive /var/logThe tool will compress the logs and store them in a new directory called archived_logs, with a filename like:
logs_archive_20240816_100648.tar.gz
Additionally, a log entry will be created in the archive_log.txt file in the archived_logs directory with the timestamp and archive filename.
- Log Compression: The tool compresses the logs using the
.tar.gzformat. - Timestamped Archives: Each archive is named with the current timestamp (e.g.,
logs_archive_20240816_100648.tar.gz). - Event Logging: The tool logs the date and time of the archive creation in
archive_log.txt.
This tool can also be deployed in a Docker container for easy scheduling and execution.
-
Clone this repository.
-
Build the Docker image:
docker-compose build
-
Run the container in detached mode:
docker-compose up -d
-
The tool will run daily at 03:00 AM, and the logs will be archived in the
archived_logsdirectory mounted from your host machine.
The archived_logs directory on your local machine will store all the archived logs. The Docker container mounts this directory as a volume, so you can easily access the logs generated by the tool.
ls ./archived_logsYou can also view the logs of the cron job inside the container:
docker logs log-archiveThis project is licensed under the MIT License - see the LICENSE file for details.