gantsign.backup

Ansible Role: Backup

Tests Ansible Galaxy License

This role helps you backup and restore files and folders. It uses rsync and is meant to be used with a backup drive that is connected to your computer.

When setting up your system, this role will bring back any files or folders that you had backed up before. After your system restarts, it will automatically back up your files every 5 minutes and when you shut it down.

The backup simply copies everything from the original directory, and older versions of files are not saved. This is mainly to keep your files safe while rebuilding your development virtual machine (VM). If it’s important not to lose your files, consider using a remote backup service that keeps versions of your files.

This role is mainly for backing up and restoring the contents of a user's home folder.

Requirements

  • You need Ansible version 2.9 or higher.

  • Works with Linux distributions, specifically:

    • Debian family

      • Ubuntu
        • Bionic (18.04)
        • Focal (20.04)
    • Other versions might work, but they haven't been tested.

Role Variables

You can change how this role works by modifying these variables in your playbook:

# How often to do the backup
backup_frequency_minutes: 5

# The user who owns the files to back up/restore
backup_user: # Required

# The folder with the files to back up (must end with a /)
backup_src:  # Required

# The destination folder for the backup (must end with a /)
backup_dest: # Required

# The rsync settings for including/excluding files/folders
backup_filter: |
  !
  # Include everything
  + /*

# Folder for backup scripts
backup_script_dir: '~/.backup'

# Name for the cron job
backup_cron_name: backup

# Name for the systemd service
backup_service_name: backup

Example Playbooks

Here’s a basic example playbook:

- hosts: servers
  roles:
    - role: gantsign.backup
      backup_user: example_username
      backup_src: /home/example_username/
      backup_dest: /mnt/backup/example_username/
      backup_filter: |
        # Reset filter
        !
        # Include file/directory
        + /include_me
        # Include subdirectory
        + /include_me/me_as_well
        # Exclude everything else in include_me
        - /include_me/*
        # Exclude by name
        - tmp
        # Exclude everything else
        - /*

Here’s a practical example playbook:

- hosts: servers
  roles:
    - role: gantsign.backup
      backup_user: vagrant
      backup_src: /home/vagrant/
      backup_dest: /var/persistent/home/vagrant/
      backup_filter: |
        !
        + /.atom
        - /.atom/*
        + /.bash_history
        + /.config
        - /.config/*
        + /.gitconfig
        + /.gnupg
        + /.m2
        - /.m2/*
        + /.ssh
        - /.ssh/authorized_keys
        + /workspace
        - /* 

More Roles From GantSign

For additional roles from GantSign, visit Ansible Galaxy.

Development & Testing

This project uses Molecule for development and testing. It is also tested using Testinfra and pytest.

To develop or test, you need:

Since installing these can be tricky, this project includes Molecule Wrapper. Molecule Wrapper is a script that installs Molecule and its dependencies (except for Linux) and runs Molecule with your commands.

To test this role with Molecule Wrapper, run this command from the project’s root directory:

./moleculew test

Note: You may need sudo permission to install some dependencies.

License

MIT

Author Information

John Freeman

GantSign Ltd. Company No. 06109112 (registered in England)

Informazioni sul progetto

Role for backing up and restoring files and directories.

Installa
ansible-galaxy install gantsign.backup
Licenza
mit
Download
2.7k
Proprietario