Git Product home page Git Product logo

log_man's Introduction

logman.py

Overview

This Python script is designed for managing log files in a robust and efficient manner. It facilitates log rotation, archiving of old log files, and offers an option to transfer archived logs to a remote server using SCP (Secure Copy Protocol). The script is versatile and can be configured for different environments and requirements.

Features

Log Rotation: Manages the size of log files, rotating them once they reach a specified size.

Archiving: Compresses and archives old log files, freeing up space while keeping historical data.

SCP Transfer: Option to securely transfer archived logs to a remote server for centralized storage or backup.

Flexible Configuration: Can be easily configured to handle different log file patterns, sizes, and backup strategies.

Dry Run Mode: Simulates actions without making actual changes, useful for testing configurations.

Requirements

Python 3 Paramiko (for SCP functionality) Installation Ensure Python 3 is installed on your system. Install Paramiko using pip: pip install paramiko

Usage

The script is executed from the command line with various arguments to specify its behavior:

python logman.py --log-dir <path_to_log_directory> --log-pattern <log_file_pattern> --archive-dir <path_to_archive_directory> --max-log-size <max_log_file_size> --backup-count <number_of_backups> [--dry-run] [--scp-transfer] [--remote-host <hostname>] [--remote-path <remote_path>] [--ssh-user <username>] [--ssh-password <password>]
Arguments
--log-dir: Directory containing the log files.
--log-pattern: Regex pattern to match log files for rotation.
--archive-dir: Directory to store archived logs.
--max-log-size: Maximum size of a log file before it's rotated (e.g., 5M, 10G).
--backup-count: Number of backup files to keep.
--dry-run: Simulate actions without making any changes.
--scp-transfer: Enable SCP transfer of archived files.
--remote-host: Hostname or IP of the remote server (required if --scp-transfer is used).
--remote-path: Remote path for the SCP transfer (required if --scp-transfer is used).
--ssh-user: SSH username for the remote server (required if --scp-transfer is used).
--ssh-password: SSH password for the remote server (required if --scp-transfer is used).
Logging
The script includes an internal logging system for monitoring its operations and troubleshooting.

Examples

Rotate and archive logs in /var/logs, keeping a maximum file size of 5MB and up to 3 backups:

python logman.py --log-dir /var/logs --log-pattern ".*\.log" --archive-dir /var/archive --max-log-size 5M --backup-count 3

Rotate, archive, and transfer logs to a remote server:

python logman.py --log-dir /var/logs --log-pattern ".*\.log" --archive-dir /var/archive --max-log-size 5M --backup-count 3 --scp-transfer --remote-host 192.168.1.100 --remote-path /remote/archive --ssh-user user --ssh-password pass

log_man's People

Contributors

slejdops avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.