Skip to content

Commit

Permalink
Better backup task schedule (ansible-ThoTeam#269)
Browse files Browse the repository at this point in the history
- Allow any schedule type for backup task
- Add backup task to other tasks list to create in
  same operation.
  • Loading branch information
zeitounator authored and maxdanilov committed Sep 9, 2020
1 parent 85a3e87 commit 1d0aea1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,11 @@ nexus_rut_auth_header: "CUSTOM_HEADER"
### Backups
```yaml
nexus_backup_configure: false
nexus_backup_schedule_type: cron
nexus_backup_cron: '0 0 21 * * ?' # See cron expressions definition in nexus create task gui
# nexus_backup_start_date_time: "yyyy-MM-dd'T'HH:mm:ss"
# nexus_backup_weekly_days: ['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
# nexus_backup_monthly_days: {{ range(1,32) | list + [999] }}
nexus_backup_dir: '/var/nexus-backup'
nexus_restore_log: '{{ nexus_backup_dir }}/nexus-restore.log'
nexus_backup_rotate: false
Expand All @@ -667,8 +671,13 @@ nexus_rut_auth_header: "CUSTOM_HEADER"
```

Backup will not be configured unless you switch `nexus_backup_configure: true`.
In this case, a scheduled script task will be configured in nexus to run
at interval specified by `nexus_backup_cron` (defaults to 21:00 every day).
In this case, a script task will be configured in nexus.

The script task schedule will be set as `cron` by default and runs every day at 21:00. You can define whatever
schedule you like by setting accordingly the variables `nexus_backup_schedule_type`, `nexus_backup_cron`,
`nexus_backup_start_date_time`, `nexus_backup_weekly_days` and `nexus_backup_monthly_days`. To understand
their usage depending on the type of schedule you choose, please see [Scheduled tasks](#scheduled-tasks)

See [the groovy template for this task](templates/backup.groovy.j2) for details.
This scheduled task is independent from the other `nexus_scheduled_tasks` you
declare in your playbook
Expand Down
6 changes: 6 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ nexus_max_direct_memory: "2G"
nexus_backup_dir: '/var/nexus-backup'
nexus_restore_log: '{{ nexus_backup_dir }}/nexus-restore.log'
nexus_backup_configure: false # Shall we configure backup ?
## For next schedule vars, see related schedule tasks settings
## https://github.com/ansible-ThoTeam/nexus3-oss/wiki/Scheduled-tasks-configuration#schedule-types-and-related-settings
nexus_backup_schedule_type: cron
nexus_backup_cron: "0 0 21 * * ?" # See cron expression in nexus create task GUI
# nexus_backup_start_date_time: "yyyy-MM-dd'T'HH:mm:ss"
# nexus_backup_weekly_days: ['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
# nexus_backup_monthly_days: {{ range(1,32) | list + [999] }}
nexus_backup_rotate: false # Shall we rotate backups
nexus_backup_rotate_first: false # Shall we rotate before making the current backup ?
nexus_backup_keep_rotations: 4 # Keep 4 backup rotations by default (current + last 3)
Expand Down
33 changes: 18 additions & 15 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,22 @@
capability_enabled: "{{ nexus_audit_enabled | bool }}"
capability_properties: {}

- include_tasks: create_task_each.yml
with_items: "{{ nexus_scheduled_tasks }}"
when: nexus_run_provisionning | default(true) | bool

- name: Configure nexus backup task
include_tasks: call_script.yml
vars:
script_name: create_task
args:
name: db and blobstores backup
typeId: script
cron: "{{ nexus_backup_cron }}"
taskProperties:
language: groovy
source: "{{ lookup('template', './templates/backup.groovy.j2') }}"
- name: Define backup task if backup is configured
set_fact:
_nexus_backup_task:
- name: db and blobstores backup
typeId: script
schedule_type: "{{ nexus_backup_schedule_type }}"
cron: "{{ nexus_backup_cron }}"
start_date_time: "{{ nexus_backup_start_date_time | default('') }}"
weekly_days: "{{ nexus_backup_weekly_days | default([]) }}"
monthly_days: "{{ nexus_backup_monthly_days | default([]) }}"
taskProperties:
language: groovy
source: "{{ lookup('template', './templates/backup.groovy.j2') }}"
when: nexus_backup_configure | bool

- name: Create scheduled tasks (with backup task if relevant)
include_tasks: create_task_each.yml
with_items: "{{ nexus_scheduled_tasks + _nexus_backup_task | default([]) }}"
when: nexus_run_provisionning | default(true) | bool

0 comments on commit 1d0aea1

Please sign in to comment.