Merge branch '45-refactor-improve-backup-usage' into 'main'
Resolve "refactor: improve backup usage README" Closes #45 See merge request lydra/yunohost/ansible-yunohost!39
This commit is contained in:
commit
888d14cd03
6 changed files with 27 additions and 29 deletions
|
@ -30,18 +30,17 @@ ynh_backup:
|
||||||
scheduled_month: "*"
|
scheduled_month: "*"
|
||||||
system: True
|
system: True
|
||||||
apps: True
|
apps: True
|
||||||
src_script: "templates/ynh_backup.sh.j2"
|
|
||||||
dest_script: "/usr/bin"
|
|
||||||
|
|
||||||
number_days_to_keep: "2"
|
number_days_to_keep: "2"
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
- `ynh_backup.scheduled` : active la fonctionnalité de sauvegarde des applications YunoHost, mettez la valeur à `True`.
|
- `ynh_backup.scheduled` : active la fonctionnalité de sauvegarde des applications YunoHost en mettant la valeur à `True`.
|
||||||
- `ynh_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_backup.directory` : le dossier de sauvegarde par défaut est `/home/yunohost.backup/archives`. Vous pouvez 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_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/>.
|
- `ynh_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 à 3 heure du matin. Pour plus d'informations concernant les réglages horaires cron, cet outil peut être utile : <https://crontab.guru/>.
|
||||||
- `ynh_backup.system` : **obligatoire**. Activez la sauvegarde du système YunoHost en mettant la valeur à `True`.
|
- `ynh_backup.system` : Désactivez la sauvegarde du système YunoHost en mettant la valeur à `False`, la valeur par défaut est à `True`.
|
||||||
- `ynh_backup.apps` : **obligatoire**. Activez la sauvegarde des applications YunoHost en mettant la valeur à `True`.
|
- `ynh_backup.apps` : Désactivez la sauvegarde des applications YunoHost en mettant la valeur à `False`, la valeur par défaut est à `True`.
|
||||||
- `number_days_to_keep` : **obligatoire**. Détermine le nombre de jours à garder pour le système de purge.
|
- `ynh_backup.number_days_to_keep` : Détermine le nombre de jours à garder pour le système de purge, la valeur par défaut est 2.
|
||||||
|
- ⚠️ Attention, à partir du moment où vous activez la fonctionnalité de sauvegarde locale `ynh_backup.scheduled`, vous ne pouvez pas désactiver les sauvegardes système **et** applications. Si vous mettez `ynh_backup.system` **et** `ynh_backup.apps` à `False`, le rôle tombera en erreur.
|
||||||
|
|
||||||
### Sauvegardes distantes avec BorgBackup
|
### Sauvegardes distantes avec BorgBackup
|
||||||
|
|
||||||
|
|
|
@ -34,12 +34,13 @@ ynh_backup:
|
||||||
dest_script: "/usr/bin"
|
dest_script: "/usr/bin"
|
||||||
```
|
```
|
||||||
|
|
||||||
- `ynh_backup.scheduled`: to enable the YunoHost applications backup feature, set the value to `True`.
|
- `ynh_backup.scheduled`: Enable the YunoHost applications backup feature by setting the value to `True`.
|
||||||
- `ynh_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_backup.directory`: the default backup folder is `/home/yunohost.backup/archives`. 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_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/>.
|
- `ynh_backup.scheduled_[hour|minute|weekday|month]`: modifies the scheduling of the cron task. By default, it will run every day of the year at 3am. For more information about cron time settings, this tool can be useful: <https://crontab.guru/>.
|
||||||
- `ynh_backup.system`: **mandatory**. Enables automatic backup of the YunoHost system by setting the value to `True`.
|
- `ynh_backup.system`: Disable YunoHost system backup by setting the value to `False`, the default value is `True`.
|
||||||
- `ynh_backup.apps`: **mandatory**. Enables automatic backup of YunoHost applications by setting the value to `True`.
|
- `ynh_backup.apps`: Disable backup of YunoHost applications by setting the value to `False`, the default is `True`.
|
||||||
- `number_days_to_keep` : **mandatory**. Determines the number of days to keep for the purging system.
|
- `ynh_backup.number_days_to_keep` : Determines the number of days to keep for the purging system, the default is 2.
|
||||||
|
- ⚠️ Beware, once you enable the local backup feature `ynh_backup.scheduled`, you cannot disable system **and** application backups. If you set `ynh_backup.system` **and** `ynh_backup.apps` to `False`, the role will fail.
|
||||||
|
|
||||||
### remote backups with YunoHost BorgBackup
|
### remote backups with YunoHost BorgBackup
|
||||||
|
|
||||||
|
|
|
@ -21,15 +21,6 @@
|
||||||
# Variables for local YunoHost backups
|
# Variables for local YunoHost backups
|
||||||
ynh_backup:
|
ynh_backup:
|
||||||
scheduled: False
|
scheduled: False
|
||||||
# directory: "/data/backup"
|
|
||||||
# scheduled_hour: 3
|
|
||||||
# scheduled_minute: "0"
|
|
||||||
# scheduled_weekday: "*"
|
|
||||||
# scheduled_month: "*"
|
|
||||||
# system: True
|
|
||||||
# apps: True
|
|
||||||
|
|
||||||
number_days_to_keep: "2"
|
|
||||||
|
|
||||||
# Variables for YunoHost BorgBackup
|
# Variables for YunoHost BorgBackup
|
||||||
ynh_borg_backup_scheduled: False
|
ynh_borg_backup_scheduled: False
|
||||||
|
|
|
@ -17,12 +17,18 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
||||||
# #
|
# #
|
||||||
#-----------------------------------------------------------------------------#
|
#-----------------------------------------------------------------------------#
|
||||||
|
- name: Fail if variables are not used correctly
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: You need to define variable ynh_backup.apps and / or ynh_backup.system to True
|
||||||
|
when: ynh_backup.apps | default(True) is false and ynh_backup.system | default(True) is false
|
||||||
|
tags: backup
|
||||||
|
|
||||||
- name: Create backup folder if doesn't already exist
|
- name: Create backup folder if doesn't already exist
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: "{{ ynh_backup.directory | default('/home/yunohost.backup/archives') }}"
|
path: "{{ ynh_backup.directory }}"
|
||||||
state: directory
|
state: directory
|
||||||
mode: '0750'
|
mode: '0750'
|
||||||
|
when: ynh_backup.directory is defined
|
||||||
tags: backup
|
tags: backup
|
||||||
|
|
||||||
- name: Create backup script
|
- name: Create backup script
|
||||||
|
@ -36,7 +42,7 @@
|
||||||
|
|
||||||
- name: Create cron task to schedule YNH backup script
|
- name: Create cron task to schedule YNH backup script
|
||||||
ansible.builtin.cron:
|
ansible.builtin.cron:
|
||||||
name: "auto-backup to {{ ynh_backup.directory | default('/home/yunohost.backup/archives') }}"
|
name: "auto-backup to {{ ynh_backup.directory | default(_ynh_backup_directory) }}"
|
||||||
month: "{{ ynh_backup.scheduled_month | default('*') }}"
|
month: "{{ ynh_backup.scheduled_month | default('*') }}"
|
||||||
weekday: "{{ ynh_backup.scheduled_weekday | default('*') }}"
|
weekday: "{{ ynh_backup.scheduled_weekday | default('*') }}"
|
||||||
hour: "{{ ynh_backup.scheduled_hour | default('1') }}"
|
hour: "{{ ynh_backup.scheduled_hour | default('1') }}"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
today="$(date +%Y%m%d)"
|
today="$(date +%Y%m%d)"
|
||||||
number_to_keep="{{ number_days_to_keep }}"
|
number_to_keep="{{ ynh_backup.number_days_to_keep | default("2") }}"
|
||||||
old_backup_list="$(yunohost backup list --output-as plain | head -n -"$number_to_keep")" # Afficher toutes les lignes de sauvegardes à part les deux dernières.
|
old_backup_list="$(yunohost backup list --output-as plain | head -n -"$number_to_keep")"
|
||||||
|
|
||||||
_good() {
|
_good() {
|
||||||
echo "SUCCESS: ${1}" && exit 0
|
echo "SUCCESS: ${1}" && exit 0
|
||||||
|
@ -13,7 +13,7 @@ _fail() {
|
||||||
|
|
||||||
_create_ynh_backup() {
|
_create_ynh_backup() {
|
||||||
echo "Backing up $today YunoHost data now."
|
echo "Backing up $today YunoHost data now."
|
||||||
yunohost backup create {% if ynh_backup.system %}--system{% endif %}{% if ynh_backup.apps %} --apps{% endif %}{% if ynh_backup.directory %} --output-directory {{ ynh_backup.directory }}/backup_"$today" {% endif %} || _fail "can't create a backup"
|
yunohost backup create {% if ynh_backup.system | default(True) %}--system{% endif %}{% if ynh_backup.apps | default(True) %} --apps{% endif %}{% if ynh_backup.directory is defined %} --output-directory {{ ynh_backup.directory }}/backup_"$today" {% endif %} || _fail "can't create a backup"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,3 +21,4 @@
|
||||||
# Variables for backup
|
# Variables for backup
|
||||||
ynh_backup_src_script: "templates/ynh_backup.sh.j2"
|
ynh_backup_src_script: "templates/ynh_backup.sh.j2"
|
||||||
ynh_backup_dest_script: "/usr/local/bin/ynh_backup.sh"
|
ynh_backup_dest_script: "/usr/local/bin/ynh_backup.sh"
|
||||||
|
_ynh_backup_directory: "/home/yunohost.backup/archives"
|
||||||
|
|
Loading…
Reference in a new issue