A small command-line utility to rotate a file or directory.
Follows a specified schedule passed as a commandline argument and purges old rotations.
I've seen a number scripts written to perform backups implement file rotation in diverse ways, often without tests to verify their behaviour.
To avoid reinventing the wheel each time, it occurred to me that it would be useful to have a utility that does the one job of rotating a file or directory. I couldn't find any existing utility that compiles to a binary to fulfill that task, so I wrote this one.
./rotate -help
Usage: ./rotate <source> <target>
-schedule="1d:7,1w:5,1m:12,1y:4": rotation schedule and retention period
-verbose=false: verbose output
-version=false: prints current version
This example shows the first rotation of a directory named source
using the default schedule and retention policy.
$ tree source
source
├── fileA
├── fileB
├── dirA
└── dirB
$ rotate source target
$ tree target
target
├── 1d
│ └── 2015-08-15
│ ├── fileA
│ ├── fileB
│ ├── dirA
│ └── dirB
├── 1m
│ └── 2015-08-15
│ ├── fileA
│ ├── fileB
│ ├── dirA
│ └── dirB
├── 1w
│ └── 2015-08-15
│ ├── fileA
│ ├── fileB
│ ├── dirA
│ └── dirB
└── 1y
└── 2015-08-15
├── fileA
├── fileB
├── dirA
└── dirB