From 6acf59517d14d3f2d3a31f42d0180ee2ba738a4e Mon Sep 17 00:00:00 2001 From: Arthur BOUDREAULT <arthur@lydra.fr> Date: Mon, 24 Jan 2022 15:24:23 +0100 Subject: [PATCH] --wip-- [skip ci] --- README-FR.md | 12 ++++++------ README.md | 12 ++++++------ defaults/main.yml | 4 ++-- tasks/backup.yml | 13 +++++++------ tasks/main.yml | 3 ++- templates/ynh_apps_backup.sh.j2 | 2 +- 6 files changed, 24 insertions(+), 22 deletions(-) diff --git a/README-FR.md b/README-FR.md index 472fb75..c4f0572 100644 --- a/README-FR.md +++ b/README-FR.md @@ -142,14 +142,14 @@ ynh_apps_backup: scheduled_weekday: "*" scheduled_month: "*" src_script: "templates/ynh_apps_backup.sh.j2" - dest_script: "/data/backup/backup_ynh_apps.sh" + dest_script: "/usr/bin" ``` 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/. -- `src_script` est obligatoire. Il s'agit du répertoire où le fichier de template se situe sur la machine qui exécute Ansible. -- `dest_script` est obligatoire. Il s'agit du répertoire où le fichier de template va être stocké. +- `ynh_apps_backup.scheduled` : active 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]`: modifie la planification de la tâche cron. 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/. +- `src_script`: il s'agit du chemin absolu où le fichier de template se situe sur la machine qui exécute Ansible. Par défaut, il sera stocké dans `templates/ynh_apps_backup.sh.j2`. +- `dest_script`: il s'agit du répertoire où le fichier de template va être stocké. Par défaut, il sera stocké dans `/usr/local/bin/`. Le script s'appelle `ynh_apps_backup.sh`. ## Dépendances diff --git a/README.md b/README.md index 0c80072..ffbd4cc 100644 --- a/README.md +++ b/README.md @@ -142,15 +142,15 @@ ynh_apps_backup: scheduled_weekday: "*" scheduled_month: "*" src_script: "templates/ynh_apps_backup.sh.j2" - dest_script: "/data/backup/backup_ynh_apps.sh" + dest_script: "/usr/bin" ``` 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/. -- `src_script` is mandatory. This is the directory where the template file is located on the machine running Ansible. -- `dest_script` is required. This is the directory where the template file will be stored. +- `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]`: modifies the scheduling of the cron task. 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/. +- `src_script`: this is the absolute path where the template file is located on the machine running Ansible. By default is will be stored in `templates/ynh_apps_backup.sh.j2`. +- `dest_script`: this is the directory where the template file will be stored. By default is will be stored in `/usr/local/bin`. The script is named `ynh_apps_backup.sh`. ## Dependencies diff --git a/defaults/main.yml b/defaults/main.yml index d773c28..a1dfea7 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -65,11 +65,11 @@ ynh_apps: null # Variables for apps backup ynh_apps_backup: - scheduled: "false" + scheduled: False # directory: "/data/backup" # scheduled_hour: 3 # scheduled_minute: "0" # scheduled_weekday: "*" # scheduled_month: "*" # src_script: "templates/ynh_apps_backup.sh.j2" - # dest_script: "/data/backup/backup_ynh_apps.sh" + # dest_script: "/usr/local/bin/" diff --git a/tasks/backup.yml b/tasks/backup.yml index c454fc2..183b512 100644 --- a/tasks/backup.yml +++ b/tasks/backup.yml @@ -20,18 +20,18 @@ - name: Create backup folder ansible.builtin.file: - path: "{{ ynh_apps_backup.directory | default('/home/yunohost.backup/') }}" + path: "{{ ynh_apps_backup.directory | default('/home/yunohost.backup/archives') }}" state: directory mode: '0750' - + tags: test - name: Create apps backup script ansible.builtin.template: - src: "{{ ynh_apps_backup.src_script }}" - dest: "{{ ynh_apps_backup.dest_script }}" + src: "{{ ynh_apps_backup.src_script | default('templates/ynh_apps_backup.sh.j2') }}" + dest: "{{ ynh_apps_backup.dest_script | default('/usr/local/bin/') }}ynh_apps_backup.sh" owner: root group: root mode: '0740' - + tags: test - 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') }}" @@ -40,5 +40,6 @@ hour: "{{ ynh_apps_backup.scheduled_hour | default('1') }}" minute: "{{ ynh_apps_backup.scheduled_minute | default('0') }}" user: root - job: "{{ ynh_apps_backup.dest_script }}" + job: "{{ ynh_apps_backup.dest_script | default('/usr/local/bin/') }}ynh_apps_backup.sh" cron_file: ynh_apps_backup_cron + tags: test diff --git a/tasks/main.yml b/tasks/main.yml index dbb15f6..1782880 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -75,4 +75,5 @@ - name: Enable Yunohost apps backup ansible.builtin.include_tasks: backup.yml - when: ynh_apps_backup.scheduled == "true" + when: ynh_apps_backup.scheduled + tags: test diff --git a/templates/ynh_apps_backup.sh.j2 b/templates/ynh_apps_backup.sh.j2 index e973978..e31df1a 100644 --- a/templates/ynh_apps_backup.sh.j2 +++ b/templates/ynh_apps_backup.sh.j2 @@ -1,7 +1,7 @@ #!/bin/sh {% if ynh_apps_backup.directory is string %} -yunohost backup create --apps --output-directory {{ ynh_apps_backup.directory }}/backup_$(date +%Y%m%d_%H%M%S) +yunohost backup create --apps --output-directory {{ ynh_apps_backup.directory }}/backup_$(date +%Y%m%d_%H%M) {% else %} yunohost backup create --apps {% endif %} -- GitLab