alphanodes.backup

Ansible Role: Backup

This role performs daily, weekly, and monthly backups for files, MySQL databases, and PostgreSQL databases on Debian and Ubuntu servers.

You can customize the backup rotation, for instance, by using the Grandfather-father-son scheme.

Ansible Galaxy

Dependencies

  • None

Installation

For Ansible 2+

Use the Ansible Galaxy command line tool:

ansible-galaxy install alphanodes.backup

Role Variables

Here are the available variables with their default values (found in defaults/main.yml):

backup_dir: /srv/backups

This sets the directory for backups. Ensure there is enough disk space in this partition. Use quotes to avoid any issues with spaces.

backup_dir_mode: '0755'

This specifies the permissions for the backup_dir.

backup_dir_owner: root

This sets the owner of the backup_dir.

backup_dir_group: root

This specifies the group for the backup_dir.

backup_max_days: 7

This is the number of days for daily backups. Only backups from the last backup_max_days days will be kept. Older backups will be deleted automatically. The value must be at least 1.

backup_max_weeks: 1

This sets the number of weeks for weekly backups. Only backups from the last backup_max_weeks weeks will be kept. Older backups will be deleted automatically. The value must be at least 1. The weekly backup is created on the first day of the week.

backup_max_months: 1

This defines the number of months for monthly backups. Only backups from the last backup_max_months months will be kept. Older backups will be deleted automatically. The value must be at least 1. The monthly backup is created on the first day of the month.

backup_remote_host: ''

This is the hostname to sync backups for remote transfers.

backup_remote_port: ''

This sets the port for remote transfers.

backup_remote_dir: ''

This specifies the remote directory for remote transfers.

backup_remote_excludes:
  - '*.journal'
  - '.nfs*'
  - '*.tar'

These files will be excluded from syncing to the remote host when using rsync.

backup_rsync_options: '-avz --delete'

These are the rsync options for remote transfers.

backup_remote_transfer: rsync

This defines the type of sync. Possible options are: rsync or lftp.

backup_remote_user: ''

This specifies the user for remote sync when lftp is used.

backup_remote_password: ''

This is the password for remote sync when lftp is used.

backup_with_borg: ''

Set this if you want to run BackupBorg.

backup_db_dump_format: .sql.gz

This specifies the format for uncompressed SQL files, which includes .sql, .bz2, .gz, and .xz. Currently, it's only used for MySQL dumps.

backup_with_mysql: false

Set this to run a MySQL (MariaDB) backup dump. Each database will be stored in separate files.

backup_with_postgresql: false

Set this to run a PostgreSQL backup dump. Each database will be stored in separate files.

backup_with_mongodb: false

Set this to run a MongoDB backup dump. All databases will be stored in a single archive file.

backup_mongodb_options: '--archive --gzip'

These are options for the MongoDB dump.

backup_mysql_db_excludes:
  - performance_schema
  - information_schema
  - sys

This defines the databases to exclude from MySQL backups.

backup_mysql_single_transaction: true
# backup_mysqldump_options: '--extended-insert=true --opt --single-transaction'

This allows for custom MySQL options (note that sql.gz is always used). By default, this option is not set.

backup_postgresqldump_options: "--no-owner -Fc"

These are options for PostgreSQL dumps.

backup_create_hashfiles: false

This specifies whether to create hash files for all backup sets.

backup_files_unsafe_writes: false

If this is set to true and changed files are found while creating tar files, no errors will be reported. Tar will run with additional options to suppress warnings.

backup_sets: []

This defines the backup sets for file backups. Each set has a name for the backup file name, src for the source directory that should be backed up, and unsafe_writes can override the default setting. excludes is for listing files or directories to exclude.

backup_one_per_day_limit: true

This limits backups to one set per day. Any existing backups from the same day will be removed.

#sync_master: anything

If sync_master is defined, backups will be skipped. This is useful for replication environments.

backup_skip_sync_clients: true

If sync_master is defined, this indicates it is a sync client.

backup_pre_commands: []

This allows you to list commands to run before the backup dump.

backup_post_commands: []

This allows you to list commands to run after the backup dump is created.

Example Playbook

- hosts: server-name
  vars:
    backup_sets:
      - name: etc
        src: /etc
  roles:
    - alphanodes.backup

Extended Example Playbook

- hosts: server-name
  vars:
    backup_max_days: 14
    backup_max_weeks: 4
    backup_max_months: 6
    backup_with_postgresql: true
    backup_dir_mode: '0770'
    backup_dir_group: postgres
    backup_sets:
      - name: etc
        src: /etc
      - name: jenkins
        src: /var/lib/jenkins
        unsafe_writes: true
        excludes:
          - builds
          - workspace
  roles:
    - alphanodes.backup

License

This role is licensed under GPL Version 3.

Author Information

This role was created in 2018 by AlphaNodes.

Informazioni sul progetto

Run daily backups for files, MySQL databases and PostgreSQL databases

Installa
ansible-galaxy install alphanodes.backup
Licenza
gpl-3.0
Download
9.4k
Proprietario
Professional Services with Open Source