diff --git a/README-FR.md b/README-FR.md index 883dcfa2c50d6b520284474f9f9b20a1a6d54532..ae8320e2e9f02319c1b46afdba25aec31adb86d7 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 0647f8d916995ca58a55da0e22b378d27ad47346..56e816516ec59c1aab194c489286bb18e795bdf4 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 67a7ac21aff72dde1a5c489ecd2911226493663c..8410b63c21edc95e908f1f22c10f331020409961 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 9bc6ed8f19b9b2b4959daf3861117a1781ec4d70..15e732e125590ed78116672f57a66da010d5ca17 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 97ff37c18df536ed74009f3a0b971ac85a519db3..dbb15f6321e7a1a6fdf5470257d3d98fbe7b6533 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"