Skip to content

Instantly share code, notes, and snippets.

@ianling
Last active December 9, 2015 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianling/14f5953ee89de44abf41 to your computer and use it in GitHub Desktop.
Save ianling/14f5953ee89de44abf41 to your computer and use it in GitHub Desktop.
Runs a full backup of all hosts using BackupPC
---
#first, dump all MySQL databases and move them to a folder that gets backed up by BackupPC
- hosts: mysql
tasks:
- name: Create /backup/sql recursively
file: path=/backup/sql state=directory owner=backup group=backup mode=0766 recurse=yes
- name: Dump all MySQL databases, where applicable
shell: "/usr/bin/mysqldump --all-databases > /backup/sql/mysql.sql"
#do the same for PostgreSQL databases
- hosts: postgres
tasks:
- name: Create /backup/sql recursively
file: path=/backup/sql state=directory owner=backup group=backup mode=0766 recurse=yes
- name: Dump all PostgreSQL databases, where applicable
become: yes
become_user: postgres
command: /usr/bin/pg_dumpall -f /tmp/backuppc_postgres_full_dump.sql
- name: Set permissions and owner on SQL dump file
become: yes
file: path=/tmp/backuppc_postgres_full_dump.sql owner=backup group=backup mode=0700
- name: Move PostgreSQL dump to /backup/sql
command: mv /tmp/backuppc_postgres_full_dump.sql /backup/sql/postgres.sql
#Run the BackupPC backup for each host
- hosts: all
tasks:
- name: Back up the host
local_action: command /usr/share/backuppc/bin/BackupPC_dump -f {{ inventory_hostname }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment