mirror of
https://github.com/YunoHost-Apps/borg_ynh.git
synced 2024-09-03 18:16:05 +02:00
[fix] Backup with borg script was incorrect
This commit is contained in:
parent
1019fa44e3
commit
0788666a33
8 changed files with 68 additions and 36 deletions
|
@ -14,6 +14,7 @@
|
||||||
setup_private=0
|
setup_private=0
|
||||||
setup_public=0
|
setup_public=0
|
||||||
upgrade=1
|
upgrade=1
|
||||||
|
upgrade=1 from_commit=c1524dd8e37cc671c01f5b5363901dd6a01e6fc1
|
||||||
backup_restore=1
|
backup_restore=1
|
||||||
multi_instance=1
|
multi_instance=1
|
||||||
port_already_use=0
|
port_already_use=0
|
||||||
|
|
|
@ -9,14 +9,14 @@ current_date=$(date +"%y%m%d_%H%M")
|
||||||
log_file="/var/log/${borg_id}/${current_date}.log"
|
log_file="/var/log/${borg_id}/${current_date}.log"
|
||||||
err_file="/var/log/${borg_id}/${current_date}.err"
|
err_file="/var/log/${borg_id}/${current_date}.err"
|
||||||
mkdir -p "/var/log/${borg_id}"
|
mkdir -p "/var/log/${borg_id}"
|
||||||
if [[ -z "$borg_id" ]]
|
if [ -z "$borg_id" ]
|
||||||
then
|
then
|
||||||
echo "This script expects a borg app id as first argument" >&2
|
echo "This script expects a borg app id as first argument" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
filter_hooks() {
|
filter_hooks() {
|
||||||
ls /usr/share/yunohost/hooks/backup/ /etc/yunohost/hooks.d/backup/ | grep "\-$1_" | cut -d"-" -f2 | uniq
|
sudo ls /usr/share/yunohost/hooks/backup/ /etc/yunohost/hooks.d/backup/ | grep "\-$1_" | cut -d"-" -f2 | uniq 2>> $err_file
|
||||||
}
|
}
|
||||||
|
|
||||||
fail_if_partially_failed() {
|
fail_if_partially_failed() {
|
||||||
|
@ -24,52 +24,58 @@ fail_if_partially_failed() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Backup system part conf
|
# Backup system part conf
|
||||||
conf=$(yunohost app setting ${borg_id} conf)
|
conf=$(sudo yunohost app setting ${borg_id} conf)
|
||||||
if [ $conf -eq 1 ]
|
if [[ "$conf" = "1" ]]
|
||||||
then
|
then
|
||||||
if ! yunohost backup create -n auto_conf --method ${borg_id}_app --system $(filter_hooks conf) 2> $err_file > $log_file ; then
|
if ! sudo yunohost backup create -n auto_conf --method ${borg_id}_app --system $(filter_hooks conf) 2>> $err_file >> $log_file ; then
|
||||||
errors="$errors\nconf: Error"
|
errors+="\nThe backup miserably failed to backup system configurations."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Backup system data
|
# Backup system data
|
||||||
data=$(yunohost app setting $app data)
|
data=$(sudo yunohost app setting ${borg_id} data)
|
||||||
if [ $data -eq 1 ]
|
if [[ "$data" = "1" ]]
|
||||||
then
|
then
|
||||||
if ! yunohost backup create -n auto_data --method ${borg_id}_app --system $(filter_hooks data) 2> $err_file > $log_file ; then
|
if ! sudo yunohost backup create -n auto_data --method ${borg_id}_app --system $(filter_hooks data) 2>> $err_file >> $log_file ; then
|
||||||
errors="$errors\ndata: Error"
|
errors+="\nThe backup miserably failed to backup system data."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Backup all apps independently
|
# Backup all apps independently
|
||||||
apps=$(yunohost app setting ${borg_id} apps)
|
apps=$(sudo yunohost app setting ${borg_id} apps | tr -d ' ')
|
||||||
for application in $(ls /etc/yunohost/apps/*/scripts/backup | cut -d / -f 5); do
|
for application in $(sudo ls /etc/yunohost/apps/); do
|
||||||
backup_app=false
|
|
||||||
if [[ "$apps" = "all" ]]; then
|
if ( [[ "$apps" =~ ^exclude: ]] && grep -wq "$application" <<< "$apps" ) ||
|
||||||
backup_app=true
|
( [[ "$apps" != "all" ]] && [[ ! "$apps" =~ ^exclude: ]] && ! grep -wq "$application" <<< "$apps" );
|
||||||
else
|
then
|
||||||
for selected_app in $(echo $apps | tr "," " ");do
|
continue
|
||||||
if [[ "$selected_app" == "$application" ]]; then
|
|
||||||
backup_app=true
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
fi
|
||||||
if [ "$backup_app" == "true" ];then
|
|
||||||
if ! yunohost backup create -n auto_$application --method ${borg_id}_app --apps $application 2> $err_file > $log_file ; then
|
if sudo test ! -f /etc/yunohost/apps/$application/scripts/backup ; then
|
||||||
errors="$errors\$application: Error"
|
errors+="\nWarning: The application $application has no backup script. This app won't be backuped."
|
||||||
fi
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! sudo yunohost backup create -n auto_$application --method ${borg_id}_app --apps $application 2>> $err_file >> $log_file ; then
|
||||||
|
errors+="\nThe backup miserably failed to backup $application application."
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
#=========================================================
|
||||||
|
# SEND MAIL TO NOTIFY SUCCED OR FAILED OPERATIONS
|
||||||
|
#=========================================================
|
||||||
|
|
||||||
partial_errors="$(cat $log_file | grep -E "Error|Skipped")"
|
partial_errors="$(cat $log_file | grep -E "Error|Skipped")"
|
||||||
if [ ! -z "$partial_errors" ]; then
|
if [ ! -z "$partial_errors" ]; then
|
||||||
errors="$errors\n$partial_errors"
|
errors+="\nSome backup partially failed:\n$partial_errors"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Send mail on backup (partially) failed
|
# Send mail on backup (partially) failed
|
||||||
domain=$(hostname)
|
domain=$(hostname)
|
||||||
if [ ! -z "$errors" ]; then
|
if [ ! -z "$errors" ]; then
|
||||||
cat $errors | mail -s "[borg] Backup failed from $domain onto $repo" root
|
cat <(echo -e "$errors\n\n\n") "$log_file" "$err_file" | mail -s "[borg] Backup failed from $domain onto $repo" root
|
||||||
|
exit 1
|
||||||
else
|
else
|
||||||
cat $log_file | mail -s "[borg] Backup succeed from $domain onto $repo" root
|
cat $log_file | mail -s "[borg] Backup succeed from $domain onto $repo" root
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
app="${0#"./05-"}"
|
||||||
|
app="${app%"_app"}"
|
||||||
|
|
||||||
BORG_PASSPHRASE='__PASSPHRASE__'
|
BORG_PASSPHRASE="$(yunohost app setting $app passphrase)"
|
||||||
repo="__REPOSITORY__" #$4
|
repo="$(yunohost app setting $app repository)" #$4
|
||||||
if ssh-keygen -F "__SERVER__" >/dev/null ; then
|
if ssh-keygen -F "__SERVER__" >/dev/null ; then
|
||||||
BORG_RSH="ssh -i /root/.ssh/id___APP___ed25519 -oStrictHostKeyChecking=yes "
|
BORG_RSH="ssh -i /root/.ssh/id_${app}_ed25519 -oStrictHostKeyChecking=yes "
|
||||||
else
|
else
|
||||||
BORG_RSH="ssh -i /root/.ssh/id___APP___ed25519 -oStrictHostKeyChecking=no "
|
BORG_RSH="ssh -i /root/.ssh/id_${app}_ed25519 -oStrictHostKeyChecking=no "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
do_need_mount() {
|
do_need_mount() {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
__APP__ ALL=(root) /usr/local/bin/backup-with-__APP__, /usr/local/bin/borg
|
__APP__ ALL=(root) NOPASSWD: /usr/local/bin/backup-with-__APP__, /usr/local/bin/borg, /usr/bin/yunohost backup create *, /usr/bin/yunohost app setting *, /bin/ls, /usr/bin/test
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
"en": "Backup your server on a host server using Borg.",
|
"en": "Backup your server on a host server using Borg.",
|
||||||
"fr": "Sauvegardez votre serveur sur un serveur distant avec Borg."
|
"fr": "Sauvegardez votre serveur sur un serveur distant avec Borg."
|
||||||
},
|
},
|
||||||
"version": "1.1.16~ynh1",
|
"version": "1.1.16~ynh16",
|
||||||
"url": "https://borgbackup.readthedocs.io",
|
"url": "https://borgbackup.readthedocs.io",
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"maintainer": {
|
"maintainer": {
|
||||||
|
@ -67,9 +67,13 @@
|
||||||
"name": "apps",
|
"name": "apps",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"ask": {
|
"ask": {
|
||||||
"en": "Which apps should Borg backup (list separated by comma or 'all')?",
|
"en": "Which apps should Borg backup ?",
|
||||||
"fr": "Quelles applications doivent être sauvegardées par Borg (liste séparée par virgule ou 'all' ?"
|
"fr": "Quelles applications doivent être sauvegardées par Borg ?"
|
||||||
},
|
},
|
||||||
|
"help":{
|
||||||
|
"en": "App list separated by comma. You can write 'all' to select all apps, even those installed after this borg app. You can also select all apps but some apps by writing 'exclude:' following by an app list separated by comma.",
|
||||||
|
"fr": "Liste d'applications séparées par des virgules. Vous pouvez écrire 'all' pour sélectionner toutes les apps, même celles installées après cette application borg. Vous pouvez aussi sélectionner toutes les apps sauf certaines en écrivant 'exclude:' suivi d'une liste d'applications séparées par des virgules."
|
||||||
|
},
|
||||||
"default": "all"
|
"default": "all"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -60,8 +60,12 @@ ynh_system_user_create --username=$app
|
||||||
# ACTIVATE BACKUP METHODS
|
# ACTIVATE BACKUP METHODS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
mkdir -p /etc/yunohost/hooks.d/backup
|
||||||
mkdir -p /etc/yunohost/hooks.d/backup_method
|
mkdir -p /etc/yunohost/hooks.d/backup_method
|
||||||
mkdir -p /usr/share/yunohost/backup_method
|
mkdir -p /usr/share/yunohost/backup_method
|
||||||
|
mkdir -p /var/log/${app}
|
||||||
|
chown -R $app:$app /var/log/${app}
|
||||||
|
chmod u+w /var/log/${app}
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP THE BACKUP METHOD
|
# SETUP THE BACKUP METHOD
|
||||||
|
@ -72,6 +76,8 @@ chmod go=--- "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
|
||||||
|
|
||||||
ynh_add_config --template="backup-with-borg" --destination="/usr/local/bin/backup-with-$app"
|
ynh_add_config --template="backup-with-borg" --destination="/usr/local/bin/backup-with-$app"
|
||||||
chmod u+x "/usr/local/bin/backup-with-$app"
|
chmod u+x "/usr/local/bin/backup-with-$app"
|
||||||
|
chown $app:$app "/usr/local/bin/backup-with-$app"
|
||||||
|
|
||||||
ynh_add_config --template="sudoer" --destination="/etc/sudoers.d/$app"
|
ynh_add_config --template="sudoer" --destination="/etc/sudoers.d/$app"
|
||||||
|
|
||||||
if [ ! -z "$server" ]; then
|
if [ ! -z "$server" ]; then
|
||||||
|
|
|
@ -37,12 +37,19 @@ install_borg_with_pip
|
||||||
|
|
||||||
mkdir -p /etc/yunohost/hooks.d/backup_method
|
mkdir -p /etc/yunohost/hooks.d/backup_method
|
||||||
mkdir -p /usr/share/yunohost/backup_method
|
mkdir -p /usr/share/yunohost/backup_method
|
||||||
|
mkdir -p /etc/yunohost/hooks.d/backup
|
||||||
|
mkdir -p /var/log/${app}
|
||||||
|
chown -R $app:$app /var/log/${app}
|
||||||
|
chmod u+w /var/log/${app}
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE FILES
|
# RESTORE FILES
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_restore
|
ynh_restore
|
||||||
|
chmod go=--- "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
|
||||||
|
chmod u+x "/usr/local/bin/backup-with-$app"
|
||||||
|
chown $app:$app "/usr/local/bin/backup-with-$app"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# ADVERTISE SERVICE IN ADMIN PANEL
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
||||||
|
|
|
@ -99,6 +99,7 @@ chmod go=--- "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
|
||||||
|
|
||||||
ynh_add_config --template="backup-with-borg" --destination="/usr/local/bin/backup-with-$app"
|
ynh_add_config --template="backup-with-borg" --destination="/usr/local/bin/backup-with-$app"
|
||||||
chmod u+x "/usr/local/bin/backup-with-$app"
|
chmod u+x "/usr/local/bin/backup-with-$app"
|
||||||
|
chown $app:$app "/usr/local/bin/backup-with-$app"
|
||||||
|
|
||||||
ynh_add_config --template="sudoer" --destination="/etc/sudoers.d/$app"
|
ynh_add_config --template="sudoer" --destination="/etc/sudoers.d/$app"
|
||||||
|
|
||||||
|
@ -117,6 +118,11 @@ ynh_add_config --template="systemd.timer" --destination="/etc/systemd/system/$ap
|
||||||
systemctl enable $app.timer --quiet
|
systemctl enable $app.timer --quiet
|
||||||
systemctl start $app.timer
|
systemctl start $app.timer
|
||||||
|
|
||||||
|
mkdir -p /etc/yunohost/hooks.d/backup
|
||||||
|
mkdir -p /var/log/${app}
|
||||||
|
chown -R $app:$app /var/log/${app}
|
||||||
|
chmod u+w /var/log/${app}
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC FINALIZATION
|
# GENERIC FINALIZATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Add table
Reference in a new issue