Project Repository: https://github.com/Premkrishnavp887/Log-Archive-Tool
This project is a command-line tool that archives logs by compressing them into .tar.gz files and storing them in a separate directory.
It is useful for managing system logs by reducing disk usage while preserving historical logs for future reference. This project demonstrates working with files, directories, and building a simple CLI-based automation tool in Bash.
The tool must:
- Run from the command line
- Accept a log directory as an argument
- Compress logs into a
.tar.gzarchive - Store the archive in a separate directory
- Log the date and time of each archive operation
- Accepts any log directory as input
- Compresses logs into
.tar.gzformat - Uses timestamp-based naming for archives
- Stores archives in a dedicated directory
- Maintains a log file with archive history
- Linux/Unix-based system
- Bash shell
tarutility
git clone https://github.com/Premkrishnavp887/Log-Archive-Tool.git
cd Log-Archive-Toolchmod +x log-archive.shsudo mv log-archive.sh /usr/local/bin/log-archiveRun the tool by providing the log directory as an argument:
log-archive <log-directory>Example:
log-archive /var/log- Archives are stored in:
~/log-archives/
- Example archive file:
logs_archive_20240816_100648.tar.gz
Each archive operation is recorded in:
~/log-archives/archive.log
Example entry:
[Fri Aug 16 10:06:48 IST 2024] Archived /var/log -> /home/user/log-archives/logs_archive_20240816_100648.tar.gz
You can automate the script using cron.
Open crontab:
crontab -eRun daily at midnight:
0 0 * * * log-archive /var/log- Email notifications after archiving
- Upload archives to remote servers or cloud storage
- Automatic deletion of old archives
- Support for configurable archive locations
- Integration with monitoring tools
- System log maintenance
- Disk space management
- Backup automation
- DevOps and system administration tasks
MIT License
Prem Krishna https://roadmap.sh/projects/log-archive-tool