Author: Thomas Perl <m@thp.io>
Date: 2013-04-01

# backuppurge

## Selectively purge daily full backups

Author: | Thomas Perl <m@thp.io>
Date: | 2013-04-01
Copyright: | Simplified BSD License
Version: | 1.0.2
Manual section: | 1
Manual group: | Command-line utilities

# SYNOPSIS

backuppurge [-h] [-d DAYS] [-m MONTHS] [-y YEARS] [-0] [-V] [-v] DIRECTORY

# DESCRIPTION

Lists files in that should be purged in a backup strategy where daily backups are kept for DAYS days, monthly backups for MONTHS months and yearly backups for YEARS years. Monthly and yearly backups are always the oldest possible daily backup (e.g. first of month and first of year that is available).

Files are expected to have their date embedded as `YYYY-MM-DD` somewhere in the filename, e.g. `homedir-2013-03-31.tgz`

For monthly and yearly backups, the first day available will be kept (e.g. January 1st for yearly, but if that is not available, January 2nd will be kept, etc..).

This program can be used together with xargs(1) from GNU findutils:

    backuppurge --print0 /var/backups/ | xargs -r -0 rm

Only files directly in the specified DIRECTORY will be searched (in the above example, `/var/backups/homedir-2013-03-31.tgz` will be considered, but not `/var/backups/etc/etc-2013-03-31.tgz`). This prevents accidental deletion of files.

This script assumes daily backups are FULL backups, not incremental. For example, a full daily backup of your `/etc` can be created by adding (`crontab -e`) a command like the following to your crontab(5) file:

    tar czf /var/backups/etc/etc-$(date +%F).tgz /etc

# OPTIONS

> `-h, --help` | show this help message and exit
> `-d DAYS, --days DAYS`
> | Number of days to keep
> `-m MONTHS, --months MONTHS`
> | Number of months to keep (0 to disable)
> `-y YEARS, --years YEARS`
> | Number of years to keep (0 to disable)
> `-0, --print0` | Output filenames separated by NUL (for use with xargs)
> `-V, --verbose` | Verbose output of decisions to stderr
> `-v, --version` | show version number and exit

# WEBSITE

http://thp.io/2013/backuppurge/