GithubHelp home page GithubHelp logo

alphanodes / ansible-backup Goto Github PK

View Code? Open in Web Editor NEW
28.0 8.0 5.0 90 KB

Ansible daily backup role

Home Page: https://galaxy.ansible.com/AlphaNodes/backup

License: GNU General Public License v3.0

Jinja 100.00%
backup mysql-backup postgresql-backup daily-backups ansible-role files backup-rotation

ansible-backup's Introduction

Ansible Role: Backup

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

Backup rotation is configurable, e.g. you can use Grandfather-father-son

Ansible Galaxy

Dependencies

none

Installation

Ansible 2+

Using ansible galaxy cli:

ansible-galaxy install alphanodes.backup

Role Variables

Available variables are listed below, along with default values (see defaults/main.yml):

backup_dir: /srv/backups

Directory for backups. Make sure there is enough disk space at this disk partition. Use quotes to make sure there are no converting problem (e.g. with to_nice_yaml)

backup_dir_mode: '0755'

Directory permission for backup_dir

backup_dir_owner: root

Directory owner for backup_dir

backup_dir_group: root

Directory group for backup_dir

backup_max_days: 7

Amount of days for daily backup sets. This means only backup_max_days set (days) are stored. Older sets are deleted automatically. Values has to be => 1.

backup_max_weeks: 1

Amount of weeks for weekly backup sets. This means only backup_max_weeks set (weeks) are stored. Older sets are deleted automatically. Values has to be => 1. The weekly backup is created every first day of the week. At this day only this backup is created (and no daily backup - because this would be duplicate).

backup_max_months: 1

Amount of weeks for weekly backup sets. This means only backup_max_months set (months) are stored. Older sets are deleted automatically. Values has to be => 1. The monthly backup is created every first day of the month. At this day only this backup is created (and no daily or weekly backup - because this would be duplicate).

backup_remote_host: ''

Hostname to sync backups for backup_remote_transfer usage.

backup_remote_port: ''

Port to sync backups for backup_remote_transfer usage.

backup_remote_dir: ''

Remote directory of for backup_remote_host for backup_remote_transfer usage.

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

These file are excluded of sync to remote host. This is only used if backup_remote_transfer is rsync.

backup_rsync_options: '-avz --delete'

rsync options for backup_remote_transfer with rsync.

backup_remote_transfer: rsync

Type of sync. Possible values are: rsync or lftp

backup_remote_user: ''

User for remote sync. This is only used with backup_remote_transfer is lftp.

backup_remote_password: ''

Password for remote sync. This is only used with backup_remote_transfer is lftp.

backup_with_borg: ''

If backupborg should be run.

backup_db_dump_format: .sql.gz

Uncompressed SQL files (.sql) as well as bzip2 (.bz2), gzip (.gz) and xz. At the moment only used for mysql dumps.

backup_with_mysql: false

Run MySQL (MariaDB) backup dump. All databases are stored in separate files.

backup_with_postgresql: false

Run PostgreSQL backup dump. All databases are stored in separate files.

backup_with_mongodb: false

Run MongoDB backup dump. All databases are stored in a single archive file.

backup_mongodb_options: '--archive --gzip'

Options for mongodb dump.

backup_mysql_db_excludes:
  - performance_schema
  - information_schema
  - sys
backup_mysql_single_transaction: true
# backup_mysqldump_options: '--extended-insert=true --opt --single-transaction'

Custom mysql options (always sql.gz is used). If set native mysql_dump (without ansible) is used. Default this is not set.

backup_postgresqldump_options: "--no-owner -Fc"

PostgreSQL dump options.

backup_create_hashfiles: false

Create hash files of all backup sets.

backup_files_unsafe_writes: false

If backup_files_unsafe_writes is yes and changed files are found while creating tar files, no error are reported. tar runs with the additional options --warning=no-file-removed --warning=no-file-changed --warning=no-file-ignored. This option can be overwritten for each set with unsafe_writes.

backup_sets: []

Backup sets for file backup. name is used as backup file name. src is the directory of file, which should be back uped. unsafe_writes overwrites backup_files_unsafe_writes. excludes is a list, which can be used to exclude files or directories.

backup_one_per_day_limit: true

Create only one backup set per day. Existing backup sets of same day will be removed.

#sync_master: anything

If sync_master is defined, backup will be skipped. You can use it for replication environments.

backup_skip_sync_clients: true

If sync_master is defined, this means it is a sync_client.

backup_pre_commands: []

List of commands, which should be run before backup dump.

backup_post_commands: []

List of commands, which runs after backup dump has been created.

Example Playbook

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

Extendet 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

GPL Version 3

Author Information

This role was created in 2018 by AlphaNodes.

ansible-backup's People

Contributors

alexandermeindl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansible-backup's Issues

removes wrong backup archive

When i use this role for more then 1 backup scenarios, it will remove an backup from an other backup instance.

TASK [alphanodes.backup : Remove old daily files] ******************************
changed: [gitlab] => (item={'uid': 0, 'woth': False, 'mtime': 1637394339.8754258, 'inode': 51511299, 'isgid': False, 'size': 10871953292, 'roth': True, 'isuid': False, 'isreg': True, 'pw_name': 'root', 'gid': 0, 'ischr': False, 'wusr': True, 'xoth': False, 'rusr': True, 'nlink': 1, 'issock': False, 'rgrp': True, 'gr_name': 'root', 'path': '/data/backups/plex_k8s-202111200731-daily.tar.gz', 'xusr': False, 'atime': 1637393485.4575467, 'isdir': False, 'ctime': 1637394339.8754258, 'isblk': False, 'xgrp': False, 'dev': 54, 'wgrp': False, 'isfifo': False, 'mode': '0644', 'islnk': False})

Add tags for ansible-backup

Hi there, would it be possible that we could add tags for this collection so we can pin at specific versions? Thanks.

Breaking change since using community.general.archive: the functionality of excludes is different

Just wanted to let you know that the way of specifying excludes is now different, since your lib has switched to using community.general.archive. My backups were getting extremely large at one point, and I saw it was because of this.

The path and exclude_path variable from archive now take globs/wildcards so the old way of specifying paths doesn't work anymore.

Also, excluding subdirectories below the 2nd level is not possible, due to a bug i have filed here: ansible-collections/community.general#6857
This is actually not a bug, it was my failure to understand how it works. But the issue here still persists since its a breaking change.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.