{"id":21698618,"url":"https://github.com/theohbrothers/log-rotate","last_synced_at":"2025-07-12T18:38:47.570Z","repository":{"id":40250063,"uuid":"113959402","full_name":"theohbrothers/Log-Rotate","owner":"theohbrothers","description":"A replica of the logrotate utility, except this also runs on Windows systems.","archived":false,"fork":false,"pushed_at":"2025-02-13T11:23:15.000Z","size":225,"stargazers_count":43,"open_issues_count":3,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T12:49:43.949Z","etag":null,"topics":["log","log-administration","log-management","log-rotation","logrotate","logs","module","powershell","pwsh"],"latest_commit_sha":null,"homepage":"","language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/theohbrothers.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-12-12T07:44:00.000Z","updated_at":"2025-04-10T15:32:54.000Z","dependencies_parsed_at":"2024-03-16T11:36:36.158Z","dependency_job_id":"c6b3c648-0288-4323-baa2-7a1d7ed12a0b","html_url":"https://github.com/theohbrothers/Log-Rotate","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/theohbrothers/Log-Rotate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theohbrothers%2FLog-Rotate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theohbrothers%2FLog-Rotate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theohbrothers%2FLog-Rotate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theohbrothers%2FLog-Rotate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theohbrothers","download_url":"https://codeload.github.com/theohbrothers/Log-Rotate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theohbrothers%2FLog-Rotate/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260299950,"owners_count":22988671,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["log","log-administration","log-management","log-rotation","logrotate","logs","module","powershell","pwsh"],"created_at":"2024-11-25T19:35:33.298Z","updated_at":"2025-06-17T05:36:13.308Z","avatar_url":"https://github.com/theohbrothers.png","language":"PowerShell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Log-Rotate\n\n[![github-actions](https://github.com/theohbrothers/Log-Rotate/actions/workflows/ci-master-pr.yml/badge.svg?branch=master)](https://github.com/theohbrothers/Log-Rotate/actions/workflows/ci-master-pr.yml)\n[![github-release](https://img.shields.io/github/v/release/theohbrothers/Log-Rotate?style=flat-square)](https://github.com/theohbrothers/Log-Rotate/releases/)\n[![powershell-gallery-release](https://img.shields.io/powershellgallery/v/Log-Rotate?logo=powershell\u0026logoColor=white\u0026label=PSGallery\u0026labelColor=\u0026style=flat-square)](https://www.powershellgallery.com/packages/Log-Rotate/)\n\nA replica of the [logrotate utility](https://github.com/logrotate/logrotate \"logrotate utility\"), except this also runs on Windows systems.\n\n## Install\n\nOpen [`powershell`](https://docs.microsoft.com/en-us/powershell/scripting/windows-powershell/install/installing-windows-powershell?view=powershell-5.1) or [`pwsh`](https://github.com/powershell/powershell#-powershell) and type:\n\n```powershell\nInstall-Module -Name Log-Rotate -Repository PSGallery -Scope CurrentUser -Verbose\n```\n\nIf prompted to trust the repository, hit `Y` and `enter`.\n\n## Log-Rotate vs `logrotate`\n\nLog-Rotate is an independent port of `logrotate`. It's made to work exactly the same way as the original `logrotate`, except it works in Powershell and especially Windows.\n\n- Same command line\n- Same config file format, meaning you can re-use your `*nix` configs\n- Same rotation logic\n- Runs on Powershell or Powershell core.\n\nWho should use it?\n\n- Anyone with a `Windows` environment where `docker` is unavailable\n- Anyone who misses that `logrotate` on `*nix`\n- Anyone working with `Windows` and have trouble with managing tons of log files from various applications\n- Anyone who works a lot in `Powershell` automation, and love the fact you can pipe configs into a module.\n- Anyone who wants to perform a *one-time rotation*, but doesn't like that `logrotate` only accepts configs as a file and not just a string.\n\n## Usage\n\n### Windows\n\n```powershell\nImport-Module Log-Rotate\n\n# Define your config\n# Double-quotes necessary only if there are spaces in the path\n$config = @'\n\"C:\\inetpub\\logs\\access.log\" {\n    rotate 365\n    size 10M\n    postrotate\n        # My shell is powershell\n        Write-Host \"Rotated $( $Args[1] )\"\n    endscript\n}\n'@\n\n# Decide on a Log-Rotate state file that will be created by Log-Rotate\n$state = 'C:\\var\\Log-Rotate\\Log-Rotate.status'\n\n# To check rotation logic without rotating files, use the -WhatIf switch (implies -Verbose)\n$config | Log-Rotate -State $state -WhatIf\n\n# You can either Pipe the config\n$config | Log-Rotate -State $state -Verbose\n\n# Or use the full Command\nLog-Rotate -ConfigAsString $config -State $state -Verbose\n```\n\n### *nix\n\n```powershell\nImport-Module Log-Rotate\n\n# Define your config\n# Double-quotes necessary only if there are spaces in the path\n$config = @'\n\"/var/log/httpd/access.log\" {\n    rotate 365\n    size 10M\n    postrotate\n        # My shell is sh\n        /usr/bin/killall -HUP httpd\n        echo \"Rotated ${1}\"\n    endscript\n}\n'@\n\n# Decide on a Log-Rotate state file that will be created by Log-Rotate\n$state = '/var/lib/Log-Rotate/Log-Rotate.status'\n\n# To check rotation logic without rotating files, use the -WhatIf switch (implies -Verbose)\n$config | Log-Rotate -State $state -WhatIf\n\n# You can either Pipe the config\n$config | Log-Rotate -State $state -Verbose\n\n# Or use the full Command\nLog-Rotate -ConfigAsString $config -State $state -Verbose\n```\n\n## Usage as a Scheduled Task or Cron job\n\n### Windows Scheduled Task\n\nA main config `C:\\configs\\Log-Rotate\\Log-Rotate.conf`:\n\n```txt\ninclude C:\\configs\\Log-Rotate.d\\\n```\n\nConfig files in `C:\\configs\\Log-Rotate.d\\`:\n\n```txt\nC:\\configs\\logrotate.d\\\n+-- iis.conf\n+-- apache.conf\n+-- minecraftserver.conf\n```\n\nDecide on a state file `C:\\var\\Log-Rotate\\Log-Rotate.status`.\n\nRun the command with `-WhatIf` to simulate the rotation, making sure everything is working.\n\n```powershell\nImport-Module Log-Rotate; Log-Rotate -Config C:\\configs\\Log-Rotate\\Log-Rotate.conf -State C:\\var\\Log-Rotate\\Log-Rotate.status -Verbose -WhatIf\n```\n\nDecide on a log file  `C:\\logs\\Log-Rotate.log`.\n\nScheduled Task Command line:\n\n```powershell\n# Powershell\npowershell -Command 'Import-Module Log-Rotate; Log-Rotate -Config C:\\configs\\Log-Rotate\\Log-Rotate.conf -State C:\\var\\Log-Rotate\\Log-Rotate.status -Verbose' \u003e\u003e C:\\logs\\Log-Rotate.log\n# pwsh\npwsh -Command 'Import-Module Log-Rotate; Log-Rotate -Config C:\\configs\\Log-Rotate\\Log-Rotate.conf -State C:\\var\\Log-Rotate\\Log-Rotate.status -Verbose' \u003e\u003e C:\\logs\\Log-Rotate.log\n```\n\n#### *nix cron\n\nA Main config `/etc/Log-Rotate.conf`, with a single `include` line :\n\n```txt\ninclude /etc/Log-Rotate.d/\n```\n\nConfig files in `/etc/Log-Rotate.d/`:\n\n```txt\n/etc/Log-Rotate.d/\n+-- nginx.conf\n+-- apache.conf\n+-- syslog.conf\n```\n\nDecide on a state file `/var/lib/Log-Rotate/Log-Rotate.status`.\n\nRun the command with `-WhatIf` to simulate the rotation, making sure everything is working.\n\n```powershell\npwsh -Command 'Import-Module Log-Rotate; Log-Rotate -Config /etc/Log-Rotate.conf -State /var/lib/Log-Rotate/Log-Rotate.status -Verbose -WhatIf'\n```\n\nDecide on a log file `/var/log/Log-Rotate.log`.\n\nCron command line:\n\n```powershell\npwsh -Command 'Import-Module Log-Rotate; Log-Rotate -Config /etc/Log-Rotate.conf -State /var/lib/Log-Rotate/Log-Rotate.status -Verbose' \u003e\u003e /var/log/Log-Rotate.log\n```\n\n## Configuration\n\n### State\n\nIf `-State` is unspecified, by default a `Log-Rotate.status` state file is created in the working directory.\n\n### Configuration Options\n\nThe following discusses how to use certain config options.\n\n|  Option  | Examples | Explanation |\n|:--------:|----------|-------------|\n| `compresscmd` | `C:\\Program Files\\7-Zip\\7z.exe`, `C:\\Program Files\\7-Zip\\7z`, `7z.exe`, `7z`, `gzip` | Best to use a **full path**. If using aliases, ensure the binary is among the `PATH` environment variable |\n| `compressoptions` | `a -t7z`, ` ` | May be blank, in which case no parameters are sent along with`compresscmd`\n\n### Missing options\n\nA few less crucial options are left out for `Log-Rotate v1`. The option and their reasons are stated below:\n\n| Option | Explanation |\n:-------:|-------------\n| `mail`, `nomail` | The `mail` option isn't used very much, because the same can be achieved with greater flexibility by adding scripts to any of the following options: `firstaction`, `lastaction`, `prerotate`, `postrotate`, `preremove` .  |\n| `su`    | The main reason for using `su` is to improve security and reduce chances of accidental renames, moves or deletions. Unlike *nix* systems, on Windows, SYSTEM and Adminitrator users cannot `runas` another user without entering their credentials. Unless those credentials are stored in `Credential Manager`, it is impossible for a high privileged daemon to perform rotation operations (E.g. creating, moving, copying, deleting) via an external shell. In the case that the `su` option is ever supported in the future because of the first reason, it would *only* work for `*nix` platforms. The other reason for using `su` is to preserve `ownership` and `Access Control Lists (ACLs)` on rotated files. This however, can easily be achieved by appying `ACLs` on *rotated files' container folders*, so that the any rotated files (E.g. created, moved, renamed) would immediately inherit those attributes.\n| `shred`, `noshred`, `shredcycles` | This option is not supported yet, because of external dependencies on Windows - `sdelete`.\n| `minage`    | unknown reason.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheohbrothers%2Flog-rotate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheohbrothers%2Flog-rotate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheohbrothers%2Flog-rotate/lists"}