1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//! # Simple utility to rotate backup files
//!
//! Typical use:
//! ```bash
//! find . -iname "*.tar" | rotate_backup rotate --output delete | xargs rm -f
//! ```
//!
//! # Providing the files
//! You can either provide files as argument or via `stdin`:
//! - `ls *.tar | rotate_backup rotate --output delete | xargs rm -f` (requires `std` feature)
//! - `rotate_backup --output delete $(ls *.tar) | xargs rm -f`
//!
//! # Selecting output
//! By default, only file to keep are shown (equivalent to `--output keep`).
//! Otherwise, you can use `--output delete`
//!
//! # Date format
//! By default, the tool looks for this format: YYYY-mm-dd, but you can select a different format:
//! `rotate_backup --format "%Y%m%d"`
//! This will parse `20240213` for instance.
//!
//! # Choosing how much logs are kept
//! The tool uses an exponential function based on days since the oldest backup.
//! This is inspired from [`frotate`](https://github.com/ip1981/frotate.rs)
//!
//! You can choose the base for the exponent: `rotate_backup --base 1.2`.
//! Note that only `base > 1.0` are accepted.
//!
//! # Debug the partitions
//! You can use the `debug` command to find out how partitions are split:
//! `rotate_backup debug --base 1.3 20`
//!
//! ```text
//! Showing 20 partitions with exponential base 1.3
//! Ranges represents the file age in days since oldest backup
//! Only 1 file is kept per partition
//! ------------------------------------------------
//! No | Start..End
//! 000| 00000..00001
//! 001| 00001..00003
//! 002| 00003..00005
//! 003| 00005..00008
//! 004| 00008..00011
//! 005| 00011..00015
//! 006| 00015..00020
//! 007| 00020..00027
//! 008| 00027..00036
//! 009| 00036..00047
//! 010| 00047..00061
//! 011| 00061..00079
//! 012| 00079..00103
//! 013| 00103..00134
//! 014| 00134..00174
//! 015| 00174..00226
//! 016| 00226..00293
//! 017| 00293..00380
//! 018| 00380..00493
//! 019| 00493..00640
//! ```
//!
extern crate alloc;
extern crate std;