diff --git a/README.md b/README.md index 7b1841b8..722616ed 100644 --- a/README.md +++ b/README.md @@ -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' @@ -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 diff --git a/defaults/main.yml b/defaults/main.yml index 51e38740..7be00a87 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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) diff --git a/tasks/main.yml b/tasks/main.yml index f6b6e933..9ff7d1cd 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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