backup-rotate manual page
Name
backup-rotate - delete oldest files from a setSynopsis
backup-rotate [-p] [-v] [-d days] [-n nfiles] prefix...Description
The backup-rotate script deletes oldest of the files having the same prefix, while keeping files which are below a simple threshold: age in days, number of files, or both. See OPTIONS below.
The current version of backup-rotate uses find(1) to locate the files to consider for deletion, so it does not suffer from the limitation of maximum parameters as with shell expansion.
Each prefix given as an argument is a set of files which is considered for deletion, independent of each other.
Options
- -p
- Pretend only. Do not actually delete any files. May be useful for testing, best if combined with the -v option.
- -v
- Be verbose. Print the name of every file which is being deleted.
- -d days
- Only delete files older than days days. Note that "older than
0 days" means at least a day old - use a negative value to allow
today's files to be deleted.
Default: 180 (or the $defdays variable defined in the script if modified) - -n nfiles
- Regardless of their age, only delete files so that at least the newest
nfiles are left.
Default: 6 (or the $defnfiles variable defined in the script if modified) - prefix
- Prefix of the group of files to delete from. An implicit * is
appended to the end of this prefix and fed to the find(1) program. If
you want to delete all old non-dot files in a directory, use an explicit slash
(/) at the end.
Each prefix given as an argument is a set of files considered for deletion independently.
Examples
- backup-rotate -v /var/recordings/
- Delete all non-dot files in /var/recordings older than 180 days but leave at least 6 most recent ones.
- backup-rotate -d 10 -n 0 /tmp/phpsess-
- Delete all /tmp/phpsess-* files older than 10 days.
- backup-rotate -d 4 -n 5 /var/log/messages. /var/log/syslog.
- Delete the oldest /var/log/messages.* files, only keep 5 of them. Also delete the oldest /var/log/syslog.* files, only keep 5 of them. Do NOT delete any files which are not older than 4 days.
- backup-rotate -d -1 -n 1 /var/backups/
- Delete all non-dot files in /var/backups except the most recent one.
Environment
The backup-rotate script resets the PATH environment variable to
- PATH=/usr/local/bin:/usr/bin:/bin
Therefore, the required tools find(1), sed(1),
rm(1), sort(1) have to be in that search path. This is useful
when running from cron where PATH might have been unset, and
also for security reasons.
You may alter this behavior by editing or removing the PATH= line in the
backup-rotate script.
Known Bugs
File names matching the prefix must not contain the newline character (\n). This could not be dealt with using standard versions of the tools run from the script.
Version
This man page documents backup-rotate, version 1.8.
Author
Written by Matej Sustr.
Copyright
Copyright (c) 2006-2011, Matej Sustr
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See Also
find(1), rm(1)