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 7877203c authored by Arthur BOUDREAULT's avatar Arthur BOUDREAULT
Browse files

refactor: refactoring of purging system.

parent e568d353
No related branches found
No related tags found
No related merge requests found
Pipeline #7430 failed
This commit is part of merge request !41. Comments created here will be created in the context of that merge request.
......@@ -32,6 +32,8 @@ ynh_backup:
apps: True
src_script: "templates/ynh_backup.sh.j2"
dest_script: "/usr/bin"
number_days_to_keep: "2"
```
- `ynh_backup.scheduled` : active la fonctionnalité de sauvegarde des applications YunoHost, mettez la valeur à `True`.
......@@ -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.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`.
- `number_days_to_keep` : **obligatoire**. Détermine le nombre de jours à garder pour le système de purge.
### Sauvegardes distantes avec BorgBackup
......
......@@ -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.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`.
- `number_days_to_keep` : **mandatory**. Determines the number of days to keep for the purging system.
### remote backups with YunoHost BorgBackup
......
......@@ -28,6 +28,8 @@ ynh_backup:
# scheduled_month: "*"
# system: True
# apps: True
number_days_to_keep: "2"
# Variables for YunoHost BorgBackup
ynh_borg_backup_scheduled: False
......
#!/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.
today=$(date +%Y%m%d_%H%M)
old_backup=$(yunohost backup list --output-as plain | grep "$(date --date="2 days ago" +"%Y%m%d")")
_good() {
echo "SUCCESS: ${1}" && exit 0
}
_check_old_backup() {
if [ -n "$old_backup" ]; then
for i in $old_backup; do
echo "Backup $i is 2 days old or more. Purging it now."
yunohost backup delete "$i"
echo "Purging of old backup is now complete."
done
else
echo "There is no old backup to be purged."
fi
_fail() {
echo "ERROR: ${1}" && exit 1
}
_create_ynh_backup() {
......@@ -21,5 +17,17 @@ _create_ynh_backup() {
}
_check_old_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
_fail "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