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

ReaR with Borg back end to USB. #1730

Merged
merged 6 commits into from
Feb 20, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions doc/user-guide/04-scenarios.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,14 @@ TAPE_DEVICE=/dev/nst0
----


== Bootable ISO with Borg
== ReaR with Borg back end
- Install Borg backup (https://borgbackup.readthedocs.io/en/stable/installation.html).

IMPORTANT: We strongly recommend to use Borg standalone binary (https://github.com/borgbackup/borg/releases) as it includes all necessities for Borg operations.
Copy link
Member Author

Choose a reason for hiding this comment

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

This documentation update (whole IMPORTANT block) addresses part of #1727

If you decide to go for different type of Borg installation types, make sure you include all needed files for Borg runtime into ReaR rescue/recovery system.
E.g. by using `COPY_AS_IS_BORG=( '/usr/lib64/python3.4*' '/usr/bin/python3*' '/usr/bin/pyvenv*' '/usr/lib/python3.4*' '/usr/lib64/libpython3*' )`

=== Borg -> SSH
- 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:

Expand Down Expand Up @@ -117,6 +123,36 @@ export BORG_RELOCATED_REPO_ACCESS_IS_OK="yes"
export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK="yes"

----
=== Borg -> USB

- Example _local.conf_:
[source,bash]
----
OUTPUT=USB
BACKUP=BORG

USB_DEVICE=/dev/disk/by-label/REAR-000

BORGBACKUP_REPO="/my_borg_backup"
BORGBACKUP_UMASK="0002"

BORGBACKUP_PRUNE_WEEKLY=2

BORGBACKUP_ENC_TYPE="keyfile"
export BORG_PASSPHRASE="S3cr37_P455w0rD"

export BORG_RELOCATED_REPO_ACCESS_IS_OK="yes"
export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK="yes"

COPY_AS_IS_EXCLUDE=( "${COPY_AS_IS_EXCLUDE[@]}" )
COPY_AS_IS_BORG=( '/root/.config/borg/keys/' )

SSH_UNPROTECTED_PRIVATE_KEYS="yes"
SSH_FILES="yes"


----

IMPORTANT: If using BORGBACKUP_ENC_TYPE="keyfile", don't forget to make your
encryption key available for case of restore!
(using `COPY_AS_IS_BORG=( "/root/.config/borg/keys/" )` is a option to consider).
Expand All @@ -125,7 +161,7 @@ IMPORTANT: If using BORGBACKUP_ENC_TYPE="keyfile", don't forget to make your

- Executing `rear mkbackup` will create Relax-and-Recover rescue/recovery system and
start Borg backup process. Once backup finishes, it will also prune old archives from repository,
if at least one of BORGBACKUP_PRUNE_* variables is set.
if at least one of `BORGBACKUP_PRUNE_*` variables is set.
- To recover your system, boot Relax-and-Recover rescue/recovery system and trigger `rear recover`.
You will be prompted which archive to recover from Borg repository, once ReaR finished with layout configuration.

Expand Down
9 changes: 9 additions & 0 deletions usr/share/rear/backup/BORG/default/250_mount_usb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 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.
#
# 250_mount_usb.sh

# We need to mount USB destination device prior the backup starts
if [[ -z $BORGBACKUP_HOST ]]; then
mount_url usb://$USB_DEVICE $borg_dst_dev
fi
12 changes: 6 additions & 6 deletions usr/share/rear/backup/BORG/default/500_make_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ for i in $(cat $TMP_DIR/backup-include.txt); do
include_list+=("$i ")
done

Log "Creating archive ${BORGBACKUP_ARCHIVE_PREFIX}_$BORGBACKUP_SUFFIX \
in repository $BORGBACKUP_REPO on host $BORGBACKUP_HOST"

# Only in ReaR verbose mode also show borg progress output and stats
local borg_progress=''
test "$verbose" && borg_progress='--progress --stats'

# Start actual Borg backup.
Log "Creating archive ${BORGBACKUP_ARCHIVE_PREFIX}_$BORGBACKUP_SUFFIX \
in repository $BORGBACKUP_REPO"

borg create --one-file-system $borg_progress $verbose \
$BORGBACKUP_OPT_COMPRESSION $BORGBACKUP_OPT_REMOTE_PATH $BORGBACKUP_OPT_UMASK \
--exclude-from $TMP_DIR/backup-exclude.txt \
$BORGBACKUP_USERNAME@$BORGBACKUP_HOST:$BORGBACKUP_REPO::\
$BORGBACKUP_OPT_COMPRESSION $BORGBACKUP_OPT_REMOTE_PATH \
$BORGBACKUP_OPT_UMASK --exclude-from $TMP_DIR/backup-exclude.txt \
${borg_dst_dev}${BORGBACKUP_REPO}::\
${BORGBACKUP_ARCHIVE_PREFIX}_$BORGBACKUP_SUFFIX \
${include_list[@]} 0<&6 1>&7 2>&8

Expand Down
4 changes: 2 additions & 2 deletions usr/share/rear/backup/BORG/default/800_prune_old_backups.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
if [ ! -z $BORGBACKUP_OPT_PRUNE ]; then
# Purge old archives according user settings.
LogPrint "Purging old Borg archives in repository $BORGBACKUP_REPO"

borg prune --list ${BORGBACKUP_OPT_PRUNE[@]} \
$BORGBACKUP_OPT_REMOTE_PATH $BORGBACKUP_OPT_UMASK \
--prefix ${BORGBACKUP_ARCHIVE_PREFIX}_ \
$BORGBACKUP_USERNAME@$BORGBACKUP_HOST:$BORGBACKUP_REPO
${borg_dst_dev}${BORGBACKUP_REPO}

StopIfError "Failed to purge old backups"
else
# Purge is not set.
Expand Down
1 change: 1 addition & 0 deletions usr/share/rear/backup/BORG/default/900_umount_usb.sh
5 changes: 2 additions & 3 deletions usr/share/rear/lib/borg-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ function borg_set_vars {

# Query Borg server for repository information
# and store it to BORGBACKUP_ARCHIVE_CACHE.
# This should avoid repeatingly quering Borg server, which could be slow.
# This avoids repeatedly querying Borg repository, which could be slow.
function borg_archive_cache_create {
borg list $BORGBACKUP_OPT_REMOTE_PATH \
$BORGBACKUP_USERNAME@$BORGBACKUP_HOST:$BORGBACKUP_REPO \
borg list $BORGBACKUP_OPT_REMOTE_PATH ${borg_dst_dev}${BORGBACKUP_REPO} \
2> /dev/null > $BORGBACKUP_ARCHIVE_CACHE
}
14 changes: 14 additions & 0 deletions usr/share/rear/prep/BORG/default/100_set_vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,17 @@
# 100_set_vars.sh

borg_set_vars

# If BORGBACKUP_HOST is not set, we automatically assume that USB device should
# be used as backup back end.
# borg_dst_dev will be set to mount point, where USB_DEVICE will be mounted
# in case of empty BORGBACKUP_HOST. While by non-zero BORGBACKUP_HOST we assume
# that SSH should be used as transfer protocol and borg_dst_dev becomes
# combined string of "BORGBACKUP_USERNAME@BORGBACKUP_HOST".
# borg_dst_dev directory will be created in later stage
# (if not already present) by 250_mount_usb.sh script.
if [[ -n $BORGBACKUP_HOST ]]; then
borg_dst_dev=$BORGBACKUP_USERNAME@$BORGBACKUP_HOST:
else
borg_dst_dev=$BUILD_DIR/borg_backup
fi
15 changes: 15 additions & 0 deletions usr/share/rear/prep/BORG/default/250_mount_usb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 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.
#
# 250_mount_usb.sh

# We need to mount USB_DEVICE in order to prepare for Borg archive
# initialization, but only if BORGBACKUP_HOST is not set.
# When BORGBACKUP_HOST is set, we don't need to mount anything as SSH
# backup destination will be handled internally by Borg it self.
if [[ -z $BORGBACKUP_HOST ]]; then
mkdir -p $v "$borg_dst_dev" >&2
StopIfError "Could not mkdir '$borg_dst_dev'"

mount_url usb://$USB_DEVICE $borg_dst_dev
fi
10 changes: 5 additions & 5 deletions usr/share/rear/prep/BORG/default/300_init_archive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ borg_archive_cache_create
# will be skipped.
rc=$?

# This might be a Borg connection error, or missing repository.
# This might be a Borg connection / mount error, or missing repository.
# If initialization succeeds, we can rule out connection problems.
# `borg init` has to be triggered in "prep" stage if user decides to include
# keyfiles to Relax-and-Recover rescue/recovery system using COPY_AS_IS_BORG.
if [ $rc -ne 0 ]; then
LogPrint "Failed to list $BORGBACKUP_REPO on $BORGBACKUP_HOST"
LogPrint "Creating new Borg repository $BORGBACKUP_REPO on $BORGBACKUP_HOST"
LogPrint "Failed to list $BORGBACKUP_REPO"
LogPrint "Creating new Borg repository $BORGBACKUP_REPO"

borg init $BORGBACKUP_OPT_ENCRYPTION $BORGBACKUP_OPT_REMOTE_PATH \
$BORGBACKUP_OPT_UMASK \
$BORGBACKUP_USERNAME@$BORGBACKUP_HOST:$BORGBACKUP_REPO
$BORGBACKUP_OPT_UMASK ${borg_dst_dev}${BORGBACKUP_REPO}
rc=$?
fi

Expand Down
10 changes: 10 additions & 0 deletions usr/share/rear/prep/BORG/default/900_umount_usb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 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.
#
# 900_umount_usb.sh

# After BORG operations are over, we can finally umount USB_DEVICE.
# This will force final sync of data that can still sit in cache.
if [[ -z $BORGBACKUP_HOST ]]; then
umount_url usb://$USB_DEVICE $borg_dst_dev
fi
1 change: 1 addition & 0 deletions usr/share/rear/restore/BORG/default/250_mount_usb.sh
5 changes: 3 additions & 2 deletions usr/share/rear/restore/BORG/default/400_restore_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ StopIfError "Could not change directory to $TARGET_FS_ROOT"
# and should not interfere with remaining stages of rear recover.
# This is still not the ideal solution, but best I can think of so far :-/.
LogPrint "Recovering from Borg archive $BORGBACKUP_ARCHIVE"

LC_ALL=rear.UTF-8 \
borg extract --sparse $BORGBACKUP_OPT_REMOTE_PATH \
$BORGBACKUP_USERNAME@$BORGBACKUP_HOST:$BORGBACKUP_REPO::$BORGBACKUP_ARCHIVE
StopIfError "Could not successfully finish Borg restore"
${borg_dst_dev}${BORGBACKUP_REPO}::$BORGBACKUP_ARCHIVE

LogPrintIfError "Error was reported during Borg restore"
Copy link
Member Author

Choose a reason for hiding this comment

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

This change addresses #1702

LogPrint "Borg OS restore finished successfully"
popd >/dev/null