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 f1413365 authored by Christophe Chaudier's avatar Christophe Chaudier :rocket:
Browse files

Merge branch '60-local-backups-design-purge-system' into 'main'

Resolve "local backups: design purge system"

Closes #60

See merge request !41
parents 038b5624 6cf1239d
No related branches found
No related tags found
1 merge request!41Resolve "local backups: design purge system"
Pipeline #7440 passed with warnings
...@@ -32,6 +32,8 @@ ynh_backup: ...@@ -32,6 +32,8 @@ ynh_backup:
apps: True apps: True
src_script: "templates/ynh_backup.sh.j2" src_script: "templates/ynh_backup.sh.j2"
dest_script: "/usr/bin" dest_script: "/usr/bin"
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, mettez la valeur à `True`.
...@@ -39,6 +41,7 @@ ynh_backup: ...@@ -39,6 +41,7 @@ ynh_backup:
- `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 à 1 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` : **obligatoire**. Activez la sauvegarde du système YunoHost en mettant la valeur à `True`.
- `ynh_backup.apps` : **obligatoire**. Activez la sauvegarde des applications YunoHost en mettant la valeur à `True`. - `ynh_backup.apps` : **obligatoire**. Activez la sauvegarde des applications YunoHost en mettant la valeur à `True`.
- `number_days_to_keep` : **obligatoire**. Détermine le nombre de jours à garder pour le système de purge.
### Sauvegardes distantes avec BorgBackup ### Sauvegardes distantes avec BorgBackup
......
...@@ -39,6 +39,7 @@ ynh_backup: ...@@ -39,6 +39,7 @@ ynh_backup:
- `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 1am. 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`: **mandatory**. Enables automatic backup of the YunoHost system by setting the value to `True`.
- `ynh_backup.apps`: **mandatory**. Enables automatic backup of YunoHost applications by setting the value to `True`. - `ynh_backup.apps`: **mandatory**. Enables automatic backup of YunoHost applications by setting the value to `True`.
- `number_days_to_keep` : **mandatory**. Determines the number of days to keep for the purging system.
### remote backups with YunoHost BorgBackup ### remote backups with YunoHost BorgBackup
......
...@@ -29,6 +29,8 @@ ynh_backup: ...@@ -29,6 +29,8 @@ ynh_backup:
# system: True # system: True
# apps: 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
borg_source_directories: borg_source_directories:
......
#!/bin/sh #!/bin/bash
today="$(date +%Y%m%d)"
number_to_keep="{{ number_days_to_keep }}"
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.
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_$(date +%Y%m%d_%H%M) {% endif %} _good() {
echo "SUCCESS: ${1}" && exit 0
}
{% if ynh_backup.system is false and ynh_backup.apps is false %} _fail() {
echo "Read the readme to know more about vars ynh_backup.system and ynh_backup.apps" echo "ERROR: ${1}" && exit 1
exit 1 }
{% endif %}
_create_ynh_backup() {
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"
}
_prune_old_backup() {
if [ -n "$old_backup_list" ]; then
for backup in $old_backup_list; do
echo "Backup $backup is 2 days old or more. Purging it now."
yunohost backup delete "$backup"
done
_good "Purging of old backups completed."
else
_good "There is no old backup to be purged."
fi
}
_create_ynh_backup
_prune_old_backup
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