2022-07-25 15:16:54 +02:00
|
|
|
#!/bin/bash
|
|
|
|
today="$(date +%Y%m%d)"
|
2022-07-26 11:32:00 +02:00
|
|
|
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")"
|
2022-01-27 11:55:40 +01:00
|
|
|
|
2022-07-25 15:16:54 +02:00
|
|
|
_good() {
|
|
|
|
echo "SUCCESS: ${1}" && exit 0
|
|
|
|
}
|
2022-01-27 11:55:40 +01:00
|
|
|
|
2022-07-25 15:16:54 +02:00
|
|
|
_fail() {
|
|
|
|
echo "ERROR: ${1}" && exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
_create_ynh_backup() {
|
|
|
|
echo "Backing up $today YunoHost data now."
|
2022-07-26 11:32:00 +02:00
|
|
|
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"
|
2022-07-25 15:16:54 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_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
|