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

Align backup on USB with backup on NFS #1165

Merged
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
2 changes: 1 addition & 1 deletion doc/rear.8
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ OUTPUT_URL=nfs://server/path/
.\}
.RE
.sp
When using BACKUP=NETFS and BACKUP_PROG=tar there is an option to select BACKUP_TYPE=incremental or BACKUP_TYPE=differential to let rear make incremental or differential backups until the next full backup day e\&.g\&. via FULLBACKUPDAY="Mon" is reached or when the last full backup is too old after FULLBACKUP_OUTDATED_DAYS has passed\&. Incremental or differential backup is currently only known to work with BACKUP_URL=nfs\&. Other BACKUP_URL schemes may work but at least BACKUP_URL=usb is known not to work with incremental or differential backup\&.
When using BACKUP=NETFS and BACKUP_PROG=tar there is an option to select BACKUP_TYPE=incremental or BACKUP_TYPE=differential to let rear make incremental or differential backups until the next full backup day e\&.g\&. via FULLBACKUPDAY="Mon" is reached or when the last full backup is too old after FULLBACKUP_OUTDATED_DAYS has passed\&. Incremental or differential backup is currently only known to work with BACKUP_URL=nfs\&. Other BACKUP_URL schemes may work but at least BACKUP_URL=usb requires USB_SUFFIX to be set to work with incremental or differential backup\&.
.SH "CONFIGURATION"
.sp
To configure Relax\-and\-Recover you have to edit the configuration files in \fI/etc/rear/\fR\&. All \fI*\&.conf\fR files there are part of the configuration, but only \fIsite\&.conf\fR and \fIlocal\&.conf\fR are intended for the user configuration\&. All other configuration files hold defaults for various distributions and should not be changed\&.
Expand Down
4 changes: 2 additions & 2 deletions doc/rear.8.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ e.g. via +FULLBACKUPDAY="Mon"+ is reached or when the last full backup
is too old after FULLBACKUP_OUTDATED_DAYS has passed.
Incremental or differential backup is currently only known to work
with +BACKUP_URL=nfs+. Other BACKUP_URL schemes may work but
at least +BACKUP_URL=usb+ is known not to work with incremental
or differential backup.
at least +BACKUP_URL=usb+ requires USB_SUFFIX to be set
to work with incremental or differential backup.

== CONFIGURATION
To configure Relax-and-Recover you have to edit the configuration files in
Expand Down
4 changes: 2 additions & 2 deletions doc/user-guide/03-configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ e.g. via +FULLBACKUPDAY="Mon"+ is reached or when the last full backup
is too old after FULLBACKUP_OUTDATED_DAYS has passed.
Incremental or differential backup is currently only known to work
with +BACKUP_URL=nfs+. Other BACKUP_URL schemes may work but
at least +BACKUP_URL=usb+ is known not to work with incremental
or differential backup.
at least +BACKUP_URL=usb+ requires USB_SUFFIX to be set
to work with incremental or differential backup.

BACKUP=REQUESTRESTORE::
No backup, just ask user to somehow restore the filesystems.
Expand Down
26 changes: 23 additions & 3 deletions usr/share/rear/conf/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,27 @@ USB_UEFI_PART_SIZE="100"
# resulting files that should be copied onto the USB stick
USB_FILES=()

# Number of rescue environments/backups to retain on USB
# USB_SUFFIX specifies the last part of the backup directory on the USB medium.
# When USB_SUFFIX is unset or empty, backup on USB works in its default mode which means
# multiple timestamp backup directories of the form rear/HOSTNAME/YYYYMMDD.HHMM
# plus automated rescue environments and backups cleanup via USB_RETAIN_BACKUP_NR.
# In contrast when USB_SUFFIX is set, backup on USB works in compliance with how backup on NFS works
# (i.e. BACKUP_URL=usb:... and BACKUP_URL=nfs:... behave compatible when USB_SUFFIX is set)
# which means a fixed backup directory of the form rear/HOSTNAME/USB_SUFFIX on the USB medium
# and no automated removal of backups or other stuff (regardless of USB_RETAIN_BACKUP_NR)
# see https://github.com/rear/rear/issues/1164
# Using multiple backups as described in doc/user-guide/11-multiple-backups.adoc
# requires a fixed backup directory so that USB_SUFFIX must be set for multiple backups on USB
# see https://github.com/rear/rear/issues/1160
# Also BACKUP_TYPE incremental or differential requires a fixed backup directory
# so that USB_SUFFIX must be set for incremental or differential backup on USB
# see https://github.com/rear/rear/issues/1145
USB_SUFFIX=""

