Add initial source

dev
hkbakke 2016-12-22 17:59:19 +01:00
parent f34788ea60
commit e0ca054f3e
2 changed files with 87 additions and 0 deletions

67
src/borgwrapper.sh Executable file
View File

@ -0,0 +1,67 @@
#!/bin/bash
MODE="$1"
CONFIG="/etc/borgwrapper/config.sh"
print_usage () {
echo "Usage: borgwrapper.sh MODE"
echo ""
echo "arguments:"
echo " MODE backup|verify|unlock"
}
borg_backup () {
EXCLUDE_CMD=()
for EXCLUDE in ${EXCLUDES[@]}; do
EXCLUDE_CMD+=( --exclude "$EXCLUDE" )
done
# Backup all of /home and /var/www except a few
# excluded directories
$BORG create --info --stats \
--compression lz4 \
--numeric-owner \
"${REPO}"::"$(hostname)-$(date -u +'%Y%m%dT%H%M%SZ')" \
${PATHS[@]} \
${EXCLUDE_CMD[@]}
}
borg_prune () {
# Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly
# archives of THIS machine. --prefix `hostname`- is very important to
# limit prune's operation to this machine's archives and not apply to
# other machine's archives also.
$BORG prune --info --stats --list \
--prefix "$(hostname)-" \
--keep-daily=$KEEP_DAILY \
--keep-weekly=$KEEP_WEEKLY \
--keep-monthly=$KEEP_MONTHLY \
--keep-yearly=$KEEP_YEARLY \
"${REPO}"
}
borg_verify () {
$BORG check --show-rc "${REPO}"
}
borg_unlock () {
# Use if borg backup is not shut down cleanly
$BORG break-lock "${REPO}"
}
source "$CONFIG" || exit 1
export BORG_PASSPHRASE
if [[ $MODE == "backup" ]]; then
borg_backup
borg_prune
elif [[ $MODE == "verify" ]]; then
borg_verify
elif [[ $MODE == "unlock" ]]; then
borg_unlock
else
print_usage
fi

20
src/config.sh.example Normal file
View File

@ -0,0 +1,20 @@
BORG="/usr/bin/borg"
REPO="user@reposerver:/srv/borg/hostname"
BORG_PASSPHRASE="longandcomplexpassphrase"
PATHS=(
"/etc"
"/home"
"/root"
"/srv"
"/usr/local"
"/var/spool/cron/crontabs"
)
EXCLUDES=(
"sh:/home/**/.cache"
"/root/.cache"
"*.pyc"
)
KEEP_DAILY=31
KEEP_WEEKLY=0
KEEP_MONTHLY=24
KEEP_YEARLY=5