This project provides a Bash script designed to archive log files from a specified directory. The script compresses log files, generates a timestamped archive, and moves it to a designated backup directory. It’s an excellent tool for anyone looking to automate log management in a Linux environment.
- Archives all files in a specified log directory.
- Creates a timestamped archive with a
.tar.gzformat for easy storage. - Moves the archive to a
log_backupsfolder. - Logs each archiving action with a timestamp in
archive_log.txtfor tracking.
- Bash (should be available on most Linux and macOS systems)
- tar command (pre-installed on most Linux and macOS systems)
First, clone this repository to your local machine:
git clone https://github.com/your-username/log-archiver-script.git
cd log-archiver-scriptEnsure the script is executable:
chmod +x archive_logs.shRun the script, specifying the path to the directory where your log files are stored:
./archive_logs.sh /path/to/log-directoryReplace /path/to/log-directory with the actual directory containing the logs you wish to archive.
For example, to archive logs from the /var/log directory:
./archive_logs.sh /var/logThis will archive all files in the /var/log directory, create a backup in the log_backups folder, and log the action in archive_log.txt.