From 06d9a65a20f3eee47eaaf40be0efff97a650ab97 Mon Sep 17 00:00:00 2001 From: Arthur BOUDREAULT <boudreaultarthur@ik.me> Date: Wed, 12 Jan 2022 14:43:25 +0100 Subject: [PATCH] refactor: feature is now stable + add explaination in readmes --- README-FR.md | 23 +++++++++++++++++++++++ README.md | 24 ++++++++++++++++++++++++ defaults/main.yml | 14 +++++++------- tasks/backup.yml | 24 +++++++++--------------- tasks/main.yml | 4 ++-- 5 files changed, 65 insertions(+), 24 deletions(-) diff --git a/README-FR.md b/README-FR.md index 883dcfa..ae8320e 100644 --- a/README-FR.md +++ b/README-FR.md @@ -131,6 +131,29 @@ Cette tâche utilisant le module template, vous pouvez tout à fait utiliser vos Pour `owner` et `group`, par défaut le fichier va prendre comme utilisateur propriétaire le nom de l'application et comme groupe propriétaire www-data (groupe NGINX). Vous pouvez les changer en précisant des valeurs différentes. +### Gestion des sauvegardes + +```yml +- name: Create cron task to perform YNH apps backup + ansible.builtin.cron: + name: "auto-backup apps to {{ ynh_apps_backup.directory | default('/home/yunohost.backup/archives') }}" + month: "{{ ynh_apps_backup.scheduled_month | default('*') }}" + weekday: "{{ ynh_apps_backup.scheduled_weekday | default('*') }}" + hour: "{{ ynh_apps_backup.scheduled_hour | default('1') }}" + minute: "{{ ynh_apps_backup.scheduled_minute | default('0') }}" + user: root + job: "{% if ynh_apps_backup.directory is string %} + yunohost backup create --apps --output-directory {{ ynh_apps_backup.directory }}_$(date +%Y%m%d_%H%M%S) + {% else %} + yunohost backup create --apps + {% endif %}" + cron_file: ynh_apps_backup_cron +``` +La tâche backup va permettre de sauvegarder les applications Yunohost ainsi que leurs données grâce à la mise en place d'une tâche cron. +- `ynh_apps_backup.scheduled` : Pour activer la fonctionnalité de sauvegarde des applications Yunohost, mettez la valeur à `true`. +- `ynh_apps_backup.directory` : Le dossier de sauvegarde par défaut est `/home/yunohost.backup/archives` cependant vous pouvez tout à fait choisir de sauvegarder les backups dans un autre dossier grâce à cette variable. Dans ce cas, de manière à pouvoir restaurer les backups depuis l'interface web, Yunohost créé automatiquement un lien symbolique de l'archive créée vers son dossier par défaut. +- `ynh_apps_backup.scheduled_hour/minute/weekday/month`: Permet de modifier quand la tâche cron se déclenche. Par défaut elle se déclenchera tous les jours de l'année à 1 heure du matin. Pour plus d'informations concernant les réglages horaires cron, cet outil peut être utile : https://crontab.guru/. + ## Dépendances Aucune. diff --git a/README.md b/README.md index 0647f8d..56e8165 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,30 @@ Because this task uses the template module, you can use your own variables and c For `owner` and `group`, by default the file will take as owner the name of the application and as owner www-data(NGINX group). You can change them by specifying different values. +### Backups management + +```yml +- name: Create cron task to perform YNH apps backup + ansible.builtin.cron: + name: "auto-backup apps to {{ ynh_apps_backup.directory | default('/home/yunohost.backup/archives') }}" + month: "{{ ynh_apps_backup.scheduled_month | default('*') }}" + weekday: "{{ ynh_apps_backup.scheduled_weekday | default('*') }}" + hour: "{{ ynh_apps_backup.scheduled_hour | default('1') }}" + minute: "{{ ynh_apps_backup.scheduled_minute | default('0') }}" + user: root + job: "{% if ynh_apps_backup.directory is string %} + yunohost backup create --apps --output-directory {{ ynh_apps_backup.directory }}_$(date +%Y%m%d_%H%M%S) + {% else %} + yunohost backup create --apps + {% endif %}" + cron_file: ynh_apps_backup_cron +``` + +The backup task will allow to backup Yunohost applications and their data by setting up a cron job. +- `ynh_apps_backup.scheduled`: To enable the Yunohost applications backup feature, set the value to `true`. +- `ynh_apps_backup.directory`: The default backup folder is `/home/yunohost.backup/archives` however you can choose to save the backups in another folder with this variable. In this case, in order to be able to restore the backups from the web interface, Yunohost automatically creates a symbolic link from the created archive to its default folder. +- `ynh_apps_backup.scheduled_hour/minute/weekday/month`: Allows you to change when the cron job is triggered. By default it will run every day of the year at 1am. For more information about cron time settings, this tool can be useful: https://crontab.guru/. + ## Dependencies None. diff --git a/defaults/main.yml b/defaults/main.yml index 67a7ac2..8410b63 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -64,10 +64,10 @@ ynh_apps: null # group: ttrss # Only provide if different from www-data # Variables for backup -# ynh_backup: -# directory: "/data/backup" #If you want default folder, just leave it empty -# scheduled: "true" -# scheduled_hour: 3 -# scheduled_minute: "0" -# scheduled_weekday: "*" -# scheduled_month: "*" +ynh_apps_backup: + scheduled: "false" + # directory: "/data/backup" + # scheduled_hour: 3 + # scheduled_minute: "0" + # scheduled_weekday: "*" + # scheduled_month: "*" diff --git a/tasks/backup.yml b/tasks/backup.yml index 9bc6ed8..15e732e 100644 --- a/tasks/backup.yml +++ b/tasks/backup.yml @@ -20,21 +20,15 @@ - name: Create cron task to perform YNH apps backup ansible.builtin.cron: - name: "auto-backup apps to {{ ynh_backup.directory | default('/home/yunohost.backup/archives') }}" - month: "{{ ynh_backup.scheduled_month | default('*') }}" - weekday: "{{ ynh_backup.scheduled_weekday | default('*') }}" - hour: "{{ ynh_backup.scheduled_hour | default('1') }}" - minute: "{{ ynh_backup.scheduled_minute | default('0') }}" + name: "auto-backup apps to {{ ynh_apps_backup.directory | default('/home/yunohost.backup/archives') }}" + month: "{{ ynh_apps_backup.scheduled_month | default('*') }}" + weekday: "{{ ynh_apps_backup.scheduled_weekday | default('*') }}" + hour: "{{ ynh_apps_backup.scheduled_hour | default('1') }}" + minute: "{{ ynh_apps_backup.scheduled_minute | default('0') }}" user: root - job: "yunohost backup create --apps - {% if ynh_backup.directory is string %} - -o {{ ynh_backup.directory }} -n {{ ynh_backup.name }} + job: "{% if ynh_apps_backup.directory is string %} + yunohost backup create --apps --output-directory {{ ynh_apps_backup.directory }}_$(date +%Y%m%d_%H%M%S) {% else %} - -n {{ ynh_backup.name }} + yunohost backup create --apps {% endif %}" - cron_file: cron_task_ynh_apps_backup - -- name: restart cron config ##Is it useful to restart cron after config change? - ansible.builtin.service: - name: cron - state: restart + cron_file: ynh_apps_backup_cron diff --git a/tasks/main.yml b/tasks/main.yml index 97ff37c..dbb15f6 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -73,6 +73,6 @@ ansible.builtin.include_tasks: apps.yml when: ynh_apps -- name: Enable Yunohost backup +- name: Enable Yunohost apps backup ansible.builtin.include_tasks: backup.yml - when: ynh_backup.scheduled == 'true' + when: ynh_apps_backup.scheduled == "true" -- GitLab