Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit 41a1d1d0 authored by Arthur BOUDREAULT's avatar Arthur BOUDREAULT
Browse files

feat: add template script

parent 06d9a65a
No related branches found
No related tags found
1 merge request!19Draft: Resolve "backup all installed apps and system"
Pipeline #3491 passed with warnings
...@@ -123,7 +123,7 @@ Il est possible de compléter l'installation des applications par l'ajout de tem ...@@ -123,7 +123,7 @@ Il est possible de compléter l'installation des applications par l'ajout de tem
Pour activer cette fonctionnalité, définissez la variable `post_install` qui correspond à la liste des fichiers de post-installation de votre application. Pour activer cette fonctionnalité, définissez la variable `post_install` qui correspond à la liste des fichiers de post-installation de votre application.
Cette tâche utilisant le module template, vous pouvez tout à fait utiliser vos propres variables et les appeler dans vos fichiers de template. Pour en savoir sur ce module, cliquez [ici](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/template_module.html). Cette tâche utilisant le module template, vous pouvez tout à fait utiliser vos propres variables et les appeler dans vos fichiers de template. Pour en savoir sur ce module, cliquez [ici](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/template_module.html).
- `src` est obligatoire. Il s'agit du répertoire où le fichier de template se situe sur la machine qui execute Ansible. - `src` est obligatoire. Il s'agit du répertoire où le fichier de template se situe sur la machine qui exécute Ansible.
- `dest` est obligatoire. Il s'agit du répertoire où le fichier de template va être stocké. - `dest` est obligatoire. Il s'agit du répertoire où le fichier de template va être stocké.
- `type` est obligatoire : - `type` est obligatoire :
- Si vous précisez comme valeur `script` alors le fichier de template aura pour droits 740. Il sera exécuté après son transfert sur le serveur Yunohost (généralement dans `/tmp/`) puis il sera supprimé. - Si vous précisez comme valeur `script` alors le fichier de template aura pour droits 740. Il sera exécuté après son transfert sur le serveur Yunohost (généralement dans `/tmp/`) puis il sera supprimé.
...@@ -134,25 +134,22 @@ Pour `owner` et `group`, par défaut le fichier va prendre comme utilisateur pro ...@@ -134,25 +134,22 @@ Pour `owner` et `group`, par défaut le fichier va prendre comme utilisateur pro
### Gestion des sauvegardes ### Gestion des sauvegardes
```yml ```yml
- name: Create cron task to perform YNH apps backup ynh_apps_backup:
ansible.builtin.cron: scheduled: "true"
name: "auto-backup apps to {{ ynh_apps_backup.directory | default('/home/yunohost.backup/archives') }}" directory: "/data/backup"
month: "{{ ynh_apps_backup.scheduled_month | default('*') }}" scheduled_hour: "*"
weekday: "{{ ynh_apps_backup.scheduled_weekday | default('*') }}" scheduled_minute: "*/30"
hour: "{{ ynh_apps_backup.scheduled_hour | default('1') }}" scheduled_weekday: "*"
minute: "{{ ynh_apps_backup.scheduled_minute | default('0') }}" scheduled_month: "*"
user: root src_script: "templates/ynh_apps_backup.sh.j2"
job: "{% if ynh_apps_backup.directory is string %} dest_script: "/data/backup/backup_ynh_apps.sh"
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. 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.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.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/. - `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é.
## Dépendances ## Dépendances
......
...@@ -134,26 +134,23 @@ For `owner` and `group`, by default the file will take as owner the name of the ...@@ -134,26 +134,23 @@ For `owner` and `group`, by default the file will take as owner the name of the
### Backups management ### Backups management
```yml ```yml
- name: Create cron task to perform YNH apps backup ynh_apps_backup:
ansible.builtin.cron: scheduled: "true"
name: "auto-backup apps to {{ ynh_apps_backup.directory | default('/home/yunohost.backup/archives') }}" directory: "/data/backup"
month: "{{ ynh_apps_backup.scheduled_month | default('*') }}" scheduled_hour: "*"
weekday: "{{ ynh_apps_backup.scheduled_weekday | default('*') }}" scheduled_minute: "*/30"
hour: "{{ ynh_apps_backup.scheduled_hour | default('1') }}" scheduled_weekday: "*"
minute: "{{ ynh_apps_backup.scheduled_minute | default('0') }}" scheduled_month: "*"
user: root src_script: "templates/ynh_apps_backup.sh.j2"
job: "{% if ynh_apps_backup.directory is string %} dest_script: "/data/backup/backup_ynh_apps.sh"
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. 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.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.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/. - `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.
## Dependencies ## Dependencies
......
...@@ -63,7 +63,7 @@ ynh_apps: null ...@@ -63,7 +63,7 @@ ynh_apps: null
# owner: ttrss # Only provide if different from app name # owner: ttrss # Only provide if different from app name
# group: ttrss # Only provide if different from www-data # group: ttrss # Only provide if different from www-data
# Variables for backup # Variables for apps backup
ynh_apps_backup: ynh_apps_backup:
scheduled: "false" scheduled: "false"
# directory: "/data/backup" # directory: "/data/backup"
...@@ -71,3 +71,5 @@ ynh_apps_backup: ...@@ -71,3 +71,5 @@ ynh_apps_backup:
# scheduled_minute: "0" # scheduled_minute: "0"
# scheduled_weekday: "*" # scheduled_weekday: "*"
# scheduled_month: "*" # scheduled_month: "*"
# src_script: "templates/ynh_apps_backup.sh.j2"
# dest_script: "/data/backup/backup_ynh_apps.sh"
...@@ -18,6 +18,20 @@ ...@@ -18,6 +18,20 @@
# # # #
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
- name: Create backup folder
ansible.builtin.file:
path: "{{ ynh_apps_backup.directory | default('/home/yunohost.backup/') }}"
state: directory
mode: '0750'
- name: Create apps backup script
ansible.builtin.template:
src: "{{ ynh_apps_backup.src_script }}"
dest: "{{ ynh_apps_backup.dest_script }}"
owner: root
group: root
mode: '0740'
- name: Create cron task to perform YNH apps backup - name: Create cron task to perform YNH apps backup
ansible.builtin.cron: ansible.builtin.cron:
name: "auto-backup apps to {{ ynh_apps_backup.directory | default('/home/yunohost.backup/archives') }}" name: "auto-backup apps to {{ ynh_apps_backup.directory | default('/home/yunohost.backup/archives') }}"
...@@ -26,9 +40,5 @@ ...@@ -26,9 +40,5 @@
hour: "{{ ynh_apps_backup.scheduled_hour | default('1') }}" hour: "{{ ynh_apps_backup.scheduled_hour | default('1') }}"
minute: "{{ ynh_apps_backup.scheduled_minute | default('0') }}" minute: "{{ ynh_apps_backup.scheduled_minute | default('0') }}"
user: root user: root
job: "{% if ynh_apps_backup.directory is string %} job: "{{ ynh_apps_backup.dest_script }}"
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 cron_file: ynh_apps_backup_cron
#!/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)
{% else %}
yunohost backup create --apps
{% endif %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment