11

Ansible seems to be a pretty efficient automation tool to deploy and to update applications on servers.

  • Is it possible to use it to backup a (Linux) server as well? Is it a good practice to do so?

  • If yes, is there any module/example on how to do it? For example, let's say I want to create an export of a database and copy it on another machine, how to automate this task with Ansible?

2 Answers 2

10

It is possible to backup server using Ansible. I'm new user of Ansible so I'm not sure if it is a good practice or not.

If you want to backup databases you can use mysql_db module.

tasks:
  - name: backup db server
    mysql_db: name={{item}} state=dump target=/{{item}}-{{ansible_date_time.iso8601}}.sql
    with_items: db_name

then you can use fetch or synchronize module for transferring those files to local machine. With fetch module it is not possible to download multiple files as it doesn't support wildcard characters and folder download. Creating one tar file is an option to overcome this problem.

You can also use scp to download backup files from remote instance.

- name: Downloading backup files from remote machine
  command: scp -i {{ansible_ssh_private_key_file}} {{remote_user}}@{{host}}:/backup/* {{backup_folder}}
  delegate_to: 127.0.0.1
1

Answering my own question, I've found the fetch module that allows to download files from the remote server: http://docs.ansible.com/ansible/fetch_module.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .