Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Borg #1037

Merged
merged 5 commits into from
Oct 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/rear-presentation.adoc
Expand Up @@ -88,7 +88,7 @@ recovery process until the system runs:

* Back-up backends
- IBM TSM, HP DataProtector, Symantec NetBackup,
FDR/Upstream, Bacula, tar, rsync
FDR/Upstream, Bacula, tar, rsync, Borg


== How is Relax-and-Recover used ?
Expand Down
5 changes: 4 additions & 1 deletion doc/rear.8.adoc
Expand Up @@ -29,7 +29,7 @@ OBDR tape, USB or eSATA storage), a variety of network protocols (incl.
sftp, ftp, http, nfs, cifs) for storage and backup as well as a multitude
of backup strategies (incl. IBM Tivoli Storage Manager, HP DataProtector,
Symantec NetBackup, EMC NetWorker, FDR/Upstream, NovaBACKUP DC, Bareos,
Bacula, rsync, rbme). This results in a bootable image that is capable of
Bacula, rsync, rbme, Borg). This results in a bootable image that is capable of
booting via PXE, DVD/CD, bootable tape or virtual provisioning.

Relax-and-Recover was designed to be easy to set up, requires no maintenance
Expand Down Expand Up @@ -296,6 +296,9 @@ Use Open Source backup solution BACULA to restore the data.
BACKUP=*DUPLICITY*::
Use encrypted bandwidth-efficient backup solution using the rsync algorithm to restore the data.

BACKUP=*BORG*::
Use BorgBackup (short Borg) a deduplicating backup program to restore the data.

The following +BACKUP+ methods are _internal_ of Relax-and-Recover:

BACKUP=*NETFS*::
Expand Down
3 changes: 2 additions & 1 deletion doc/user-guide/01-introduction.adoc
Expand Up @@ -14,7 +14,7 @@ Currently Relax-and-Recover supports various boot media (incl. ISO, PXE,
OBDR tape, USB or eSATA storage), a variety of network protocols (incl.
sftp, ftp, http, nfs, cifs) as well as a multitude of backup strategies
(incl. IBM TSM, HP Data Protector, Symantec NetBackup, EMC NetWorker [Legato],
SEP Sesam, Galaxy [Simpana], Bacula, Bareos, RBME, rsync, duplicity).
SEP Sesam, Galaxy [Simpana], Bacula, Bareos, RBME, rsync, duplicity, Borg).

Relax-and-Recover was designed to be easy to set up, requires no maintenance
and is there to assist when disaster strikes. Its setup-and-forget nature
Expand Down Expand Up @@ -106,5 +106,6 @@ Relax-and-Recover has a wide range of features:
- Beep/UID led/USB suspend integration
- Migrate UUID from disks and MAC addressed from network interfaces
- Integrates with Disaster Recovery Linux Manager (DRLM)
- Data deduplication with Borg as backend


3 changes: 3 additions & 0 deletions doc/user-guide/03-configuration.adoc
Expand Up @@ -117,6 +117,9 @@ Use CommVault Galaxy (7 and probably newer)
BACKUP=GALAXY10::
Use CommVault Galaxy 10 (or Simpana 10)

BACKUP=BORG::
Use BorgBackup (short Borg) a deduplicating backup program to restore the data.

BACKUP=NETFS::
Use Relax-and-Recover internal backup with tar or rsync (or similar). By adding the following settings in the configuration file -
+BACKUP_TYPE=incremental+ and +FULLBACKUPDAY="Mon"+, incremental backups (only with +tar+!) will be activated.
Expand Down
52 changes: 52 additions & 0 deletions doc/user-guide/04-scenarios.adoc
Expand Up @@ -77,6 +77,58 @@ OUTPUT=OBDR
TAPE_DEVICE=/dev/nst0
----


