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
|
||||
; Manifest
|
||||
server="domain.tld:22"
|
||||
ssh_user="sam"
|
||||
server="ssh://sam@domain.tld:22/~/backup"
|
||||
passphrase="APassphrase"
|
||||
conf=1
|
||||
data=1
|
||||
|
|
|
@ -8,7 +8,7 @@ if ssh-keygen -F "{{ server }}" >/dev/null ; then
|
|||
else
|
||||
BORG_RSH="ssh -i /root/.ssh/id_{{ app }}_ed25519 -oStrictHostKeyChecking=no "
|
||||
fi
|
||||
repo=ssh://{{ ssh_user }}@{{ server }}/~/backup #$4
|
||||
repo="{{ repository }}" #$4
|
||||
|
||||
do_need_mount() {
|
||||
true
|
||||
|
@ -23,15 +23,15 @@ do_backup() {
|
|||
|
||||
export BORG_PASSPHRASE
|
||||
export BORG_RSH
|
||||
work_dir=$1
|
||||
name=$2
|
||||
repo=$3
|
||||
size=$4
|
||||
description=$5
|
||||
work_dir="$1"
|
||||
name="$2"
|
||||
repo="$3"
|
||||
size="$4"
|
||||
description="$5"
|
||||
current_date=$(date +"%d_%m_%y_%H:%M")
|
||||
pushd $work_dir
|
||||
pushd "$work_dir"
|
||||
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; }'`
|
||||
# Speed in Kbps
|
||||
#speed=1000
|
||||
|
@ -44,37 +44,37 @@ This is an automated message from your beloved YunoHost server." | /usr/bin/mail
|
|||
fi
|
||||
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
|
||||
|
||||
# About thi _20 it's a crazy fix to avoid pruning wordpress__2
|
||||
# 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() {
|
||||
export BORG_PASSPHRASE
|
||||
export BORG_RSH
|
||||
work_dir=$1
|
||||
name=$2
|
||||
repo=$3
|
||||
size=$4
|
||||
description=$5
|
||||
borg mount $repo::$name $work_dir 2>&1 >/dev/null | log_with_timestamp
|
||||
work_dir="$1"
|
||||
name="$2"
|
||||
repo="$3"
|
||||
size="$4"
|
||||
description="$5"
|
||||
borg mount "$repo::$name" "$work_dir" 2>&1 >/dev/null | log_with_timestamp
|
||||
}
|
||||
|
||||
work_dir=$2
|
||||
name=$3
|
||||
work_dir="$2"
|
||||
name="$3"
|
||||
|
||||
size=$5
|
||||
description=$6
|
||||
size="$5"
|
||||
description="$6"
|
||||
|
||||
case "$1" in
|
||||
need_mount)
|
||||
do_need_mount $work_dir $name $repo $size $description
|
||||
do_need_mount "$work_dir" "$name" "$repo" "$size" "$description"
|
||||
;;
|
||||
backup)
|
||||
do_backup $work_dir $name $repo $size $description
|
||||
do_backup "$work_dir" "$name" "$repo" "$size" "$description"
|
||||
;;
|
||||
mount)
|
||||
do_mount
|
||||
|
|
|
@ -22,30 +22,16 @@
|
|||
"arguments": {
|
||||
"install" : [
|
||||
{
|
||||
"name": "server",
|
||||
"name": "repository",
|
||||
"type": "string",
|
||||
"ask": {
|
||||
"en": "What is the domain name of the host server where backups will be sent?",
|
||||
"fr": "Quel est le nom de domaine du serveur distant sur lequel seront envoyés les sauvegardes ?"
|
||||
"en": "In which borg repository location do you want to backup your files ?",
|
||||
"fr": "Dans quel repo borg souhaitez-vous sauvegarder vos fichiers ?"
|
||||
},
|
||||
"help":{
|
||||
"en": "If this host server does use a custom SSH port (different from 22), you can specify it with DOMAIN:PORT",
|
||||
"fr": "Si le serveur distant utilise un port particulier pour SSH (différent de 22), vous pouvez le spécifier avec 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."
|
||||
},
|
||||
"example": "host.serverb:22"
|
||||
},
|
||||
{
|
||||
"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"
|
||||
"example": "ssh://john@serverb.tld:22/~/backup"
|
||||
},
|
||||
{
|
||||
"name": "passphrase",
|
||||
|
|
|
@ -23,13 +23,19 @@ ynh_abort_if_errors
|
|||
export app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
# 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
|
||||
#=================================================
|
||||
|
||||
ynh_save_args server ssh_user passphrase on_calendar conf data apps
|
||||
server=""
|
||||
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
|
||||
|
|
|
@ -23,9 +23,6 @@ ynh_script_progression --message="Loading installation settings..."
|
|||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
server=$(ynh_app_setting_get $app server)
|
||||
ssh_user=$(ynh_app_setting_get $app ssh_user)
|
||||
|
||||
#=================================================
|
||||
# INSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
|
|
|
@ -15,21 +15,14 @@ source /usr/share/yunohost/helpers
|
|||
|
||||
export app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
export repository="$(ynh_app_setting_get $app repository)"
|
||||
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
|
||||
|
@ -51,6 +44,21 @@ ynh_clean_setup () {
|
|||
# Exit if an error occurs during the execution of the script
|
||||
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
|
||||
yunohost service remove $app.timer
|
||||
|
@ -71,11 +79,13 @@ fi
|
|||
#=================================================
|
||||
# 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"
|
||||
|
||||
#=================================================
|
||||
# CONFIGURE CRON
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring systemd timer..." --weight=1
|
||||
ynh_configure backup-with-borg "/usr/local/bin/backup-with-$app"
|
||||
chmod u+x "/usr/local/bin/backup-with-$app"
|
||||
ynh_add_systemd_config
|
||||
|
@ -86,6 +96,7 @@ systemctl start $app.timer
|
|||
#=================================================
|
||||
# ADVERTISE SERVICE IN ADMIN PANEL
|
||||
#=================================================
|
||||
ynh_script_progression --message="Exposing borg service in webadmin..." --weight=1
|
||||
|
||||
yunohost service add $app --description="Deduplicating backup program"
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue