Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better backup task schedule #269

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,11 @@ and schedule types, please refer to [the specific section in the repo wiki](http
### 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_backup_dir_create: true
nexus_restore_log: '{{ nexus_backup_dir }}/nexus-restore.log'
Expand All @@ -741,8 +745,13 @@ and schedule types, please refer to [the specific section in the repo wiki](http
```

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 @@ -34,7 +34,13 @@ nexus_backup_dir: '/var/nexus-backup'
nexus_backup_dir_create: true # Shall we create the dir, or do you already have something in place?
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 @@ -243,19 +243,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