# Number of older rescue environments or backups to retain on USB.
# The default USB_RETAIN_BACKUP_NR=2 means that there is at most
# the latest (current) rescue environment or backup plus
# the second eldest and the third eldest (three all together):
USB_RETAIN_BACKUP_NR=2

# Define the default WORKFLOW for the udev handler (empty to disable)
Expand Down Expand Up @@ -494,8 +514,8 @@ BACKUP_INTEGRITY_CHECK=
# By default BACKUP_TYPE is empty which means "rear mkbackup" will create a full backup.
# Only with BACKUP=NETFS and BACKUP_PROG=tar one can also use incremental or differential backup:
# Incremental or differential backup is currently only known to work with BACKUP_URL=nfs://.
# Other BACKUP_URL schemes may work but at least BACKUP_URL=usb:///... is known not to work
# with incremental or differential backup (see https://github.com/rear/rear/issues/1145).
# Other BACKUP_URL schemes may work and at least BACKUP_URL=usb:///... requires USB_SUFFIX to be set
# to work with incremental or differential backup (see https://github.com/rear/rear/issues/1145).
# Incremental or differential backup and NETFS_KEEP_OLD_BACKUP_COPY contradict each other so that
# NETFS_KEEP_OLD_BACKUP_COPY must not be 'true' in case of incremental or differential backup
# because NETFS_KEEP_OLD_BACKUP_COPY would move an already existing backup directory away
Expand Down
67 changes: 47 additions & 20 deletions usr/share/rear/output/USB/Linux-i386/300_create_extlinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,22 @@ fi

# We generate a single syslinux.cfg for the current system
Log "Creating $USB_PREFIX/syslinux.cfg"
# FIXME: # type -a time
# time is a shell keyword
# time is /usr/bin/time
time=$(basename $USB_REAR_DIR)
if test $USB_SUFFIX ; then
# USB_SUFFIX specifies the last part of the backup directory on the USB medium
# and then basename $USB_REAR_DIR can be anything so that we use it as is:
menu_label="$time"
else
# When USB_SUFFIX is unset, empty, or contains only blanks
# basename $USB_REAR_DIR is a timestamp of the form YYYYMMDD.HHMM
menu_label="${time:0:4}-${time:4:2}-${time:6:2} ${time:9:2}:${time:11:2}"
fi
syslinux_write <<EOF 4>"$USB_REAR_DIR/syslinux.cfg"
label $HOSTNAME-$time
menu label ${time:0:4}-${time:4:2}-${time:6:2} ${time:9:2}:${time:11:2} $usb_label_workflow
menu label $menu_label $usb_label_workflow
say $HOSTNAME-$time - Recover $HOSTNAME $usb_label_workflow ($time)
text help
Relax-and-Recover v$VERSION - $usb_label_workflow using kernel $(uname -r) ${IPADDR:+on $IPADDR}
Expand All @@ -116,7 +128,7 @@ ${BACKUP:+BACKUP=$BACKUP} ${OUTPUT:+OUTPUT=$OUTPUT} ${BACKUP_URL:+BACKUP_URL=$BA
append initrd=/$USB_PREFIX/initrd.cgz root=/dev/ram0 vga=normal rw $KERNEL_CMDLINE

label $HOSTNAME-$time
menu label ${time:0:4}-${time:4:2}-${time:6:2} ${time:9:2}:${time:11:2} $usb_label_workflow - AUTOMATIC RECOVER
menu label $menu_label $usb_label_workflow - AUTOMATIC RECOVER
say $HOSTNAME-$time - Recover $HOSTNAME $usb_label_workflow ($time)
text help
Relax-and-Recover v$VERSION - $usb_label_workflow using kernel $(uname -r) ${IPADDR:+on $IPADDR}
Expand All @@ -128,25 +140,37 @@ ${BACKUP:+BACKUP=$BACKUP} ${OUTPUT:+OUTPUT=$OUTPUT} ${BACKUP_URL:+BACKUP_URL=$BA
EOF

# Clean up older images of a given system, but keep USB_RETAIN_BACKUP_NR
# entries for backup and rescue
backup_count=${USB_RETAIN_BACKUP_NR:-2}
rescue_count=${USB_RETAIN_BACKUP_NR:-2}
for rear_run in $(ls -dt $BUILD_DIR/outputfs/rear/$HOSTNAME/*); do
backup_name=$rear_run/${BACKUP_PROG_ARCHIVE}${BACKUP_PROG_SUFFIX}${BACKUP_PROG_COMPRESS_SUFFIX}
if [[ -e $backup_name ]] ; then
backup_count=$((backup_count - 1))
if (( backup_count < 0 )); then
Log "Remove older backup directory $rear_run"
rm -rf $v $rear_run >&8
fi
else
rescue_count=$((rescue_count - 1))
if (( rescue_count < 0 )); then
Log "Remove older rescue directory $rear_run"
rm -rf $v $rear_run >&8
# entries for backup and rescue when backup on USB works in default mode.
# When USB_SUFFIX is set the compliance mode is used where
# backup on USB works in compliance with backup on NFS which means
# a fixed backup directory and no automated removal of backups or other stuff
# see https://github.com/rear/rear/issues/1164
# Use plain $USB_SUFFIX and not "$USB_SUFFIX" because when USB_SUFFIX contains only blanks
# test "$USB_SUFFIX" would result true because test " " results true:
if ! test $USB_SUFFIX ; then
backup_count=${USB_RETAIN_BACKUP_NR:-2}
rescue_count=${USB_RETAIN_BACKUP_NR:-2}
for rear_run in $(ls -dt $BUILD_DIR/outputfs/rear/$HOSTNAME/*); do
# This fails when the backup archive name is not
# ${BACKUP_PROG_ARCHIVE}${BACKUP_PROG_SUFFIX}${BACKUP_PROG_COMPRESS_SUFFIX}
# so that in particular it would fail for incremental/differential backups
# but incremental/differential backups on USB require USB_SUFFIX to be set:
backup_name=$rear_run/${BACKUP_PROG_ARCHIVE}${BACKUP_PROG_SUFFIX}${BACKUP_PROG_COMPRESS_SUFFIX}
if [[ -e $backup_name ]] ; then
backup_count=$((backup_count - 1))
if (( backup_count < 0 )); then
Log "Remove older backup directory $rear_run"
rm -rf $v $rear_run >&8
fi
else
rescue_count=$((rescue_count - 1))
if (( rescue_count < 0 )); then
Log "Remove older rescue directory $rear_run"
rm -rf $v $rear_run >&8
fi
fi
fi
done
done
fi

# We generate a ReaR syslinux.cfg based on existing ReaR syslinux.cfg files.
Log "Creating /rear/syslinux.cfg"
Expand All @@ -163,6 +187,9 @@ EOF
# TODO: Sort systems by name, but also sort timestamps in reverse order
for file in $(cd $BUILD_DIR/outputfs; find rear/*/* -name syslinux.cfg); do
dir=$(dirname $file)
# FIXME: # type -a time
# time is a shell keyword
# time is /usr/bin/time
time=$(basename $dir)
system=$(basename $(dirname $dir))

Expand Down
11 changes: 8 additions & 3 deletions usr/share/rear/prep/NETFS/default/070_set_backup_archive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ if ! test "NETFS" = "$BACKUP" -a "tar" = "$BACKUP_PROG" ; then
Error "BACKUP_TYPE incremental or differential only works with BACKUP=NETFS and BACKUP_PROG=tar"
fi
# Incremental or differential backup is currently only known to work with BACKUP_URL=nfs://.
# Other BACKUP_URL schemes may work but at least BACKUP_URL=usb:///... is known not to work
# with incremental or differential backup (see https://github.com/rear/rear/issues/1145):
# Other BACKUP_URL schemes may work and at least BACKUP_URL=usb:///... needs special setup
# to work with incremental or differential backup (see https://github.com/rear/rear/issues/1145):
if test "usb" = "$scheme" ; then
Error "BACKUP_TYPE incremental or differential does not work with BACKUP_URL=usb:///..."
# When USB_SUFFIX is set the compliance mode is used where
# backup on USB works in compliance with backup on NFS which means
# a fixed backup directory where incremental or differential backups work.
# Use plain $USB_SUFFIX and not "$USB_SUFFIX" because when USB_SUFFIX contains only blanks
# test "$USB_SUFFIX" would result true because test " " results true:
test $USB_SUFFIX || Error "BACKUP_TYPE incremental or differential requires USB_SUFFIX for BACKUP_URL=usb"
fi
# Incremental or differential backup and keeping old backup contradict each other (mutual exclusive)
# so that NETFS_KEEP_OLD_BACKUP_COPY must not be 'true' in case of incremental or differential backup:
Expand Down
19 changes: 18 additions & 1 deletion usr/share/rear/prep/USB/default/060_set_usb_device.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,24 @@ if [[ -z "$USB_DEVICE" ]] && [[ "$OUTPUT_URL" ]]; then
esac
fi

USB_PREFIX="rear/$HOSTNAME/$(date +%Y%m%d.%H%M)"
# Set USB_PREFIX:
# Use plain $USB_SUFFIX and not "$USB_SUFFIX" because when USB_SUFFIX contains only blanks
# test "$USB_SUFFIX" would result true because test " " results true:
if test $USB_SUFFIX ; then
# When USB_SUFFIX is set the compliance mode is used which means
USB_PREFIX="rear/$HOSTNAME/$USB_SUFFIX"
# which results that backup on USB works in compliance with backup on NFS
# which means a fixed backup directory and no automated backups cleanup
# see https://github.com/rear/rear/issues/1164
else
# When USB_SUFFIX is unset, empty, or contains only blanks
# the default mode for backup on USB is used which means
USB_PREFIX="rear/$HOSTNAME/$( date +%Y%m%d.%H%M )"
# which results multiple timestamp backup directories
# plus automated backups cleanup via USB_RETAIN_BACKUP_NR
fi

test "$USB_PREFIX" || USB_PREFIX="rear/$HOSTNAME/$(date +%Y%m%d.%H%M)"

### Change NETFS_PREFIX to USB_PREFIX if our backup URL is on USB
if [[ "$BACKUP_URL" ]] ; then
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@

scheme=$(url_scheme "$BACKUP_URL")
if [[ "$scheme" != "usb" ]] ; then
return
fi
# In case of backup on USB let the user choose which backup will be restored.

# Detect all backups on the USB device
scheme=$( url_scheme "$BACKUP_URL" )
# Skip if not backup on USB:
test "usb" = "$scheme" || return

# When USB_SUFFIX is set the compliance mode is used where
# backup on USB works in compliance with backup on NFS which means
# a fixed backup directory where the user cannot choose the backup
# because what there is in the fixed backup directory will be restored
# via RESTORE_ARCHIVES in usr/share/rear/prep/NETFS/default/070_set_backup_archive.sh
# Use plain $USB_SUFFIX and not "$USB_SUFFIX" because when USB_SUFFIX contains only blanks
# test "$USB_SUFFIX" would result true because test " " results true:
test $USB_SUFFIX && return

# Detect all backups on the USB device.
# FIXME: This fails when the backup archive name is not
# ${BACKUP_PROG_ARCHIVE}${BACKUP_PROG_SUFFIX}${BACKUP_PROG_COMPRESS_SUFFIX}
# so that in particular it fails for incremental/differential backups
# but incremental/differential backups usually require several backup archives
# to be restored (one full backup plus one differential or several incremental backups)
# cf. RESTORE_ARCHIVES in usr/share/rear/prep/NETFS/default/070_set_backup_archive.sh
# and the code below only works for one single backup archive:
backups=()
backup_times=()
for rear_run in $BUILD_DIR/outputfs/rear/$HOSTNAME/* ;do
Expand Down