Small collection of scripts for snapshot backups of:
- files: using rsync
- MySQL/MariaDB or PostgreSQL: using default dump tools
Create new snapshot of a file system tree using rsync(1). The script creates hard links of unchanged files at the destination, thus limiting the space required more or less to the actual changes. This script was inspired by Mike Rubel's HOWTO Easy Automated Snapshot-Style Backups with Linux and Rsync.
The script allows one positional argument: a configuration file, which will be sourced and should set environment variables. This file can source other files, e.g. for global configuration.
The following option arguments can be passed:
-ior--initialcreates the initial snapshot.-vor--verboseincrease verbosity.-nor--dry-runrun a simulation, without copying any files.
The following variables need to be set (either in the configuration file or in the environment):
LIB_DIRdefines the state directory, which is used to save the timestamp of the last run.LOG_DIRis the directory for logfiles. A subdirectory with the job name will receive one file per run.BACKUP_TREEis the root of the directory tree to be snapshotted.BACKUP_FILTERis the name of a (per-directory) filter, in the format defined by rsync(1).REMOTE_BASEis the target for snapshots, in a format understood by rsync(1).TAGis the format for snapshot datestamps (i.e. name of directories created at the target), in the format used by date(1).
These variables are optional:
LOCK_DIRcan specify a directory to have lockfiles, preventing concurrent snapshot runs. Strongly recommended to set.Jobis the job name and required if no configuration file is given. If configuration file is given andJobis not manually set, it defaults to the configuration file basename.TAG_OPTIONScan contain additional options to be passed to date(1) for generating tags.REMOTE_AUTHcan be an array of additional options (passed to rsync), e.g. for authorising.
This is a systemd(1) template service file for file system snapshots. It should be instantiated with the base name of a configuration located in /etc/backup/snapshots. The file extension .conf will be appended to the instance name.
Create and store database snapshot using dump tools. The script has been tested with MariaDB and PostgreSQL tools, but could possibly work well with other systems.
The script allows one positional argument: a configuration file, which will be sourced and should set environment variables. This file can source other files, e.g. for global configuration.
The following option arguments can be passed:
-vor--verboseincrease verbosity.-nor--dry-runrun a simulation, without copying any files.
The following variables need to be set (either in the configuration file or in the environment):
DATABASESis a space-separated list of databases to be dumped.DB_DUMPis the database-specific dump command (e.g.mysqldumporpg_dump). It will be called with optionalDB_ARGSand a database name as positional argument.REMOTE_BASEis the target for snapshots, in a format understood by rsync(1). Each run will create a new directory under that target, containing one file per dumped database.TAGis the format for snapshot datestamps (i.e. name of directories created at the target), in the format used by date(1).
These variables are optional:
Jobis the job name and required if no configuration file is given. If configuration file is given andJobis not manually set, it defaults to the configuration file basename.DB_USERcan specify a user under which the dump command should be run. If specified, the dump command is run with sudo(1).DB_ARGScan be an array of additional arguments passed to the dump command.TAG_OPTIONScan contain additional options to be passed to date(1) for generating tags.REMOTE_AUTHcan be an array of additional options (passed to rsync), e.g. for authorising.
This is a systemd(1) template service file for database snapshots. It should be instantiated with the base name of a configuration located in /etc/backup/snapshots. The file extension .conf will be appended to the instance name.
Delete old snapshots