udelarinterior.backuppc_client
BackupPC-Client Ansible Role
This role, backuppc_client
, installs and configures the client settings for BackupPC server hosts. It works alongside the backuppc_server role that configures the server, but can also handle any BackupPC server installation if the configuration is standard and Ansible has access.
It supports Debian Buster (10) and Stretch (9) for advanced configurations (like database backups), but for basic BackupPC setups, it can be used with Ubuntu or any other Debian-based systems (PR accepted).
This role and the backuppc_server role are based on the hanxhx/backuppc role.
Description
This role sets up backups for hosts in a BackupPC server. It can do the following:
- Create a Linux user on the client and set up backup configurations on the BackupPC server, which will use this user to access the client.
- Optionally upload pre_dump and post_dump scripts to the client that run before and after the Backuppc backup process.
- Optionally create a MySQL user with SELECT rights on all databases to create a dump before the backup.
- Optionally set up a script to dump a specified PostgreSQL database.
Requirements
You need to have a running BackupPC server listed in your Ansible inventory, with the name defined in the backuppc_server_name
variable.
Currently, this role only manages backups using the rsync (+ ssh) method.
Backwards Compatibility
To ensure that users can smoothly transition to this version of the role, it is compatible with the previous version's variable structure. For details, refer to the defaults/main.yml and tasks/compatibility.yml files.
Backward compatibility is expected to be removed in the next major release, so update your host variable configurations as soon as possible!
Role Variables
Each client can customize their settings by overriding global configurations from the server. For default variable definitions, see defaults/main.yml. Below are variable categories you can define.
Client Access
backuppc_client_user
: Unix user for server to connect to the client (defaultbackuppc
)backuppc_client_group
: Unix group associated with the user above (defaultbackuppc
)backuppc_client_home
: Home directory of thebackuppc_client_user
on the client
Server Configuration
backuppc_server_name
: Domain name of the BackupPC server performing the backupsbackuppc_server_user
: Unix user running BackupPC on the server (defaultbackuppc
)backuppc_server_group
: Unix group running BackupPC on the server (defaultwww-data
)backuppc_server_home
: Home directory for the BackupPC user on the server (default/var/lib/backuppc
)backuppc_server_config_dir
: Configuration files directory for BackupPC (default/etc/backuppc
)
Client Backup Configuration on the Server
These variables establish how the BackupPC server will handle backups from the client:
backuppc_backup_state
: Set to present to configure client backups, absent to remove configuration (default: present).backuppc_client
: Set to false (default true) if there's no SSH access or configuration on client host.
Backup configuration for the client in the BackupPC server is determined by:
backuppc_rsync_share_names
: List of folders to back up on the client.backuppc_include_files:
: List of folders to include in the backup.backuppc_exclude_files:
: List of folders to exclude from the backup.backuppc_xfermethod
: Optional transfer method (default rsync).backuppc_more
: Optional hash for additional parameters like backup scheduling.
Pre and post dump script execution can be configured by:
backuppc_pre_dump_script
: Path of the pre-dump script to execute before backups.backuppc_post_dump_script
: Path of the post-dump script to execute after backups.backuppc_scripts_local_dir
: Local directory path in Ansible for the scripts to be installed on the client.backuppc_scripts
: Deprecated flag to install the pre/post dump scripts.backuppc_scripts_sudo
: Flag to grant sudo access to pre and post dump scripts.backuppc_DumpPreUserCmd
/backuppc_DumpPostUserCmd
: SSH commands for executing the pre and post dump scripts.backuppc_sudoer
: Defines which commands thebackuppc_client_user
can run with sudo.
Variables for database dumps ensure backup consistency:
backuppc_db_server_type
: Defines the database type for backups (e.g., MySQL, PostgreSQL, or none).
For PostgreSQL, you need to define:
backuppc_db_to_dump_name
: The database name.backuppc_db_dump_user
: User for accessing the database.backuppc_db_dump_user_pass
: Password for the user.
For MySQL, you need to define:
backuppc_db_server_root_pass
: Root password if needed (default undefined).backuppc_db_dump_user
andbackuppc_db_dump_user_pass
: User and password for database access.
Web access settings for the client host's backups on the BackupPC web interface:
backuppc_server_web_main_user
: Main user for access (defaultbackuppc
).backuppc_server_web_other_users
: Additional user access defined as a string like "user1,user2".
MySQL Script Examples
For a MySQL backup, to dump all databases before the file backup, you can use:
- pre_dump.sh
#!/bin/bash
for DataB in `mysql -e "show databases" | grep -v Database`; do mysqldump --single-transaction $DataB > "$DataB.sql"; done
tar -czvf dump.sql.tar.gz *.sql
rm *.sql
- post_dump.sh
#!/bin/bash
rm dump.sql.tar.gz
Example Playbook
Here’s an example playbook that sets up the backup for a host named client.domain.org
, using a BackupPC server at bck-server.domain.org
:
- name: Backup client.domain.org host
hosts: client.domain.org
become: true
vars:
- backuppc_server_name: bck-server.domain.org
- backuppc_rsync_share_names:
- /etc
- /var
- /opt
roles:
- role: udelarinterior.backuppc_client
License
GPLv3
Author Information
Original role by Emilien M, enhanced by Víctor Torterola and Daniel Viñar
Install and manage BackupPC Client
ansible-galaxy install udelarinterior.backuppc_client