Backup on local disk without encryption
Warning: this kind of backup don’t protect you from fire, flood, theft because the backup is only on one place. This backup don’t protect your server from cryptolocker virus and some big manual mistakes.
This kind of backup can protect your server from some kinds of manual mistakes, hard drive/ssd/sd end of life, because your usb hard drive is an other storage.
Setup borg
apt-get install python3-pip python3-dev libacl1-dev libssl-dev liblz4-dev
pip3 install borgbackup
Create your local repository
Your disk should be mounted on server start
mkdir /media/DISK/backup
borg init --encryption=none /media/DISK/backup
Activate custom backup methods
mkdir -p /etc/yunohost/hooks.d/backup_method
mkdir -p /usr/share/yunohost/backup_method
Add the mylocalborg hooks
Don’t forget to replace DISK by your directory
/etc/yunohost/hooks.d/backup_method/05-mylocalborg
#!/bin/bash
set -e
repo=/media/DISK/backup
do_need_mount() {
true
}
do_backup() {
work_dir=$1
name=$2
repo=$3
size=$4
description=$5
LOGFILE=/var/log/backup_borg.log
ERRFILE=/var/log/backup_borg.err
current_date=$(date +"%d_%m_%y_%H:%M")
pushd $work_dir
borg create $repo::${name}_${current_date} ./ >> $LOGFILE 2>> $ERRFILE
popd
borg prune $repo -P ${name} --keep-daily=7 --keep-weekly=8 --keep-monthly=12 >> $LOGFILE 2>> $ERRFILE
}
do_mount() {
work_dir=$1
name=$2
repo=$3
size=$4
description=$5
LOGFILE=/var/log/backup_borg.log
ERRFILE=/var/log/backup_borg.err
borg mount $repo::$name $work_dir >> $LOGFILE 2>> $ERRFILE
}
work_dir=$2
name=$3
size=$5
description=$6
case "$1" in
need_mount)
do_need_mount $work_dir $name $repo $size $description
;;
backup)
do_backup $work_dir $name $repo $size $description
;;
mount)
do_mount
;;
*)
echo "hook called with unknown argument \`$1'" >&2
exit 1
;;
esac
exit 0
Test
yunohost backup create --ignore-apps --system conf_ldap -n test --method mylocalborg --debug --verbose
Run the backup each night
If it’s ok you can create a cron to run the command each night
/etc/cron.daily/yunohost-99-backup
#!/bin/bash
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
yunohost backup create $ignore_apps -n auto_conf --methods mylocalborg --system $(filter_hooks conf)
# Backup system data
yunohost backup create $ignore_apps -n auto_data --methods mylocalborg --system $(filter_hooks data)
# Backup all apps independently
for app in $(yunohost app list --installed -b | grep id: | cut -d: -f2); do
backup_methods=$(yunohost app setting $app backup_methods)
if [ -z "$backup_methods" ]; then
backup_methods=mylocalborg
fi
if [ "$backup_methods" != "none" ]; then
yunohost backup create $ignore_system -n auto_$app --methods $backup_methods --apps $app
fi
done
Don’t forget to give rights to execute !
chmod a+x /etc/cron.daily/yunohost-99-backup
Disable the backup for a particular app
yunohost app setting strut backup_methods -v none