Efficient backuping system using Borgbackup

BorgBackup (short: Borg) is a deduplicating backup program. Optionally, it supports compression and authenticated encryption.

Below, I present some trick for automatic backup using cron.

First, the main script:

#!/usr/bin/env sh
# -*- coding: UTF8 -*-
# Author: Guillaume Bouvier -- guillaume.bouvier@pasteur.fr
# https://research.pasteur.fr/en/member/guillaume-bouvier/
# 2017-04-21 10:57:53 (UTC+0200)
REPOSITORY=pi@82.231.223.163:/mnt/usb1/mantrisse_backup
REMOTEPATH=/home/pi/bin/borg
BORGPATH=/home/bougui/bin
nice -n 19 $BORGPATH/borg create -svp --compression lzma \
--remote-path $REMOTEPATH \
$REPOSITORY::{hostname}-{user}-{now:%Y-%m-%dT%H:%M:%S} \
/home/bougui \
--exclude '/home/bougui/.cache' \
--exclude '*.pyc'
# Keep 10 days of backups
nice -n 19 $BORGPATH/borg prune --remote-path $REMOTEPATH \
-v --list $REPOSITORY --prefix '{hostname}-{user}-' \
--keep-within=10d
view raw borgbackup.sh hosted with ❤ by GitHub

And the cron line to insert to crontab:

*/15 * * * * ionice -c 3 nice -n 19 sh /home/bougui/bin/borgbackup.sh > /dev/null 2>&1

Bonus: some convenient aliases:

alias borg-list="borg list --remote-path /home/pi/bin/borg pi@82.231.223.163:/mnt/usb1/mantrisse_backup"

borg-info () {
    borg info --remote-path /home/pi/bin/borg pi@82.231.223.163:/mnt/usb1/mantrisse_backup::$1
    }
If you want to ask me a question or leave me a message add @bougui505 in your comment.