Skip to content

Commit 73ea042

Browse files
committed
doc
1 parent 23d1967 commit 73ea042

File tree

15 files changed

+203
-82
lines changed

15 files changed

+203
-82
lines changed

README.Rmd

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ an empty file in place of the original one. This is useful for log rotation.
3535
`backup()`, `backup_date()` and `backup_time()` do the same but keep the
3636
original file.
3737

38-
See the
38+
rotor also includes a few utility functions for examining backups of a
39+
file: `list_backups()`, `backup_info()`, `n_backups`, `newest_backup()`,
40+
`oldest_backup()`. See the
3941
[function reference](https://s-fleck.github.io/rotor/reference/index.html) for
40-
more details
42+
details.
4143

4244
## Installation
4345

@@ -68,6 +70,8 @@ tf <- file.path(td, "mylogfile.log")
6870
writeLines("An important message", tf)
6971
```
7072

73+
### Indexed backups
74+
7175
`backup()` makes a copy of a file and inserts an index between the filename
7276
and the file extension. The file with the index `1` is always the most recently
7377
made backup.
@@ -115,13 +119,31 @@ the `max_backups` parameter. By setting it to `0`, we delete all backups.
115119
prune_backups(tf, max_backups = 0)
116120
```
117121

118-
Besides creating backup up with an index, **rotor** can also create timestamped
119-
backups.
122+
## Timestamped backups
123+
124+
**rotor** can also create timestamped backups. `backup_date()` creates uses a
125+
Date (`yyyy-mm-dd`) timestamp, `backup_time()` uses a full datetime-stamp by
126+
default (`yyyy-mm-dd--hh-mm-ss`). The format of the timestamp can be modified
127+
with a subset of the formatting tokens understood by `strftime()` (within
128+
certain restrictions). Backups created with both functions are compatible with
129+
each other (but not with those created with `backup_index()`).
130+
120131
```{r timestamp}
121-
backup_date(tf)
122-
rotate_time(tf)
123-
list_backups(tf)
132+
# be default backup_date() only makes a backup if the last backups is younger
133+
# than 1 day, so we set `age` to -1 for this example
134+
backup_date(tf, age = -1)
135+
backup_date(tf, format = "%Y-%m", age = -1)
136+
backup_time(tf)
137+
backup_time(tf, format = "%Y-%m-%d_%H-%M-%S") # Python logging
138+
backup_time(tf, format = "%Y%m%dT%H%M%S") # ISO 8601 compatible
139+
140+
backup_info(tf)
124141
```
142+
If we examine the "timestamp" column in the example above, we see that missing
143+
date information is always interpreted as the start of the period; i.e. so
144+
`"2019-01"` is equivalent to `"2019-01-01--00--00--00"` for all intentds and
145+
purposes.
146+
125147
```{r}
126148
prune_backups(tf, max_backups = 0) # cleanup
127149
list_backups(tf)

README.md

Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ addition, they create an empty file in place of the original one. This
3030
is useful for log rotation. `backup()`, `backup_date()` and
3131
`backup_time()` do the same but keep the original file.
3232

33-
See the [function
33+
rotor also includes a few utility functions for examining backups of a
34+
file: `list_backups()`, `backup_info()`, `n_backups`, `newest_backup()`,
35+
`oldest_backup()`. See the [function
3436
reference](https://s-fleck.github.io/rotor/reference/index.html) for
35-
more details
37+
details.
3638

3739
## Installation
3840

@@ -67,6 +69,8 @@ tf <- file.path(td, "mylogfile.log")
6769
writeLines("An important message", tf)
6870
```
6971

72+
### Indexed backups
73+
7074
`backup()` makes a copy of a file and inserts an index between the
7175
filename and the file extension. The file with the index `1` is always
7276
the most recently made backup.
@@ -79,8 +83,8 @@ backup(tf, compression = TRUE)
7983

8084
# display backups of a file
8185
list_backups(tf)
82-
#> [1] "/tmp/RtmplU947x/rotor/mylogfile.1.log.zip"
83-
#> [2] "/tmp/RtmplU947x/rotor/mylogfile.2.log"
86+
#> [1] "/tmp/RtmppxEUB8/rotor/mylogfile.1.log.zip"
87+
#> [2] "/tmp/RtmppxEUB8/rotor/mylogfile.2.log"
8488
```
8589

8690
`rotate()` also backs up a file, but replaces the original file with an
@@ -89,9 +93,9 @@ empty one.
8993
``` r
9094
rotate(tf)
9195
list_backups(tf)
92-
#> [1] "/tmp/RtmplU947x/rotor/mylogfile.1.log"
93-
#> [2] "/tmp/RtmplU947x/rotor/mylogfile.2.log.zip"
94-
#> [3] "/tmp/RtmplU947x/rotor/mylogfile.3.log"
96+
#> [1] "/tmp/RtmppxEUB8/rotor/mylogfile.1.log"
97+
#> [2] "/tmp/RtmppxEUB8/rotor/mylogfile.2.log.zip"
98+
#> [3] "/tmp/RtmppxEUB8/rotor/mylogfile.3.log"
9599

96100
# the original file is now empty
97101
readLines(tf)
@@ -114,10 +118,10 @@ backup(tf, max_backups = 4)
114118
backup(tf, max_backups = 4)
115119

116120
list_backups(tf)
117-
#> [1] "/tmp/RtmplU947x/rotor/mylogfile.1.log"
118-
#> [2] "/tmp/RtmplU947x/rotor/mylogfile.2.log"
119-
#> [3] "/tmp/RtmplU947x/rotor/mylogfile.3.log"
120-
#> [4] "/tmp/RtmplU947x/rotor/mylogfile.4.log.zip"
121+
#> [1] "/tmp/RtmppxEUB8/rotor/mylogfile.1.log"
122+
#> [2] "/tmp/RtmppxEUB8/rotor/mylogfile.2.log"
123+
#> [3] "/tmp/RtmppxEUB8/rotor/mylogfile.3.log"
124+
#> [4] "/tmp/RtmppxEUB8/rotor/mylogfile.4.log.zip"
121125
```
122126

123127
We can also use `prune_backups()` to delete old backups. Other than
@@ -129,17 +133,58 @@ delete all backups.
129133
prune_backups(tf, max_backups = 0)
130134
```
131135

132-
Besides creating backup up with an index, **rotor** can also create
133-
timestamped backups.
136+
## Timestamped backups
137+
138+
**rotor** can also create timestamped backups. `backup_date()` creates
139+
uses a Date (`yyyy-mm-dd`) timestamp, `backup_time()` uses a full
140+
datetime-stamp by default (`yyyy-mm-dd--hh-mm-ss`). The format of the
141+
timestamp can be modified with a subset of the formatting tokens
142+
understood by `strftime()` (within certain restrictions). Backups
143+
created with both functions are compatible with each other (but not with
144+
those created with
145+
`backup_index()`).
134146

135147
``` r
136-
backup_date(tf)
137-
rotate_time(tf)
138-
list_backups(tf)
139-
#> [1] "/tmp/RtmplU947x/rotor/mylogfile.2019-05-28--07-51-44.log"
140-
#> [2] "/tmp/RtmplU947x/rotor/mylogfile.2019-05-28.log"
148+
# be default backup_date() only makes a backup if the last backups is younger
149+
# than 1 day, so we set `age` to -1 for this example
150+
backup_date(tf, age = -1)
151+
backup_date(tf, format = "%Y-%m", age = -1)
152+
backup_time(tf)
153+
backup_time(tf, format = "%Y-%m-%d_%H-%M-%S") # Python logging
154+
backup_time(tf, format = "%Y%m%dT%H%M%S") # ISO 8601 compatible
155+
156+
backup_info(tf)
157+
#> path
158+
#> 1 /tmp/RtmppxEUB8/rotor/mylogfile.2019-05-30_23-15-33.log
159+
#> 2 /tmp/RtmppxEUB8/rotor/mylogfile.2019-05-30--23-15-33.log
160+
#> 5 /tmp/RtmppxEUB8/rotor/mylogfile.20190530T231533.log
161+
#> 3 /tmp/RtmppxEUB8/rotor/mylogfile.2019-05-30.log
162+
#> 4 /tmp/RtmppxEUB8/rotor/mylogfile.2019-05.log
163+
#> dir name sfx ext size isdir mode
164+
#> 1 /tmp/RtmppxEUB8/rotor mylogfile 2019-05-30_23-15-33 log 26 FALSE 664
165+
#> 2 /tmp/RtmppxEUB8/rotor mylogfile 2019-05-30--23-15-33 log 26 FALSE 664
166+
#> 5 /tmp/RtmppxEUB8/rotor mylogfile 20190530T231533 log 26 FALSE 664
167+
#> 3 /tmp/RtmppxEUB8/rotor mylogfile 2019-05-30 log 26 FALSE 664
168+
#> 4 /tmp/RtmppxEUB8/rotor mylogfile 2019-05 log 26 FALSE 664
169+
#> mtime ctime atime uid gid
170+
#> 1 2019-05-30 23:15:33 2019-05-30 23:15:33 2019-05-30 23:15:33 1000 1000
171+
#> 2 2019-05-30 23:15:33 2019-05-30 23:15:33 2019-05-30 23:15:33 1000 1000
172+
#> 5 2019-05-30 23:15:33 2019-05-30 23:15:33 2019-05-30 23:15:33 1000 1000
173+
#> 3 2019-05-30 23:15:33 2019-05-30 23:15:33 2019-05-30 23:15:33 1000 1000
174+
#> 4 2019-05-30 23:15:33 2019-05-30 23:15:33 2019-05-30 23:15:33 1000 1000
175+
#> uname grname timestamp
176+
#> 1 hoelk hoelk 2019-05-30 23:15:33
177+
#> 2 hoelk hoelk 2019-05-30 23:15:33
178+
#> 5 hoelk hoelk 2019-05-30 23:15:33
179+
#> 3 hoelk hoelk 2019-05-30 00:00:00
180+
#> 4 hoelk hoelk 2019-05-01 00:00:00
141181
```
142182

183+
If we examine the “timestamp” column in the example above, we see that
184+
missing date information is always interpreted as the start of the
185+
period; i.e. so `"2019-01"` is equivalent to `"2019-01-01--00--00--00"`
186+
for all intentds and purposes.
187+
143188
``` r
144189
prune_backups(tf, max_backups = 0) # cleanup
145190
list_backups(tf)

docs/404.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/LICENSE-text.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/LICENSE.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/authors.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)