mirror of
https://github.com/YunoHost-Apps/borg_ynh.git
synced 2024-09-03 18:16:05 +02:00
[enh] Allow local repository
This commit is contained in:
parent
d62d4120fa
commit
ff0be0b044
6 changed files with 63 additions and 64 deletions
|
@ -1,7 +1,6 @@
|
||||||
;; Test complet
|
;; Test complet
|
||||||
; Manifest
|
; Manifest
|
||||||
server="domain.tld:22"
|
server="ssh://sam@domain.tld:22/~/backup"
|
||||||
ssh_user="sam"
|
|
||||||
passphrase="APassphrase"
|
passphrase="APassphrase"
|
||||||
conf=1
|
conf=1
|
||||||
data=1
|
data=1
|
||||||
|
|
|
@ -8,7 +8,7 @@ if ssh-keygen -F "{{ server }}" >/dev/null ; then
|
||||||
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
|
||||||
repo=ssh://{{ ssh_user }}@{{ server }}/~/backup #$4
|
repo="{{ repository }}" #$4
|
||||||
|
|
||||||
do_need_mount() {
|
do_need_mount() {
|
||||||
true
|
true
|
||||||
|
@ -23,15 +23,15 @@ do_backup() {
|
||||||
|
|
||||||
export BORG_PASSPHRASE
|
export BORG_PASSPHRASE
|
||||||
export BORG_RSH
|
export BORG_RSH
|
||||||
work_dir=$1
|
work_dir="$1"
|
||||||
name=$2
|
name="$2"
|
||||||
repo=$3
|
repo="$3"
|
||||||
size=$4
|
size="$4"
|
||||||
description=$5
|
description="$5"
|
||||||
current_date=$(date +"%d_%m_%y_%H:%M")
|
current_date=$(date +"%d_%m_%y_%H:%M")
|
||||||
pushd $work_dir
|
pushd "$work_dir"
|
||||||
set +e
|
set +e
|
||||||
if borg init -e repokey $repo ; then
|
if borg init -e repokey "$repo" ; then
|
||||||
#human_size=`echo $size | awk '{ suffix=" KMGT"; for(i=1; $1>1024 && i < length(suffix); i++) $1/=1024; print int($1) substr(suffix, i, 1), $3; }'`
|
#human_size=`echo $size | awk '{ suffix=" KMGT"; for(i=1; $1>1024 && i < length(suffix); i++) $1/=1024; print int($1) substr(suffix, i, 1), $3; }'`
|
||||||
# Speed in Kbps
|
# Speed in Kbps
|
||||||
#speed=1000
|
#speed=1000
|
||||||
|
@ -44,37 +44,37 @@ This is an automated message from your beloved YunoHost server." | /usr/bin/mail
|
||||||
fi
|
fi
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
borg create $repo::${name}_${current_date} ./ 2>&1 >/dev/null | log_with_timestamp
|
borg create "$repo::${name}_${current_date}" ./ 2>&1 >/dev/null | log_with_timestamp
|
||||||
popd
|
popd
|
||||||
|
|
||||||
# About thi _20 it's a crazy fix to avoid pruning wordpress__2
|
# About thi _20 it's a crazy fix to avoid pruning wordpress__2
|
||||||
# if you prune wordpress
|
# if you prune wordpress
|
||||||
borg prune $repo -P ${name}_20 --keep-hourly 2 --keep-daily=7 --keep-weekly=8 --keep-monthly=12 2>&1 >/dev/null | log_with_timestamp
|
borg prune "$repo" -P ${name}_20 --keep-hourly 2 --keep-daily=7 --keep-weekly=8 --keep-monthly=12 2>&1 >/dev/null | log_with_timestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
do_mount() {
|
do_mount() {
|
||||||
export BORG_PASSPHRASE
|
export BORG_PASSPHRASE
|
||||||
export BORG_RSH
|
export BORG_RSH
|
||||||
work_dir=$1
|
work_dir="$1"
|
||||||
name=$2
|
name="$2"
|
||||||
repo=$3
|
repo="$3"
|
||||||
size=$4
|
size="$4"
|
||||||
description=$5
|
description="$5"
|
||||||
borg mount $repo::$name $work_dir 2>&1 >/dev/null | log_with_timestamp
|
borg mount "$repo::$name" "$work_dir" 2>&1 >/dev/null | log_with_timestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
work_dir=$2
|
work_dir="$2"
|
||||||
name=$3
|
name="$3"
|
||||||
|
|
||||||
size=$5
|
size="$5"
|
||||||
description=$6
|
description="$6"
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
need_mount)
|
need_mount)
|
||||||
do_need_mount $work_dir $name $repo $size $description
|
do_need_mount "$work_dir" "$name" "$repo" "$size" "$description"
|
||||||
;;
|
;;
|
||||||
backup)
|
backup)
|
||||||
do_backup $work_dir $name $repo $size $description
|
do_backup "$work_dir" "$name" "$repo" "$size" "$description"
|
||||||
;;
|
;;
|
||||||
mount)
|
mount)
|
||||||
do_mount
|
do_mount
|
||||||
|
|
|
@ -22,30 +22,16 @@
|
||||||
"arguments": {
|
"arguments": {
|
||||||
"install" : [
|
"install" : [
|
||||||
{
|
{
|
||||||
"name": "server",
|
"name": "repository",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"ask": {
|
"ask": {
|
||||||
"en": "What is the domain name of the host server where backups will be sent?",
|
"en": "In which borg repository location do you want to backup your files ?",
|
||||||
"fr": "Quel est le nom de domaine du serveur distant sur lequel seront envoyés les sauvegardes ?"
|
"fr": "Dans quel repo borg souhaitez-vous sauvegarder vos fichiers ?"
|
||||||
},
|
},
|
||||||
"help":{
|
"help":{
|
||||||
"en": "If this host server does use a custom SSH port (different from 22), you can specify it with DOMAIN:PORT",
|
"en": "You can specify a local by giving direct path or a remote repo in this format: ssh://USER@DOMAIN.TLD:PORT/~/backup . For remote user, it is not meant to be an existing user on the guest server. Instead, it will be created *on the host server* during the installation of the Borg Server App."
|
||||||
"fr": "Si le serveur distant utilise un port particulier pour SSH (différent de 22), vous pouvez le spécifier avec DOMAIN:PORT"
|
|
||||||
},
|
},
|
||||||
"example": "host.serverb:22"
|
"example": "ssh://john@serverb.tld:22/~/backup"
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "ssh_user",
|
|
||||||
"type": "string",
|
|
||||||
"ask": {
|
|
||||||
"en": "Which SSH username should be used to connect to the host server?",
|
|
||||||
"fr": "Quel utilisateur faut-il utiliser pour se connecter au serveur distant ?"
|
|
||||||
},
|
|
||||||
"help":{
|
|
||||||
"en": "It is not meant to be an existing user on this guest server. Instead, it will be created *on the host server* during the installation of the Borg Server App.",
|
|
||||||
"fr": "Cet utilisateur n'est pas censé exister sur ce serveur. Il sera créé *sur le serveur distant* lors de l'installation de l'App Borg Server sur celui-ci."
|
|
||||||
},
|
|
||||||
"example": "borgservera"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "passphrase",
|
"name": "passphrase",
|
||||||
|
|
|
@ -23,13 +23,19 @@ ynh_abort_if_errors
|
||||||
export app=$YNH_APP_INSTANCE_NAME
|
export app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Retrieve arguments
|
# Retrieve arguments
|
||||||
ynh_export server ssh_user passphrase on_calendar conf data apps
|
ynh_export repository passphrase on_calendar conf data apps
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STORE SETTINGS FROM MANIFEST
|
# STORE SETTINGS FROM MANIFEST
|
||||||
#=================================================
|
#=================================================
|
||||||
|
server=""
|
||||||
ynh_save_args server ssh_user passphrase on_calendar conf data apps
|
if [[ $repository == *"@"* ]]; then
|
||||||
|
server=$(echo "$repository" | cut -d"@" -f2 | cut -d"/" -f1)
|
||||||
|
if [[ $server == *":"* ]]; then
|
||||||
|
server="[$(echo "$server" | cut -d":" -f1)]:$(echo "$server" | cut -d":" -f2)"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
ynh_save_args repository server passphrase on_calendar conf data apps
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# INSTALL DEPENDENCIES
|
# INSTALL DEPENDENCIES
|
||||||
|
|
|
@ -23,9 +23,6 @@ ynh_script_progression --message="Loading installation settings..."
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
server=$(ynh_app_setting_get $app server)
|
|
||||||
ssh_user=$(ynh_app_setting_get $app ssh_user)
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# INSTALL DEPENDENCIES
|
# INSTALL DEPENDENCIES
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -15,21 +15,14 @@ source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
export app=$YNH_APP_INSTANCE_NAME
|
export app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
export server=$(ynh_app_setting_get $app server)
|
export repository="$(ynh_app_setting_get $app repository)"
|
||||||
export ssh_user=$(ynh_app_setting_get $app ssh_user)
|
export server="$(ynh_app_setting_get $app server)"
|
||||||
export passphrase=$(ynh_app_setting_get $app passphrase)
|
export ssh_user="$(ynh_app_setting_get $app ssh_user)"
|
||||||
export on_calendar=$(ynh_app_setting_get $app on_calendar)
|
export passphrase="$(ynh_app_setting_get $app passphrase)"
|
||||||
export conf=$(ynh_app_setting_get $app conf)
|
export on_calendar="$(ynh_app_setting_get $app on_calendar)"
|
||||||
export data=$(ynh_app_setting_get $app data)
|
export conf="$(ynh_app_setting_get $app conf)"
|
||||||
export apps=$(ynh_app_setting_get $app apps)
|
export data="$(ynh_app_setting_get $app data)"
|
||||||
|
export apps="$(ynh_app_setting_get $app apps)"
|
||||||
export server=$(ynh_app_setting_get $app server)
|
|
||||||
export ssh_user=$(ynh_app_setting_get $app ssh_user)
|
|
||||||
export passphrase=$(ynh_app_setting_get $app passphrase)
|
|
||||||
export on_calendar=$(ynh_app_setting_get $app on_calendar)
|
|
||||||
export conf=$(ynh_app_setting_get $app conf)
|
|
||||||
export data=$(ynh_app_setting_get $app data)
|
|
||||||
export apps=$(ynh_app_setting_get $app apps)
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CHECK IF AN UPGRADE IS NEEDED
|
# CHECK IF AN UPGRADE IS NEEDED
|
||||||
|
@ -51,6 +44,21 @@ ynh_clean_setup () {
|
||||||
# Exit if an error occurs during the execution of the script
|
# Exit if an error occurs during the execution of the script
|
||||||
ynh_abort_if_errors
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# ENSURE DOWNWARD COMPATIBILITY
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
||||||
|
|
||||||
|
if [ -z "$repository" ]; then
|
||||||
|
repository="ssh://$ssh_user@$server/~/backup"
|
||||||
|
server=$(echo "$repository" | cut -d"@" -f2 | cut -d"/" -f1)
|
||||||
|
if [[ $server == *":"* ]]; then
|
||||||
|
server="[$(echo "$server" | cut -d":" -f1)]:$(echo "$server" | cut -d":" -f2)"
|
||||||
|
fi
|
||||||
|
ynh_app_setting_set $app repository "$repository"
|
||||||
|
ynh_app_setting_set $app server "$server"
|
||||||
|
ynh_app_setting_delete $app ssh_user
|
||||||
|
fi
|
||||||
|
|
||||||
if grep "borg.timer" /etc/yunohost/services.yml > /dev/null ; then
|
if grep "borg.timer" /etc/yunohost/services.yml > /dev/null ; then
|
||||||
yunohost service remove $app.timer
|
yunohost service remove $app.timer
|
||||||
|
@ -71,11 +79,13 @@ fi
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP THE BACKUP METHOD
|
# SETUP THE BACKUP METHOD
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_script_progression --message="Setting up backup method..." --weight=1
|
||||||
ynh_configure backup_method "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
|
ynh_configure backup_method "/etc/yunohost/hooks.d/backup_method/05-${app}_app"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CONFIGURE CRON
|
# CONFIGURE CRON
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_script_progression --message="Configuring systemd timer..." --weight=1
|
||||||
ynh_configure backup-with-borg "/usr/local/bin/backup-with-$app"
|
ynh_configure backup-with-borg "/usr/local/bin/backup-with-$app"
|
||||||
chmod u+x "/usr/local/bin/backup-with-$app"
|
chmod u+x "/usr/local/bin/backup-with-$app"
|
||||||
ynh_add_systemd_config
|
ynh_add_systemd_config
|
||||||
|
@ -86,6 +96,7 @@ systemctl start $app.timer
|
||||||
#=================================================
|
#=================================================
|
||||||
# ADVERTISE SERVICE IN ADMIN PANEL
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
||||||
#=================================================
|
#=================================================
|
||||||
|
ynh_script_progression --message="Exposing borg service in webadmin..." --weight=1
|
||||||
|
|
||||||
yunohost service add $app --description="Deduplicating backup program"
|
yunohost service add $app --description="Deduplicating backup program"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue