mirror of
https://github.com/YunoHost-Apps/borg_ynh.git
synced 2024-09-03 18:16:05 +02:00
use env var BORG_REPO and BORG_LOGGING_CONF to manage repo and logs
This commit is contained in:
parent
9c033bf31f
commit
014972b810
1 changed files with 22 additions and 24 deletions
|
@ -5,7 +5,8 @@ borg="__INSTALL_DIR__/venv/bin/borg"
|
||||||
app="__APP__"
|
app="__APP__"
|
||||||
|
|
||||||
BORG_PASSPHRASE="$(yunohost app setting "$app" passphrase)"
|
BORG_PASSPHRASE="$(yunohost app setting "$app" passphrase)"
|
||||||
repo="$(yunohost app setting "$app" repository)" #$4
|
BORG_REPO="$(yunohost app setting "$app" repository)"
|
||||||
|
BORG_LOGGING_CONF="__INSTALL_DIR__/logging.conf"
|
||||||
|
|
||||||
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 "
|
||||||
|
@ -17,22 +18,16 @@ do_need_mount() {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGFILE=/var/log/backup_borg.err
|
|
||||||
log_with_timestamp() {
|
|
||||||
sed -e "s/^/[$(date +"%Y-%m-%d_%H:%M:%S")] /" | tee -a $LOGFILE
|
|
||||||
}
|
|
||||||
|
|
||||||
do_backup() {
|
do_backup() {
|
||||||
export BORG_PASSPHRASE
|
export BORG_PASSPHRASE
|
||||||
|
export BORG_REPO
|
||||||
export BORG_RSH
|
export BORG_RSH
|
||||||
|
export BORG_LOGGING_CONF
|
||||||
export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes
|
export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes
|
||||||
work_dir="$1"
|
work_dir="$1"
|
||||||
name="$2"
|
name="$2"
|
||||||
repo="$3"
|
size="$3"
|
||||||
size="$4"
|
description="$4"
|
||||||
description="$5"
|
|
||||||
current_date=$(date +"%Y-%m-%d_%H:%M")
|
|
||||||
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; }'`
|
||||||
|
@ -41,35 +36,38 @@ do_backup() {
|
||||||
# evaluated_time=$(($size / ($speed * 1000 / 8) / 3600))
|
# evaluated_time=$(($size / ($speed * 1000 / 8) / 3600))
|
||||||
echo "Hello,
|
echo "Hello,
|
||||||
|
|
||||||
Your first backup on $repo is starting.
|
Your first backup on $BORG_REPO is starting.
|
||||||
|
|
||||||
This is an automated message from your beloved YunoHost server." | /usr/bin/mail.mailutils -a "Content-Type: text/plain; charset=UTF-8" -s "[YNH] First backup is starting" "root"
|
This is an automated message from your beloved YunoHost server." | /usr/bin/mail.mailutils -a "Content-Type: text/plain; charset=UTF-8" -s "[YNH] First backup is starting" "root"
|
||||||
fi
|
fi
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
"$borg" create "$repo::_${name}-${current_date}" ./ 2>&1 >/dev/null | log_with_timestamp
|
# About the {now} placeholder:
|
||||||
popd
|
# https://borgbackup.readthedocs.io/en/stable/usage/create.html#description
|
||||||
|
# In the archive name, you may use the following placeholders: {now}, {utcnow}, {fqdn}, {hostname}, {user} and some others.
|
||||||
|
"$borg" create "::_${name}-{now}" "$work_dir"
|
||||||
|
|
||||||
# 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}-" --keep-hourly 2 --keep-daily=7 --keep-weekly=8 --keep-monthly=12 2>&1 >/dev/null | log_with_timestamp
|
"$borg" prune -P "_${name}-" --keep-hourly 2 --keep-daily=7 --keep-weekly=8 --keep-monthly=12
|
||||||
|
|
||||||
# Prune legacy archive name without error on wordpress/wordpress__2
|
# Prune legacy archive name without error on wordpress/wordpress__2
|
||||||
"$borg" prune "$repo" -P "${name}_" --keep-within 2m --keep-monthly=12 2>&1 >/dev/null | log_with_timestamp
|
"$borg" prune -P "${name}_" --keep-within 2m --keep-monthly=12
|
||||||
|
|
||||||
# We prune potential manual backup older than 1 year
|
# We prune potential manual backup older than 1 year
|
||||||
"$borg" prune "$repo" --keep-within 1y 2>&1 >/dev/null | log_with_timestamp
|
"$borg" prune --keep-within 1y
|
||||||
}
|
}
|
||||||
|
|
||||||
do_mount() {
|
do_mount() {
|
||||||
export BORG_PASSPHRASE
|
export BORG_PASSPHRASE
|
||||||
|
export BORG_REPO
|
||||||
export BORG_RSH
|
export BORG_RSH
|
||||||
|
export BORG_LOGGING_CONF
|
||||||
work_dir="$1"
|
work_dir="$1"
|
||||||
name="$2"
|
name="$2"
|
||||||
repo="$3"
|
size="$3"
|
||||||
size="$4"
|
description="$4"
|
||||||
description="$5"
|
"$borg" mount "::$name" "$work_dir"
|
||||||
"$borg" mount "$repo::$name" "$work_dir" 2>&1 >/dev/null | log_with_timestamp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
work_dir="$2"
|
work_dir="$2"
|
||||||
|
@ -80,13 +78,13 @@ 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" "$size" "$description"
|
||||||
;;
|
;;
|
||||||
backup)
|
backup)
|
||||||
do_backup "$work_dir" "$name" "$repo" "$size" "$description"
|
do_backup "$work_dir" "$name" "$size" "$description"
|
||||||
;;
|
;;
|
||||||
mount)
|
mount)
|
||||||
do_mount "$work_dir" "$name" "$repo" "$size" "$description"
|
do_mount "$work_dir" "$name" "$size" "$description"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "hook called with unknown argument \`$1'" >&2
|
echo "hook called with unknown argument \`$1'" >&2
|
||||||
|
|
Loading…
Add table
Reference in a new issue