== Bootable ISO with Borg
- Install Borg backup (https://borgbackup.readthedocs.io/en/stable/installation.html) to _/usr/sbin/borg_.
- Setup ssh key infrastructure for user that will be running backup.
Issuing following command must work without any password prompts or remote host identity confirmation:

`ssh <BORG_USERNAME>@<BORG_HOST>`

- Edit _local.conf_ / _site.conf_ as follows:
[source,bash]
----
OUTPUT=ISO
OUTPUT_URL=nfs://<server_to_store_iso>/<directory/to/store/iso>

BACKUP=BORG
BORG_HOST=<server_to_store_backup>
BORG_USERNAME=<user_to_run_backup>
BORG_REPO=</path/to/borg/repository>
----
- Setting automatic retention strategy:
(https://borgbackup.readthedocs.io/en/stable/usage.html#borg-prune)
[source,bash]
----
BORG_PRUNE_HOURLY=
BORG_PRUNE_DAILY=
BORG_PRUNE_WEEKLY=
BORG_PRUNE_MONTHLY=
BORG_PRUNE_YEARLY=
----

- Executing `rear mkbackup` will create bootable ISO image of your system and start Borg backup process. It will also prune old backups if BORG_PRUNE* is set.
- To recover your system, boot ISO and trigger `rear recover`, you will be prompted which archive to recover from Borg repository, once ReaR finished with layout configuration.
```
...
Disk layout created.
Starting Borg restore

=== Borg archives list ===
Host: beta
Repository: /mnt/rear/borg/alfa

[1] rear_1 Sun, 2016-10-16 14:08:16
[2] rear_2 Sun, 2016-10-16 14:32:11

[3] Exit

Choose archive to recover from:


```


== Using Relax-and-Recover with USB storage devices
Using USB devices with Relax-and-Recover can be appealing for several reasons:

Expand Down
2 changes: 2 additions & 0 deletions doc/user-guide/09-design-concepts.adoc
Expand Up @@ -63,6 +63,7 @@ The configuration must define the +BACKUP+ and +OUTPUT+ methods. Valid choices a
|RSYNC | BACKUP | Use rsync to remote location | done
|RBME | BACKUP | Use Rsync Backup Made Easy | done
|FDRUPSTREAM | BACKUP | Use FDR/Upstream | done
|BORG | BACKUP | Use Borg | done
| | | |
|ISO | OUTPUT | Write result to ISO9660 image | done
|OBDR | OUTPUT | Create OBDR Tape | done
Expand Down Expand Up @@ -238,6 +239,7 @@ The various stages and modules communicate via standardized environment variable
|SHARE_DIR |STRING (RO) |Shared data dir |'/usr/share/rear/'
|BUILD_DIR |STRING (RO) |Build directory |'/tmp/rear.$$/'
|ROOTFS_DIR |STRING (RO) |Root FS directory for rescue system |'/tmp/rear.$$/initrd/'
|TARGET_FS_ROOT |STRING (RO) |Directory for restore |'/mnt/local'
|PROGS |LIST |Program files to copy |+bash ip route grep ls+ ...
|MODULES |LIST |Modules to copy |+af_unix e1000 ide-cd+ ...
|COPY_AS_IS |LIST |Files (with path) to copy as-is |'/etc/localtime' ...
Expand Down
6 changes: 3 additions & 3 deletions doc/user-guide/10-integrating-external-backup.adoc
Expand Up @@ -2,7 +2,7 @@

Relax-and-Recover can be used only to restore the disk layout of your system and boot loader. However, that means you are responsible for taking backups. And, more important, to restore these before you reboot recovered system.

However, we have sucessfully already integrated external backup programs within rear, such as Netbackup, EMC NetWorker, Tivoli Storage Manager, Data Protetctor to name a few commercial backup programs. Furthermore, open source external backup programs which are also working with rear are, Bacula, Bareos and Duplicity to name the most known ones.
However, we have sucessfully already integrated external backup programs within rear, such as Netbackup, EMC NetWorker, Tivoli Storage Manager, Data Protetctor to name a few commercial backup programs. Furthermore, open source external backup programs which are also working with rear are, Bacula, Bareos, Duplicity and Borg to name the most known ones.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

successfully
and i guess the comma after "are" should not be there?


Ah, my backup program which is the best of course, is not yet integrated within rear. How shall we proceed to make your backup program working with rear? This is a step by step approach.

Expand Down Expand Up @@ -36,15 +36,15 @@ Start with the default configuration file of rear:
default.conf:COPY_AS_IS_NBU=( /usr/openv/bin/vnetd /usr/openv/bin/vopied /usr/openv/lib /usr/openv/netbackup /usr/openv/var/auth/[mn]*.txt )
default.conf:COPY_AS_IS_EXCLUDE_NBU=( "/usr/openv/netbackup/logs/*" "/usr/openv/netbackup/bin/bpjava*" "/usr/openv/netbackup/bin/xbp" )
default.conf:PROGS_NBU=( )


What does this learn you?

* you need to define a backup method name, e.g. `BACKUP=NBU` (must be unique within rear!)
* define some new variables to automatically copy executables into the rear rescue image, and one to exclude stuff which is not required by the recovery (this means you have to play with it and fine-tune it)
* finally, define a place holder array for your backup programs (is empty to start with).

Now, you have defined a new BACKUP scheme name, right? As an example take the name BURP (http://burp.grke.org/).
Now, you have defined a new BACKUP scheme name, right? As an example take the name BURP (http://burp.grke.org/).

Define in /usr/share/rear/conf/default:

Expand Down
61 changes: 61 additions & 0 deletions usr/share/rear/backup/BORG/default/10_load_init_archives.sh
@@ -0,0 +1,61 @@
# This file is part of Relax-and-Recover, licensed under the GNU General
# Public License. Refer to the included COPYING for full text of license.
#
# 10_load_archives.sh

# Check if BORG_ARCHIVE_PREFIX is correctly set
# Using '_' could result to some unpleasant site effects,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

side

# as this character is used as delimiter in latter `for' loop ...
# Excluding other non aplhanum characeters is not really necessary,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alphanumeric
characters

# however it looks safer to me.
# I'm sure archive handling can be done better, but no time for it now ...
if [[ $BORG_ARCHIVE_PREFIX =~ [^a-zA-Z0-9] ]] \
|| [[ -z $BORG_ARCHIVE_PREFIX ]]; then
Error "BORG_ARCHIVE_PREFIX must be alphanumeric non emply value only"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-empty

fi

# Do we have Borg binary?
has_binary borg
StopIfError "Could not find Borg binary"

# Query Borg server for repoitory information and store it to archive_cache.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repository

# This should avoid repeatingly quering Borg server, which could be slow.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

querying

archive_cache=$TMP_DIR/borg_archive
borg list $BORG_USERNAME@$BORG_HOST:$BORG_REPO 2> /dev/null > $archive_cache

# If $rc == 0 we have repository present, but it is empty
# In my tests, Borg returned RC = 2, when repository was non-existent or
# due connection problems (bad hostname, etc ...)
# If repository is present but empty, rc will be set to 0, and initialization
# will be skipped

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general, please globally review this yourself: add a dot at the end of a sentence.

rc=$?

# TODO: Add security options for Borg repository initialization ...
# This might be an Borg connection error, or missing repository

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a

# If initialization succeedes, we can cast out connection problems

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

succeeds?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never heard "cast out". "rule out" seems more widespread.

if [ $rc -ne 0 ]; then
Log "Creating new Borg repository $BORG_REPO on $BORG_HOST"
borg init -e none $BORG_USERNAME@$BORG_HOST:$BORG_REPO

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no encryption is a bad default, esp. if hardcoded. open a ticket about this?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

be careful: env vars starting with BORG_ are used by borg. e.g. borg will read BORG_REPO and expect it to be a full repo URL (or path).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ThomasWaldmann
Fully agree with no encryption, it will be added soon.
Thanks for the hint with variables.
@gdha @jsmeix any suggestions for new/better variable names? BORGB_* or BORGBACKUP_* maybe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any variable prefix is o.k. for me for rear
as long as it starts with BORG...

Personally I prefer BORGBACKUP_ over BORGB_
cf. "Code must be easy to read" in
https://github.com/rear/rear/wiki/Coding-Style

rc=$?
fi

# Borg repository initilization failed in previous step,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initialization

# backup abort is inevitablee

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inevitable

if [ $rc -ne 0 ]; then
Error "Could not initialize Borg repository"
fi

# Everything should be be OK now, we can extract information about archives
# Lets find largest suffix in use, and increment it by 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's

SUFFIX=0

for i in \
$(cat $archive_cache | grep "^$BORG_ARCHIVE_PREFIX_" | awk '{print $1}'); do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, "borg list --short" exists.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ThomasWaldmann
Will certainly check that!

suffix_tmp=$(echo $i | cut -d "_" -f 2)

if [ $suffix_tmp -gt $SUFFIX ]; then
SUFFIX=$suffix_tmp
fi
done

SUFFIX=$(($SUFFIX + 1))
28 changes: 28 additions & 0 deletions usr/share/rear/backup/BORG/default/50_make_backup.sh
@@ -0,0 +1,28 @@
# This file is part of Relax-and-Recover, licensed under the GNU General
# Public License. Refer to the included COPYING for full text of license.
#
# 20_start_backup.sh

include_list=()

# Check if backup-include.txt (created by 40_create_include_exclude_files.sh),
# really exists
if [ ! -r $TMP_DIR/backup-include.txt ]; then
Error "Cant find include list"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't

fi

# Create Borg friendly include list
for i in $(cat $TMP_DIR/backup-include.txt); do
include_list+=("$i ")
done

Log "Creating archive ${BORG_ARCHIVE_PREFIX}_$SUFFIX \
in repository $BORG_REPO on host $BORG_HOST"

# Start actual Borg backup
borg create --one-file-system --verbose --stats \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is --one-file-system the usual thing done in REAR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ThomasWaldmann from what I've understood --one-file-system have similar functionality as -x or --xdev (hence is not crossing mount points).
Hopefully I get it right that $TMP_DIR/backup-include.txt does contain all mount points (/, /var, /usr, ...) that should be backed up...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rear uses '--one-file-system' intentionally for the 'tar' backup
so that other backup methods should behave by default same
but it could also depend on the other backup method what
its particular default behaviour is - i.e. different backup methods
could behave differently in rear.

--compression $BORG_COMPRESSION --exclude-from $TMP_DIR/backup-exclude.txt \
$BORG_USERNAME@$BORG_HOST:$BORG_REPO::${BORG_ARCHIVE_PREFIX}_$SUFFIX \
${include_list[@]}

StopIfError "Failed to create backup"
39 changes: 39 additions & 0 deletions usr/share/rear/backup/BORG/default/80_prune_old_backups.sh
@@ -0,0 +1,39 @@
# This file is part of Relax-and-Recover, licensed under the GNU General
# Public License. Refer to the included COPYING for full text of license.
#
# 30_prune_old_backups.sh

prune_opts=()

# Construct Borg arguments for archive purging

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pruning

# No need to check config values of $BORG_PRUNE* family
# Borg will boil out with error if values are wrong

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bail out :)

if [ ! -z $BORG_PRUNE_HOURLY ]; then
prune_opts+=("--keep-hourly=$BORG_PRUNE_HOURLY ")
fi

if [ ! -z $BORG_PRUNE_DAILY ]; then
prune_opts+=("--keep-daily=$BORG_PRUNE_DAILY ")
fi

if [ ! -z $BORG_PRUNE_WEEKLY ]; then
prune_opts+=("--keep-weekly=$BORG_PRUNE_WEEKLY ")
fi

if [ ! -z $BORG_PRUNE_MONTHLY ]; then
prune_opts+=("--keep-monthly=$BORG_PRUNE_MONTHLY ")
fi

if [ ! -z $BORG_PRUNE_YEARLY ]; then
prune_opts+=("--keep-yearly=$BORG_PRUNE_YEARLY ")
fi

if [ ! -z $prune_opts ]; then
# Purge old archives according user settings
Log "Purging old Borg archives in repository $BORG_REPO"
borg prune -v --list ${prune_opts[@]} $BORG_USERNAME@$BORG_HOST:$BORG_REPO

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what you name BORG_REPO is a path btw.

StopIfError "Failed to purge old backups"
else
# Purge is not set
Log "Purgining of old Borg archives not set, skipping"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Purging (or Pruning)

fi
10 changes: 8 additions & 2 deletions usr/share/rear/build/GNU/Linux/10_copy_as_is.sh
Expand Up @@ -24,8 +24,14 @@ fi

### Copy configuration directory
mkdir $v -p $ROOTFS_DIR/etc/rear
cp $v -r $CONFIG_DIR/* $ROOTFS_DIR/etc/rear/ >&2
cp $v -r $CONFIG_DIR/.[a-z]* $ROOTFS_DIR/etc/rear/ >&2
# This will do same job as lines below.
# On top of that, it does not throw log warning like:
# "cp: missing destination file operand after"
# if hidden file (.<filename>) is missing in $CONFIG_DIR
cp $v -r $CONFIG_DIR/. $ROOTFS_DIR/etc/rear/ >&2

#cp $v -r $CONFIG_DIR/* $ROOTFS_DIR/etc/rear/ >&2
#cp $v -r $CONFIG_DIR/.[a-z]* $ROOTFS_DIR/etc/rear/ >&2

COPY_AS_IS_EXELIST=()
while read -r ; do
Expand Down
41 changes: 37 additions & 4 deletions usr/share/rear/conf/default.conf
Expand Up @@ -621,6 +621,39 @@ BEXTRACT_VOLUME=
# eg. Ultrium-1 or /dev/sda1
BEXTRACT_DEVICE=

##
# BACKUP=BORG stuff (https://borgbackup.readthedocs.io)
##
# Copy Borg stuff 1:1
COPY_AS_IS_BORG=( )
# Binaries Borg needs to operate correctly
# ReaR includes `borg' and `locale' automatically
PROGS_BORG=( )
# Borg server name
BORG_HOST=
# Username for connection to Borg server
BORG_USERNAME=
# Path to Borg repository on Borg server
BORG_REPO=

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

# Prefix used by ReaR to name archives
# WARNING:
# Do not use '_' in BORG_ARCHIVE_PREFIX as it is used internally by ReaR.
BORG_ARCHIVE_PREFIX="rear"
# Compression used by Borg
# Syntax: <compression_type,level>
# compression_type: none, lz4, zlib, lzma
# level: 0-9
BORG_COMPRESSION="zlib,9"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason why we default to no compression is that users have to make an informed choice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ThomasWaldmann OK, I'll change that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume with an empty
BORG_COMPRESSION=""
the Borg default gets used.

@gozora
please add a comment to default.conf why
BORG_COMPRESSION=""
is the default to avoid enhancement requests
from other usres to use a "better" default here
(which could get easily implemented at some later time
in the future when nobody remembers this issue here).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsmeix will do.
Btw, new name will be BORGBACKUP_COMPRESSION ;-)

# Borg retention strategy
BORG_PRUNE_HOURLY=
BORG_PRUNE_DAILY=
BORG_PRUNE_WEEKLY=
BORG_PRUNE_MONTHLY=
BORG_PRUNE_YEARLY=
# SSH keys to use for connection to Borg server
# NOT IMPLEMENTED YET!
BORG_SSH_KEYS=

##
# BACKUP=BAREOS stuff (bareos.org)
##
Expand Down Expand Up @@ -1130,15 +1163,15 @@ PRE_RECOVERY_SCRIPT=

# PRE/POST Backup scripts will provide the ability to run certain tasks before and after a ReaR backup.
# for example:
# If a small database running on local filesystem and dependant on a local service, you will maintain its data consistency.
# Stopping it before backup and restarting again after.
# If a small database running on local filesystem and dependant on a local service, you will maintain its data consistency.
# Stopping it before backup and restarting again after.
# In case of any error during backup, if POST tasks were defined, ReaR will run those POST tasks within ExitTasks Array.
# This will prevent that the database remain stopped.

# Call this after Relax-and-Recover finished to do anything in the mkbackup/mkbackuponly workflow.
# Call this after Relax-and-Recover finished to do anything in the mkbackup/mkbackuponly workflow.
POST_BACKUP_SCRIPT=

# Call this before Relax-and-Recover starts to do anything in the mkbackup/mkbackuponly workflow.
# Call this before Relax-and-Recover starts to do anything in the mkbackup/mkbackuponly workflow.
PRE_BACKUP_SCRIPT=

# some external backup software give you the opportunity to enter paths to exclude ...
Expand Down
17 changes: 17 additions & 0 deletions usr/share/rear/prep/BORG/default/10_prep_borg.sh
@@ -0,0 +1,17 @@
# This file is part of Relax-and-Recover, licensed under the GNU General
# Public License. Refer to the included COPYING for full text of license.
#
# 10_prep_borg.sh

# Create our own locales, used only for Borg restore
mkdir -p $ROOTFS_DIR/usr/lib/locale
localedef -f UTF-8 -i en_US $ROOTFS_DIR/usr/lib/locale/rear.UTF-8
StopIfError "Could not create locales"

# Activate $COPY_AS_IS_BORG from default.conf
COPY_AS_IS=( "${COPY_AS_IS[@]}" "${COPY_AS_IS_BORG[@]}" )

# Activate $PROGS_BORG from default.conf
# Avoid user to accidentelly override `borg' and `locale' and exclude them

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accidentally

# from Relax-and-Recover rescue/recovery system
PROGS=( "${PROGS[@]}" "${PROGS_BORG[@]}" borg locale )