Skip to main content

Overview

The backup definition is a YAML file that describes the structure of your backups. In it, you provide the information that backmon needs to collect metric data, purge files, and offer file downloads.

backmon looks for the backup definition file called backup_definitions.yaml at the root directory of your disk. You can overwrite the file naming in the backmon configuration file.

Sample backup_definitions.yaml file

# use directory ./databases as the the root directory. You can have multiple directories in each YAML file. 
# use '.' if the definitions file is in the same directory as your backups.
'./databases/{{client}}':
# alias is used for Prometheus metrics
alias: DB
# assign variables
fuse:
- 'client'
# apply those defaults to all files.* sections. You can override each parameter in the files.* section
defaults:
# expect that a backup file is generated at 00:30 each night
schedule: 30 0 * * *
# for identifying the newest file, we use the `born_at` field
sort: born_at
# purge old files which are older than 7 days and keep at least 10 backups
purge: true

# @see https://github.com/dreitier/backmon/issues/19
# retention-count: 10
# retention-age: 7d
# inside the ./databases folder there are multiple files like `postgres-20220713.gz`
files:
'postgres-%Y%M%D.gz':
# File alias for Prometheus
alias: PostgeSQL
# This backup is generated at 01:00 each night
schedule: 0 1 * * *
retention-count: 10
retention-age: 7d
'%Y%M%D_mysql_%I.gz':
alias: MySQL

Available configuration keys

KeyDefaultRequiredDescription
[$directory]<empty> (string)YesDirectory name inside the disk, relative to the backup_definitions.yaml.
[$directory].alias<name of directory> (string)NoUsed alias when exporting metrics.
[$directory].fuse[]<empty> (list of wildcard strings)NoGroup files together by that substitutions.
[$directory].defaults.*<empty> (any of .schedule, .sort, .purge)NoApply those defaults for each [$directory].files[$file] section. Each [$directory].files[$file].* key can override this default.

(.retention-count, .retention-age) are not available, see #19.
[$directory].files[$file]<empty> (map)YesFile pattern to check for.
[$directory].files[$file].schedule<empty> (valid cron definition)NoCron definition to check for files
[$directory].files[$file].sortinterpolation (one of born_at, modified_at, archived_at or interpolation)NoUsed data to sort the files. The selected method uses the given field to sort the files and find the latest/newest one. In case of interpolation, the variable substitution is applied
[$directory].files[$file].purge<empty> (bool)NoPurges each file which does not match retention-age or retention-count. If purge is set to true, without having an explicit retention, a limit von 14 days is assumed.
[$directory].files[$file].retention-count<empty> (int)NoKeep max number of files
[$directory].files[$file].retention-age<empty> (duration)NoKeep files newer than that
[$directory].files[$file].alias<name of file> (string)NoUsed alias when exporting metrics.

[$directory]

The root elements for each backup_definitions.yaml are the names of the subdirectories in a disk.

Location of backup directories

Backups in the same directory

When backups are in the same directory with the backup_definitions.yaml, you have to use . or ./ as root element:

- backup_definitions.yaml
- backup1.tar.gz
- backup2.tar.gz

Backups in subdirectories

- backup_definitions.yaml
+ /backup-1/
- backup1.tar.gz
- backup2.tar.gz
+ /backup-2/
- backup1.tar.gz
- backup2.tar.gz

Patterns

Pattern variables

A variable can be put on a directory pattern by using two curly braces (e.g. {{variable}}). For variable names only characters 0-9, A-Z, a-z, and _ are allowed. Please note that you should not override the variables names from the substituions.

Variables can be referenced later on in a file pattern with help of ${variable}.

Pattern substitutions

See substituions.

[$directory].alias

If specified, the label dir for the epxorted Prometheues metrics will be overwritten with the given alias.

Without .alias

'./backups':
files:
'dump-%Y%M%D.sql':

With .alias specified

'./backups':
alias: "custom_backups"
files:
'dump-%Y%M%D.sql':

[$directory].fuse

Sometimes you need to group files together which belong logically to the same backup set but are split across different directories.

Let's group together the following backup `.sql` files:
backups/2022/01/postgres/some_subdir
- 20220101.sql
backups/2022/02/postgres/some_subdir
- 20220201.sql
backups/2022/03/postgres/some_subdir
- 20220301.sql

[$directory].defaults.*

If you want to use the same configuration over multiple [$directory].files[$file] sections, you can use .defaults. With .defaults you can apply the configuration keys

  • .schedule
  • .sort
  • .purge

as defaults for each [$directory].files[$file].* section. You can can override the default key value in each [$directory].files[$file] section.

The two settings

  • .retention-count
  • .retention-age

are not available, see #19.

[$directory].files[$file]

Each [$directory].files[$file] key supports so called substitutions. They are basically simplified regular expressions. Some of those substitutions like '%Y' and '%M' are used to update the file's `interpolated_timestamp'.

backups-1/
- dump-20220401.sql
- dump-20220501.sql
- dump-20220601.sql
- dump-20220701.sql

[$directory].files[$file].schedule

Put in your crontab definition for when the backup should occur.

[$directory].files[$file].sort

With help of .sort you can define which of the backup file's fields is used for sorting. Sorting is used for finding the latest/newest files (relevant for the /api/download endpoint) and oldest files (relevant for purging).

KeyTimestamp usedDefault
born_atborn_at-
modified_atmodified_at-
archived_atarchived_at-
interpolationinterpolated timestamp

If you are not using .stat / dotstat files, interpolation is used.

[$directory].files[$file].purge

If set to true, files which are older than retention-age and over the number of retention-count are deleted.

[$directory].files[$file].retention-count

If .purge is set to true, at least a number of .retention-count files are kept, even if they are older than .retention-age.

[$directory].files[$file].retention-age

If .purge is set to true, files older then .retention-age are purged. Pleas note that at least a number of .retention-count files is kept. .sort is used to calculate if a given file is older than .retention-age from today.

[$directory].files[$file].alias

If specified, the label file for the epxorted Prometheues metrics will be overwritten with the given alias.

Without .alias

'./backups':
files:
'dump-%Y%M%D.sql':

With .alias specified

'./backups':
files:
'dump-%Y%M%D.sql':
alias: "pg-dump"