2020-02-23 12:02:10 +01:00
|
|
|
#!/bin/bash
|
|
|
|
LOCK_FILE=/tmp/{{ app }}_backup.lock
|
2020-02-23 19:20:42 +01:00
|
|
|
EXIT_PROPERLY() {
|
|
|
|
echo -e "\e[91m \e[1m" # Shell in light red bold
|
|
|
|
echo -e "!!\n Caught an interruption signal, removing lock file...\n!!"
|
|
|
|
echo -e "\e[22m" # Remove bold
|
|
|
|
|
|
|
|
rm $LOCK_FILE
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
trap EXIT_PROPERLY 1 2 3 6 15
|
2020-02-23 12:02:10 +01:00
|
|
|
if [ -f "$LOCK_FILE" ];then
|
|
|
|
echo "Backup already launched by process $(grep '.*' $LOCK_FILE), canceling this one" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo $$ > "$LOCK_FILE"
|
|
|
|
if yunohost -v | grep "version: 2." > /dev/null; then
|
|
|
|
ignore_apps="--ignore-apps"
|
|
|
|
ignore_system="--ignore-system"
|
|
|
|
else
|
|
|
|
ignore_apps=""
|
|
|
|
ignore_system=""
|
|
|
|
fi
|
|
|
|
filter_hooks() {
|
|
|
|
ls /usr/share/yunohost/hooks/backup/ /etc/yunohost/hooks.d/backup/ | grep "\-$1_" | cut -d"-" -f2 | uniq
|
|
|
|
}
|
|
|
|
|
|
|
|
# Backup system part conf
|
|
|
|
conf=$(yunohost app setting {{ app }} conf)
|
|
|
|
if [ $conf -eq 1 ];then
|
|
|
|
yunohost backup create $ignore_apps -n auto_conf --method {{ app }}_app --system $(filter_hooks conf)
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Backup system data
|
|
|
|
data=$(yunohost app setting {{ app }} data)
|
|
|
|
if [ $data -eq 1 ];then
|
|
|
|
yunohost backup create $ignore_apps -n auto_data --method {{ app }}_app --system $(filter_hooks data)
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Backup all apps independently
|
|
|
|
apps=$(yunohost app setting {{ app }} apps)
|
2020-06-19 14:36:25 +02:00
|
|
|
for app in $(ls /etc/yunohost/apps/*/scripts/backup | cut -d / -f 5); do
|
2020-02-23 12:02:10 +01:00
|
|
|
backup_app=false
|
|
|
|
for selected_app in $(echo $apps | tr "," " ");do
|
|
|
|
if [[ "$selected_app" == "$app" ]] || [ "$apps" = "all" ]; then
|
|
|
|
backup_app=true
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ "$backup_app" == "true" ];then
|
|
|
|
yunohost backup create $ignore_system -n auto_$app --method {{ app }}_app --apps $app
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
rm "$LOCK_FILE"
|