Skip to content

Commit

Permalink
fix how backup rotation script is transferred to the target server, m…
Browse files Browse the repository at this point in the history
…ake backup directory configurable, transfer backup.sh to the target server using provisioning scripts
  • Loading branch information
rikukissa committed Apr 29, 2024
1 parent b86db75 commit 5be1dd4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
6 changes: 4 additions & 2 deletions infrastructure/server-setup/backups.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@

- name: Copy rotate_backups.sh file to external_backup_server_user's home directory
copy:
src: infrastructure/backups/rotate_backups.sh
src: ../backups/rotate_backups.sh
dest: '{{ external_backup_server_user_home }}/rotate_backups.sh'
owner: '{{ external_backup_server_user }}'
mode: 0755
Expand All @@ -153,5 +153,7 @@
name: 'rotate backups'
minute: '0'
hour: '0'
job: 'bash {{ external_backup_server_user_home }}/rotate_backups.sh --backup_dir=/home/backup/backups --amount_to_keep={{ amount_of_backups_to_keep }} >> /var/log/opencrvs-rotate-backups.log 2>&1'
job: 'bash {{ external_backup_server_user_home }}/rotate_backups.sh --backup_dir={{ external_backup_server_remote_directory }} --amount_to_keep={{ amount_of_backups_to_keep }} >> /var/log/opencrvs-rotate-backups.log 2>&1'
state: "{{ 'present' if (amount_of_backups_to_keep) else 'absent' }}"
tags:
- backups
3 changes: 3 additions & 0 deletions infrastructure/server-setup/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ backups:
hosts:
farajaland-qa:
ansible_host: '165.22.110.53'
vars:
# @todo how many days to store backups for?
amount_of_backups_to_keep: 3
1 change: 0 additions & 1 deletion infrastructure/server-setup/qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ all:
additional_keys_for_provisioning_user:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDk15q1EI7FXqX9sgSpO7u89ZjcZV00k2yyq/9YNLk2XWHE54qPhOdaPPgJyuIhgDGQB20uDow/E8mIkPHNstX/Gp0GXn06L7fd/BfwFmFWi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Uhkpot7+fehIQo2qhq1I9wbTsD137JsOgZFYl93X1zE51G4eaHXtNNx7v9Sga/4dlOkQoxDkypw3fL2pR44xqJip+vE374aWYDrxa5NN64M1vt1bZqSvwyRyntbBL0P/oi2X30mO8I2pUDc0LZLzUeIqrVYiQc6CS+KB0kIHlAxQQdtPP4DC0AaRdyv5GTJ7+lF4urDjfj7YlZppX+t9n6qvQdqzjfvnQ== runner@fv-az982-41
amount_of_backups_to_keep: 3
docker-manager-first:
hosts:
farajaland-qa:
Expand Down
3 changes: 3 additions & 0 deletions infrastructure/server-setup/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ backups:
hosts:
farajaland-qa:
ansible_host: '165.22.110.53'
vars:
# @todo how many days to store backups for?
amount_of_backups_to_keep: 3
9 changes: 8 additions & 1 deletion infrastructure/server-setup/tasks/backups/crontab.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
- name: Copy backups.sh file to external_backup_server_user's home directory
copy:
src: ../backups/backup.sh
dest: '{{ crontab_user_home }}/backup.sh'
owner: 'root'
mode: 0755

- name: 'Setup crontab to backup the opencrvs data'
cron:
user: '{{ crontab_user }}'
name: 'backup opencrvs'
minute: '0'
hour: '0'
job: 'cd / && bash /opt/opencrvs/infrastructure/backups/backup.sh --passphrase={{ backup_encryption_passphrase }} --ssh_user={{ external_backup_server_user }} --ssh_host={{ external_backup_server_ip }} --ssh_port={{ external_backup_server_ssh_port }} --remote_dir={{ external_backup_server_remote_directory }} --replicas=1 >> /var/log/opencrvs-backup.log 2>&1'
job: 'bash {{ crontab_user_home }}/backup.sh --passphrase={{ backup_encryption_passphrase }} --ssh_user={{ external_backup_server_user }} --ssh_host={{ external_backup_server_ip }} --ssh_port={{ external_backup_server_ssh_port }} --remote_dir={{ external_backup_server_remote_directory }} --replicas=1 >> /var/log/opencrvs-backup.log 2>&1'
state: "{{ 'present' if (external_backup_server_ip is defined and backup_encryption_passphrase and (enable_backups | default(false))) else 'absent' }}"

##
Expand Down

0 comments on commit 5be1dd4

Please sign in to comment.