poa-devops/roles/backup-parity/tasks/main.yml

79 lines
2.2 KiB
YAML
Raw Normal View History

2017-12-29 05:10:57 -08:00
---
2018-01-22 06:03:46 -08:00
# initial checks
2018-01-26 11:42:01 -08:00
- name: Check that poa-netstats is running
shell: "systemctl is-active poa-netstats"
register: systemctl_poa_netstats
2018-01-26 11:47:28 -08:00
failed_when: systemctl_poa_netstats.rc not in [0,3] # neither active nor inactive
2018-01-22 06:03:46 -08:00
2018-01-26 11:42:01 -08:00
- name: Check that poa-parity is running
2018-01-22 06:03:46 -08:00
shell: "systemctl is-active poa-parity"
2018-01-26 11:42:01 -08:00
register: systemctl_poa_parity
2018-01-26 11:47:28 -08:00
failed_when: systemctl_poa_parity.rc not in [0,3] # neither active nor inactive
2018-01-22 06:03:46 -08:00
# stop services
2017-12-29 05:10:57 -08:00
- name: Shutdown poa-netstats service
service: name=poa-netstats state=stopped
2018-01-26 11:42:01 -08:00
when: systemctl_poa_netstats.rc == 0
2017-12-29 05:10:57 -08:00
- name: Shutdown poa-parity service
service: name=poa-parity state=stopped
2018-01-26 11:42:01 -08:00
when: systemctl_poa_parity.rc == 0
2017-12-29 05:10:57 -08:00
2018-01-22 06:03:46 -08:00
# make backups
2017-12-29 05:10:57 -08:00
- name: Create backup directory
file: path=/data state=directory
2018-01-22 06:03:46 -08:00
- name: Create parity_data archive
2017-12-29 05:10:57 -08:00
archive:
format: gz
2018-01-02 13:47:49 -08:00
path: /home/{{ poa_role }}/parity_data
2017-12-29 10:34:28 -08:00
dest: "/data/parity_data.tar.gz"
2018-01-22 06:03:46 -08:00
when: backup_parity_data == true
2017-12-29 05:10:57 -08:00
2018-01-22 06:03:46 -08:00
- name: Export parity blocks
shell: "cd /home/{{ poa_role }}; ./parity --config node.toml export blocks blocks.rlp"
when: backup_parity_blocks == true
- name: Create parity blocks archive
archive:
format: gz
path: /home/{{ poa_role }}/blocks.rlp
dest: "/data/parity_blocks.rlp.gz"
when: backup_parity_blocks == true
# start services
- name: Launch poa-parity service
service: name=poa-parity state=started
2018-01-26 11:42:01 -08:00
when: systemctl_poa_parity.rc == 0
2018-01-22 06:03:46 -08:00
- name: Launch poa-netstats service
service: name=poa-netstats state=started
2018-01-26 11:49:27 -08:00
when: systemctl_poa_netstats.rc == 0
2018-01-22 06:03:46 -08:00
# upload backups to s3
- name: Upload parity_data to s3
2017-12-29 05:10:57 -08:00
s3:
aws_access_key: "{{ access_key }}"
aws_secret_key: "{{ secret_key }}"
bucket: "{{ s3_bucket }}"
2018-01-22 06:03:46 -08:00
object: "/{{ date }}-{{ poa_role }}-{{ node_name }}-parity_data.tar.gz"
2017-12-29 10:34:28 -08:00
src: "/data/parity_data.tar.gz"
2017-12-29 05:10:57 -08:00
mode: put
2018-01-22 06:03:46 -08:00
when: backup_parity_data == true
2017-12-29 10:34:28 -08:00
2018-01-22 06:03:46 -08:00
- name: Upload parity blocks to s3
s3:
aws_access_key: "{{ access_key }}"
aws_secret_key: "{{ secret_key }}"
bucket: "{{ s3_bucket }}"
object: "/{{ date }}-{{ poa_role }}-{{ node_name }}-parity_blocks.rlp.gz"
src: "/data/parity_blocks.rlp.gz"
mode: put
when: backup_parity_blocks == true
# Cleanup
2017-12-29 10:34:28 -08:00
- name: Clean local backup storage
file:
state: absent
path: "/data/"