geerlingguy.backup

Ansible Role: Backup for Simple Servers

CI

Easily back up Linux servers using Rsync and Cron.

Requirements

You need to have these installed:

  • rsync
  • cron

If you want to back up MySQL databases, make sure you have MySQL or a compatible database installed.

You’ll need another server that can receive backup data via Rsync. On this server, install rsync and set up SSH authentication so this role can send backups to a specific folder.

Role Variables

Here are the variables you can use, along with their default values (found in defaults/main.yml):

backup_cron_job_state: present
backup_hour: "3"
backup_minute: "00"

This controls whether the backup script runs as a scheduled task. Make sure to stagger backups between servers to avoid overwhelming the backup server.

backup_user: "{{ ansible_env.SUDO_USER | default(ansible_env.USER, true) | default(ansible_user_id, true) }}"

The user account that will run the backup jobs.

backup_path: /home/{{ backup_user }}/backups

Where the backup configuration will be saved. It’s best to use a dedicated backup user account, but any account with the right access can be used.

backup_directories:
  - /home/{{ backup_user }}/domains
  - /home/{{ backup_user }}/repositories

Directories to back up. The {{ backup_user }} must have permission to read these directories. Each will be backed up separately using rsync.

backup_exclude_items:
  - .DS_Store
  - cache
  - tmp

Files or folders to exclude from the backup. Each item will be added to an excludes file for the rsync command. You can read more about excluding items here.

backup_identifier: id_here
backup_remote_connection: [email protected]

Settings for where to send the backups. Backups will be sent to a remote server via SSH. Manage SSH keys and authentication separately.

backup_remote_base_path: "~/backups"

The full path on the backup server where your backups will go (each server's backups are stored in a directory named with the backup_identifier).

backup_remote_host_name: ''
backup_remote_host_key: ''

Information about the remote host key to prevent SSH connection issues. Leave blank if you don’t use host key checking.

backup_remote_connection_ssh_options: ''

Additional SSH options (like -p [port]) can be added as needed, as detailed in the SSH command manual.

backup_mysql: false
backup_mysql_user: dbdump
backup_mysql_password: password
backup_mysql_credential_file: ''

Settings for backing up MySQL databases. Ensure the ansible_ssh_user has permissions to manage MySQL users for this to work correctly. Alternatively, you can use an existing MySQL user with backup_mysql_credential_file.

Dependencies

None.

Example Playbook

- hosts: servers

  vars:
    backup_identifier: "{{ inventory_hostname|replace('.', '') }}"
    backup_user: "backupuser"
    backup_remote_connection: [email protected]
    backup_hour: "1"
    backup_minute: "15"
    backup_mysql: false
    backup_directories:
      - /etc/myapp
      - /var/myapp/data
      - /home/myuser

  roles:
    - geerlingguy.backup

License

MIT / BSD

Author Information

This role was created in 2017 by Jeff Geerling, who wrote Ansible for DevOps.

Installa
ansible-galaxy install geerlingguy.backup
Licenza
mit
Download
17k
Proprietario
Father, author, developer, maker. Sometimes called "an inflammatory enigma". #stl #drupal #ansible #k8s #raspberrypi #crohns