Skip to content

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Archive CleanUp Tool 🚮

A lightweight, efficient Bash CLI utility designed to automate the cleanup of old backup archives. This tool scans the backup directory passed by the user, identifies compressed .tar.gz files older than 30 days, deletes them to save disk space, and maintains a detailed log history of all actions.

✨ Features

  • Smart Cleanup: Automatically targets files with the .tar.gz extension.
  • Time-Based Rotation: Only removes archives older than 30 days (mtime +30).
  • Automated Logging: Maintains archive-logs-history.log within the target directory for audit trails.
  • Safety Checks: Validates directory existence and input arguments before execution.
  • Global Access: Designed to run as a system-wide command.

🚀 Installation

To use this tool globally from any directory, follow these steps:

  1. Clone the script:

    git clone https://github.com/2Kelvin/archives-cleanup.git
    
  2. Change into the directory

    cd archives-cleanup
    
  3. Make the script executable

    chmod +x cleanup-tool
  4. Move script to global bin: Move the script to /usr/local/bin to ensure it is available in your system $PATH.

    sudo mv cleanup-tool /usr/local/bin/cleanup-tool

🛠 Usage

Because this tool is installed in a protected system directory and often manages backups in restricted folders, it should be executed with root privileges or from a user with sudo.

To run the tool globally, use:

sudo cleanup-tool /path/to/your/backups

Example

If you have backups stored in /var/backups/my-logs-backup-folder, simply run:

sudo cleanup-tool /var/backups/my-logs-backup-folder
Screenshot 2026-02-04 083318

🤖 Automation Ready

This utility is designed for headless execution and is perfect for scheduled system maintenance. Since it is installed in /usr/local/bin, it can be easily integrated into your preferred scheduling engine; systemmd timers or cron jobs.

📝 Logging System

The tool maintains a continuous audit trail by creating or updating a log file named archive-logs-history.log directly within your target directory.

What is tracked:

  • Timestamps: Precise records of when the cleanup was initiated.
  • Deletion Manifest: A specific list of every .tar.gz filename removed during the session.
  • Status Reports: Clear confirmation of "Success" or specific error codes if the process fails.

Sample Log Entry:

cat /path/to/your/archive-logs-history.log
Screenshot 2026-02-04 084649

About

Bash script to clean up old backed up archives inorder to save space

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages