-
Notifications
You must be signed in to change notification settings - Fork 247
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
Support for Borg #1037
Changes from all commits
3cd93ce
136bc49
4f5ebb1
ee8ed28
73b7be2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. alphanumeric |
||
# 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. repository |
||
# This should avoid repeatingly quering Borg server, which could be slow. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a |
||
# If initialization succeedes, we can cast out connection problems | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. succeeds? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ThomasWaldmann There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any variable prefix is o.k. for me for rear Personally I prefer BORGBACKUP_ over BORGB_ |
||
rc=$? | ||
fi | ||
|
||
# Borg repository initilization failed in previous step, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. initialization |
||
# backup abort is inevitablee | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw, "borg list --short" exists. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ThomasWaldmann |
||
suffix_tmp=$(echo $i | cut -d "_" -f 2) | ||
|
||
if [ $suffix_tmp -gt $SUFFIX ]; then | ||
SUFFIX=$suffix_tmp | ||
fi | ||
done | ||
|
||
SUFFIX=$(($SUFFIX + 1)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../NETFS/default/40_create_include_exclude_files.sh |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is --one-file-system the usual thing done in REAR? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rear uses '--one-file-system' intentionally for the 'tar' backup |
||
--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" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Purging (or Pruning) |
||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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= | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ThomasWaldmann OK, I'll change that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume with an empty @gozora There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jsmeix will do. |
||
# 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) | ||
## | ||
|
@@ -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 ... | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ) |
There was a problem hiding this comment.
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?