Utility for creating and pruning backup directories.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2017-07-19 18:48:21 +01:00
LICENSE Initial checkin 2016-09-20 09:23:41 +01:00
prunedir Use correct DoW offset to calculate weekly keep 2017-07-19 18:48:21 +01:00
prunedir.spec Use correct DoW offset to calculate weekly keep 2017-07-19 18:48:21 +01:00
README.md add --prune-sequences option for extra deleting 2016-12-04 15:41:54 +00:00

NAME

prunedir - Creating and pruning archive/backup directories

SYNOPSIS

prunedir [options] [--new | --prune | --init ]

Options: --help brief help message --man full documentation

--dir            path to master directory

--init           initialise configuration is specified directory

--dailies n      number of dailies to keep
--weeklies n     number of Sunday backups to keep
--monthlies n    number of 1st of the month backups to keep

--new            create a time-stamped directory
--snapshot       create the directory to second resolution
--basename       output the basename rather than the fullname

--prune          prune subdirectories according to defined rules
--prune-sequences  prune sequenced subdirectories as well

OPTIONS

  • --help

    Print a brief help message and exits.

  • --man

    Prints the manual page and exits.

  • --dir directory

    Specify the directory where the prunedir configuration and sub-directories reside. Should be specified as full path for safety and clarity.

  • --init

    Initialise the specified directory for use by prunedir. The directory must exist and must not already have a prunedir configuration. This option also allows the use of --dailies, --weeklies and --monthlies options.

  • --dailies n

    Specified the number of most recent daily backup directories to keep on --prune. Defaults to 7.

  • --weeklies n

    Specified the number of most recent weekly backup directories to keep on --prune. Defaults to 5. Weekly backups are defined as those taken on Sundays.

  • --monthlies n

    Specified the number of most recent monthly backup directories to keep on --prune. Defaults to 12. Monthly backups are defined as those taken on the first of the month.

  • --new

    Create a sub-directory in the specified master directory. Print the combined pathname on standard output to allow capture by the calling program.

  • --snapshot

    Force the name of the --new subdirectory to be specified to 1 second resolution.

  • --basename

    Adjusts the output format of --new/--snapshot to output on the basename of the newly created sub-directory.

  • --prune

    Prune the day-based sub-directories according to the rules in the configuration file.

  • --prune-sequences

    If pruning the day-based sub-directories according to the rules in the configuration file include any sequenced versions as well.

DESCRIPTION

prunedir creates and prunes day-stamped directories under a specified master directory according to defined rules.

A typical use within a backup script for an application like PostgreSQL might be as follows

MASTERDIR=/var/backup/myapp
BACKUPDIR=`prunedir --new --dir "$MASTERDIR" `
pg_dump --dbname myapp --file="$BACKUPDIR/myapp.db.sql"
bzip2 "$BACKUPDIR/myapp.db.sql"
prunedir --prune --dir "$MASTERDIR"

In this context prunedir will create a new subdirectory of the format YYYYMMDD. The directory will be given the same access permissions as the master directory. After the output file is compressed prunedir is called again to prune the older subdirectories according to the rules in the configuration file in the master directory.

Prior to first use the directory should configured for use by checking the access permissions on the master directory are suitable and then by creating the configuration file

prunedir --init --directory /var/backup/myapp

prunedir can also be called to both prune and create a new sub-directory.

prunedir --new --prune --directory /var/backup/myapp

The configuration file created in the master directory is called prunedir.conf and can be edited to adjust the default configuration

# Configuration file for pruning directory /var/backup/myapp
#
# Created - 20160919223811


# Keep the following number of daily subdirectories
daily=7

# Keep the following number of weekly subdirectories
weekly=6

# Keep the following number of monthly subdirectories
monthly=13

WARNINGS

It is important to be aware that prunedir will always create a new subdirectory when required. If the requsted sort of directory already exists, be that a daily YYYYmmdd or snapshot YYYYmmddHHMMSS variaton, then prunedir will add an incrementing suffix .1, .2 until it find a name that does not exist. This ensures a unique empty directory every time.

This functionality also affects the --prune option in that --prune only deletes subdirectories of the form YYYYmmdd so any extra directories created will not be pruned.