newtonne.backup
Ansible Role: Backup
This role installs and sets up borgmatic and borg for automating file backups and backups of MySQL and PostgreSQL databases.
Requirements
Optional requirements:
You need to have
cron
installed to automate the backup process.You must have MySQL or a compatible database to back up MySQL databases, and the same goes for PostgreSQL databases.
Role Variables
Here are the variables you can use, along with their default values (see defaults/main.yml):
Borgmatic Configuration
backup_directories: []
List of directories or individual files to back up.
backup_mysql_databases: []
List of MySQL databases to back up. More info can be found in borgmatic - database dump hooks.
backup_postgresql_databases: []
List of PostgreSQL databases to back up. More info can be found in borgmatic - database dump hooks.
backup_repositories: []
List of borg
repositories to back up to. These should be created beforehand using borg init
. You can also check the borg documentation on repository URLs.
backup_location_options: {}
backup_storage_options: {}
backup_retention_options: {}
backup_consistency_options: {}
backup_hooks_options: {}
These variables allow you to provide extra configuration for borgmatic
, such as the encryption passphrase for the borg
repository or other hook scripts/commands. See the borgmatic schema for a full list of options.
backup_hooks_globlist: hooks/*
Patterns used to find hook scripts on the control machine.
backup_hooks_directory: /etc/borgmatic/hooks
Directory where any hook scripts found will be copied.
General Settings
backup_cron_jobs
- schedule: "0 3 * * *"
# action: create
List of cron job schedules and actions to take. If no action is specified, borgmatic
will execute all tasks: prune, create, and check (see borgmatic docs - set up backups). If left blank, no crontab will be set up.
backup_cron_path: "{{ backup_borg_path | dirname }}:/usr/bin:/bin"
Sets the $PATH
value at the top of the crontab.
backup_verbosity: 0
Sets the verbosity level for running borgmatic
. See borgmatic command-line reference.
backup_user: root
The user who will run the backups and own the backup files and directories.
backup_group: root
The group that will own the backup files and directories.
backup_config_directory: /etc/borgmatic
Directory for the borgmatic
configuration file.
backup_log_file: /var/log/borgmatic.log
File where borgmatic
output will be logged.
Installation Settings
backup_borg_keyserver: hkps://keys.openpgp.org
The GPG keyserver for downloading the borg
public key.
backup_borg_gpg_fpr: 6D5BEF9ADD2075805747B70F9F88FB52FAF7B393
The fingerprint for the borg
public key. More details can be found in borg documentation - security.
backup_borg_url: https://github.com/borgbackup/borg/releases/download
URL to download the borg
binary.
backup_borg_asset: borg-linux{{ ansible_architecture [-2:] }}
Name of the borg
binary to download.
backup_borg_version: 1.1.17
Version of the borg
binary to download.
backup_borg_path: /usr/local/bin/borg
Path where the borg
binary will be installed. Note: borg
won't be installed if this file already exists.
backup_borgmatic_version: 1.5.20
Version of borgmatic
to install using pip.
backup_borgmatic_venv: /etc/borgmatic/venv
Path to the virtual environment where pip will install borgmatic
. It will be created if it does not exist.
Dependencies
None
Example Playbook
- hosts: servers
vars:
backup_directories:
- /etc/myapp
- /var/myapp
backup_repositories:
- user@host1:server_backup1
- user@host2:server_backup2
backup_storage_options:
encryption_passphrase: secretpassword
backup_retention_options:
keep_daily: 7
keep_weekly: 4
backup_cron_jobs:
- schedule: "0 2 * * *"
roles:
- { role: newtonne.backup }
License
MIT