Commit 177b4267 authored by lavamind's avatar lavamind

Merge branch 'borg_support' into 'master'

Borg support (rebased)

See merge request !10
parents e0b43754 0d9b1089
......@@ -20,6 +20,8 @@ etc/cron.d/backupninja
etc/logrotate.d/backupninja
examples/Makefile
handlers/Makefile
handlers/borg
handlers/borg.helper
handlers/dup
handlers/dup.helper
handlers/ldap
......
......@@ -59,3 +59,5 @@ Daniel Lo Nigro <daniel@dan.cx> -- Dropbox support for Duplicity
Matthijs Wensveen <matthijs.wensveen@gmail.com> -- fix symmetric encryption in dup handler
ulrich <ulrich@habmalnefrage.de> -- Added validation check for when
Romain Dessort <romain@univers-libre.net> -- Fix list of devices when dumping partition tables
Guillaume Subiron <ben@wainei.net> -- borg handler
Jerome Charaoui <jerome@riseup.net> -- borg handler
......@@ -2,6 +2,9 @@ version 1.0.3 -- UNRELEASED
documentation changes
· Fix typos in README.md and manpages. Thank you, Lintian!
handler changes
borg:
. Added initial support
version 1.0.2 -- September 05, 2017
handler changes
......
......@@ -15,7 +15,7 @@ Requirements:
Recommended:
rdiff-backup duplicity rsync gzip hwinfo sfdisk cryptsetup flashrom hwinfo
rdiff-backup duplicity rsync borgbackup gzip hwinfo sfdisk cryptsetup flashrom hwinfo
To install backupninja, simply do the following:
......
......@@ -33,7 +33,7 @@ The following backup types are supported:
with an unpriviledged backup user
- backup of mysql databases (via mysqlhotcopy and mysqldump)
- basic system and hardware info
- encrypted remote backups (via duplicity)
- encrypted remote backups (via duplicity or borgbackup)
- backup of subversion repositories
Installation
......@@ -107,6 +107,7 @@ file in `/etc/backup.d` according to the file's suffix:
- `.sh`: run this file as a shell script.
- `.rdiff`: filesystem backup (using rdiff-backup)
- `.dup`: filesystem backup (using duplicity)
- `.borg`: filesystem backup (using borg)
- `.mysql`: backup mysql databases
- `.pgsql`: backup PostgreSQL databases
- `.sys`: general hardware, partition, and system reports.
......
EXAMPLES = example.dup example.maildir example.makecd example.mysql \
example.pgsql example.rdiff example.rsync example.sh \
example.svn example.sys example.trac
EXAMPLES = example.borg example.dup example.maildir example.makecd \
example.mysql example.pgsql example.rdiff example.rsync \
example.sh example.svn example.sys example.trac
EXTRA_DIST = $(EXAMPLES)
......
##
## This is an example borgbackup configuration file.
##
## Here you can find all the possible borgbackup options, details of
## what the options provide and possible settings. The defaults are set
## as the commented out option, uncomment and change when
## necessary. Options which are uncommented in this example do not have
## defaults, and the settings provided are recommended.
##
## The defaults are useful in most cases, just make sure to configure the
## destination host and user.
##
## default is 0, but set to 19 if you want to lower the priority.
## an example setting would be:
## nicelevel = 19
##
## Default
# nicelevel = 0
## default is yes. set to no to skip the test if the remote host is alive
##
## Default:
# testconnect = yes
## default is not to limit bandwidth.
## set to a number in kiBytes/second to limit bandwidth usage.
##
## Default:
# bwlimit = 0
######################################################
## source section
## (where the files to be backed up are coming from)
[source]
## default is to initialize the backup repository if absent
## set to no to skip this step
##
## Default:
# init = yes
## A few notes about includes and excludes:
## 1. include paths do not support any kind of pattern matching
## 2. exclude paths support several types of pattern matching, the default being
## shell-style matching, where, for example, '*' matches any number of
## characters. for more info, see : borg help patterns
## 3. Symlinks are preserved (not followed).
##
## for more info see : borg help patterns
##
## files to include in the backup
include = /opt
include = /srv
include = /etc
include = /root
include = /home
include = /usr/local
include = /var
## files to exclude from the backup
exclude = /var/lock
exclude = /var/run
exclude = /var/cache
exclude = /var/tmp
exclude = /var/lib/mongodb/journal
exclude = /var/lib/clamav
exclude = /var/lib/mlocate
exclude = /var/lib/postgresql
exclude = /var/lib/mysql
## define extra command-line options for the "borg create" operation.
##
## Example:
## create_options = --exclude-caches
##
## for more info see : borg help create
##
## Default:
# create_options =
## whether to prune (remove) older backups
##
## Default:
# prune = yes
## keep all backups within this time frame.
## must be defined as a number followed by one of the
## following characters: "H", "d", "w", "m", "y"
##
## this option will be ignored if set to 0
##
## the default is to keep all backups made within the
## last 30 days
##
## Default:
# keep = 30d
## define extra command-line options for the "borg prune" operation.
##
## Example:
## prune_options = --keep-daily=7 --keep-weekly=4 --keep-monthly=6
##
## for more info see : borg help prune
##
## Default:
# prune_options =
######################################################
## destination section
## (where the files are copied to)
[dest]
## put the backups under this directory, this must be set!
## an example setting would be:
## directory = /backups
##
## Default:
# directory =
## the machine which will receive the backups.
## an example setting would be:
## host = backuphost
##
## set host = localhost for local backups (no ssh)
##
## Default
# host =
## make the files owned by this user. you must be able to
## `su -c "ssh backupuser@backhost"` without specifying a password.
## an example setting would be:
## user = backupuser
##
## Default:
# user =
## archive name, should be unique every day.
## Format tags available :
## {now}, {utcnow}, {fqdn}, {hostname}, {user}, {pid}
##
## for more info see : borg help create
##
## Default:
# archive = {now:%Y-%m-%dT%H:%M:%S}
## compression algorithm
## can be "none", "lz4", "zstd[,L]", "zlib[,L]", "lzma[,L]", "auto,C[,L]".
## - "none" stands for "no compression"
## - "lz4" offers very high speed, very low compression
## - "zstd" is a modern wide-range algorithm
## - "zlib" offers medium speed, medium compression
## - "lzma" offers low speed, high compression
## - "auto,C" will use a heuristic to decide whether to compress using
## selected algorithm C
##
## for more info see : borg help compression
##
## Default:
# compression = lz4
## encryption mode to use for repository creation
##
## common options are "none", "repokey" or "keyfile"
## - "none" = no encryption
## - "repokey" = encryption with key stored inside the repository
## - "keyfile" = encryption with key stored in ~/.config/borg/keys/
##
## for other options and more info, see : borg help init
##
## Default:
# encryption = none
## passphrase of the key used for repository encryptions
##
## must be set if encryption is not "none"
## encryption is disabled by default
##
## Default:
# passphrase =
HANDLERS = dup dup.helper maildir makecd \
HANDLERS = borg borg.helper dup dup.helper maildir makecd \
makecd.helper mysql mysql.helper pgsql pgsql.helper rdiff \
rdiff.helper rsync sh svn sys sys.helper trac tar tar.helper
DIST_HANDLERS = dup.in dup.helper.in maildir.in makecd.in \
DIST_HANDLERS = borg.in borg.helper.in dup.in dup.helper.in maildir.in makecd.in \
makecd.helper.in mysql.in mysql.helper.in pgsql.in pgsql.helper.in rdiff.in \
rdiff.helper.in rsync.in sh.in svn.in sys.in sys.helper.in trac.in tar.in tar.helper.in wget
......@@ -18,6 +18,14 @@ edit = sed \
pkgdata_DATA = $(HANDLERS)
borg: $(srcdir)/borg.in
rm -f borg
$(edit) $(srcdir)/borg.in > borg
borg.helper: $(srcdir)/borg.helper.in
rm -f borg.helper
$(edit) $(srcdir)/borg.helper.in > borg.helper
dup: $(srcdir)/dup.in
rm -f dup
$(edit) $(srcdir)/dup.in > dup
......
This diff is collapsed.
# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
# vim: set filetype=sh sw=3 sts=3 expandtab autoindent:
#
# borg handler script for backupninja
# requires borgbackup
#
# Guillaume Subiron, Sysnove, 2016
#
# Copyright 2016 Guillaume Subiron <guillaume@sysnove.fr>
#
# This work is free. You can redistribute it and/or modify it under the
# terms of the Do What The Fuck You Want To Public License, Version 2,
# as published by Sam Hocevar. See the http://www.wtfpl.net/ file for more details.
#
#
export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes
export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=yes
### GET CONFIG ###
getconf testconnect yes
getconf nicelevel 0
getconf bwlimit
setsection source
getconf init yes
getconf include
getconf exclude
getconf create_options
getconf prune yes
getconf keep 30d
getconf prune_options
setsection dest
getconf user
getconf host
getconf directory
# strip trailing /
directory=${directory%/}
getconf archive {now:%Y-%m-%dT%H:%M:%S}
getconf compression lz4
getconf encryption none
getconf passphrase
export BORG_PASSPHRASE="$passphrase"
### CHECK CONFIG ###
# destination specific checks
[ "$directory" != "" ] || fatal "Destination directory not set"
if [ "$host" != "localhost" ]; then
execstr_repository="ssh://${user}@${host}${directory}"
else
execstr_repository="$directory"
fi
execstr_archive="$archive"
# check the connection at the source and destination
[ -n "$test" ] || test=0
if [ "$host" != "localhost" ] && ([ "$testconnect" = "yes" ] || [ "${test}" -eq 1 ]); then
debug "ssh -o PasswordAuthentication=no $host -l $user 'echo -n 1'"
local ret=`ssh -o PasswordAuthentication=no $host -l $user 'echo -n 1'`
if [ "$ret" = 1 ]; then
debug "Connected to $host as $user successfully"
else
teststr="borg list --show-rc -v $execstr_repository"
debug "$teststr"
output=`su -c "$teststr" 2>&1`
if echo "$output" | grep "terminating with success status" ; then
debug "Connected to $host as $user successfully (forced command)"
else
if echo "$output" | grep -E "Repository.+does not exist" ; then
debug "Connected to $host as $user successfully (forced command)"
else
fatal "Can't connect to $host as $user."
fi
fi
fi
fi
### INIT IF NEEDED ###
if [ "$init" == "yes" ]; then
initstr="borg init --encryption=$encryption $execstr_repository"
debug "$initstr"
if [ $test = 0 ]; then
output="`su -c "$initstr" 2>&1`"
if [ $? = 2 ]; then
debug $output
info "Repository was already initialized"
else
warning $output
warning "Repository has been initialized"
fi
fi
fi
### EXECUTE ###
execstr="borg create --stats --compression $compression"
set -o noglob
# includes
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for i in $include; do
includes="${includes} '$i'"
done
IFS=$SAVEIFS
# excludes
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for i in $exclude; do
excludes="${excludes} --exclude '$i'"
done
IFS=$SAVEIFS
set +o noglob
if [ ! -z $bwlimit ]; then
execstr="${execstr} --remote-ratelimit=${bwlimit}"
fi
if [ ! -z $create_options ]; then
execstr="${execstr} ${create_options}"
fi
# include client-part and server-part
execstr="${execstr} ${excludes} $execstr_repository::$execstr_archive ${includes}"
debug "$execstr"
if [ $test = 0 ]; then
output=`nice -n $nicelevel su -c "$execstr" 2>&1`
if [ $? = 0 ]; then
debug $output
info "Successfully finished backing up source $label"
else
error $output
fatal "Failed backuping up source $label"
fi
fi
### REMOVE OLD BACKUPS ###
# borg prune
if [ "$prune" == "yes" ]; then
if [ ! "$keep" == "0" ]; then
prune_options="${prune_options} --keep-within=${keep}"
fi
prunestr="borg prune $prune_options $execstr_repository"
debug "$prunestr"
if [ $test = 0 ]; then
output="`su -c "$prunestr" 2>&1`"
if [ $? = 0 ]; then
debug $output
info "Removing old backups succeeded."
else
warning $output
warning "Failed removing old backups."
fi
fi
fi
unset BORG_PASSPHRASE
return 0
......@@ -33,6 +33,8 @@ run this file as a shell script.
backup action for rdiff-backup.
.IP .dup
backup action for duplicity.
.IP .borg
backup action for borgbackup.
.IP .maildir
backup action for slow, incremental rsyncs of tens of thousands of maildirs.
.IP .mysql
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment