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

nfs_server as new restore method #2973

Merged
merged 9 commits into from May 3, 2023
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
5 changes: 5 additions & 0 deletions doc/rear.8.adoc
Expand Up @@ -366,6 +366,11 @@ Use BorgBackup (short Borg) a deduplicating backup program to restore the data.
Executing 'rear mkbackup' will create a Borg backup,
see the section 'ReaR with Borg back end' in the ReaR user-guide 'Scenarios' documentation.

BACKUP=*NFS4SERVER*::
This is a restore only method. ReaR starts a NFSv4 server in the restore stage and
provides the to be restored filesystems as NFSv4 share. Another
server (with a special backup sotware) can mount this share and can push the backup data into it.

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

BACKUP=*NETFS*::
Expand Down
22 changes: 22 additions & 0 deletions usr/share/rear/conf/default.conf
Expand Up @@ -2169,6 +2169,28 @@ COPY_AS_IS_NBKDC=()
COPY_AS_IS_EXCLUDE_NBKDC=()
####

####
# BACKUP=NFS4SERVER
##
# Note: This is for restore via NFS server, where another computer can connect to the rescue system via NFS and push
codefritzel marked this conversation as resolved.
Show resolved Hide resolved
# the backup files onto the disks after ReaR prepared and formatted them.
#
# This method has no backup functionality, only restore. And it requires interaction with an external system to push the files.
#
# ReaR will wait for a signal file to appear to indicate that the file transfer is complete.
#
REQUIRED_PROGS_NFS4SERVER=("rpc.nfsd" "rpc.mountd" "exportfs" "ss" "nproc")
codefritzel marked this conversation as resolved.
Show resolved Hide resolved
NFS4SERVER_MODULES=(nfs nfsd)
# List of share options for the recovery system, see 'General Options' in exports(5)
NFS4SERVER_EXPORT_OPTS=(rw no_root_squash async no_subtree_check)
# List of trusted systems that can mount the recovery system, see 'Machine Name Formats' in exports(5)
# e.g. NFS4SERVER_TRUSTED_CLIENTS=( myclient 172.16.76.0/24 )
NFS4SERVER_TRUSTED_CLIENTS=()
# this file is relative to $TARGET_FS_ROOT/
# it will be deleted after restore
NFS4SERVER_RESTORE_FINISHED_FILE=var/lib/rear/rear_finished.txt


####
# BACKUP=GALAXY
##
Expand Down
13 changes: 13 additions & 0 deletions usr/share/rear/prep/NFS4SERVER/default/400_prep_nfs_server.sh
@@ -0,0 +1,13 @@
# 400_prep_nfs_server.sh
#
# prepare stuff for NFS4SERVER
#

PROGS+=("${PROGS_NFS4SERVER[@]}")

REQUIRED_PROGS+=("${REQUIRED_PROGS_NFS4SERVER[@]}")

MODULES_LOAD+=("${NFS4SERVER_MODULES[@]}")

# Check if at least one trusted client was specified
(( "${#NFS4SERVER_TRUSTED_CLIENTS[@]}" > 0 )) || Error "You must have defined at least one client in NFS4SERVER_TRUSTED_CLIENTS."
codefritzel marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

You could omit this check from this file and add a symlink pointing to usr/share/rear/verify/NFS4SERVER/default/400_verify_nfs_server.sh to this directory instead to reduce code duplication a bit.

Copy link
Member

Choose a reason for hiding this comment

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

I think better to not mess with the MODULES_LOAD variable during verify because there no code cares about it and I don't like code that is meaningless but appears to be important. It might confuse other people who come to work on ReaR.

Copy link
Member

Choose a reason for hiding this comment

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

@schlomo oh, I meant only the last line, not the stuff above.

42 changes: 42 additions & 0 deletions usr/share/rear/restore/NFS4SERVER/default/300_start_nfs_server.sh
@@ -0,0 +1,42 @@
# 300_start_nfs_server.sh

# same options works for mountd
local nfsd_opts=(--no-udp --no-nfs-version 3 -V 4.2)
local cpu_cores
cpu_cores=$(nproc) || Error "Could not determine CPU details via nproc"
# 4 threads per cpu core
local nfs_threads=$(( $cpu_cores * 4 ))
# 8 are the standard and should be the minumun
if (( nfs_threads < 8 )); then nfs_threads=8; fi

# clear /etc/exports if the user rerun the restore with other options
> /etc/exports

# add all mountpoints to /etc/exports
schlomo marked this conversation as resolved.
Show resolved Hide resolved
while read mountpoint junk ; do
local options=("${NFS4SERVER_EXPORT_OPTS[@]}")
if [[ $mountpoint == "/" ]]; then
options+=("fsid=0")
else
options+=(nohide)
fi
local nfs_options=$(IFS=',' ; echo "${options[*]}")
local nfs_trust_options=""
for trust in "${NFS4SERVER_TRUSTED_CLIENTS[@]}"; do
nfs_trust_options+="$trust($nfs_options) "
done

echo "${TARGET_FS_ROOT}${mountpoint} $nfs_trust_options" >> /etc/exports
done < "${VAR_DIR}/recovery/mountpoint_device"
Debug "$(cat /etc/exports)"

exportfs $v -ra || Error "exportfs failed!"

rpc.nfsd --debug "$nfs_threads" "${nfsd_opts[@]}" || Error "rpc.nfsd failed!"
Copy link
Member

Choose a reason for hiding this comment

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

Is it intended to turn on debugging unconditionally?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, in case of error we'll see a bit more useful stuff, otherwise it doesn't matter. As we capture stdout the user isn't impacted.

Debug "nfsd startet with $nfs_threads threads."

if [ -z "$(pidof rpc.mountd)" ]; then
rpc.mountd --debug all "${nfsd_opts[@]}" || Error "rpc.mountd failed!"
Copy link
Member

Choose a reason for hiding this comment

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

ditto about --debug

fi

LogPrint "NFS-Server started successfully."
@@ -0,0 +1,23 @@
# 400_restore_with_nfs_server.sh

local check_file="$TARGET_FS_ROOT/$NFS4SERVER_RESTORE_FINISHED_FILE"

LogPrint "Mount the nfs share: 'mount -t nfs <ip>:/ <destination>' and restore all files to mounted destination."
LogPrint "Create the $check_file file when the restore is completed and umount the share."

rm -f $check_file || Error "Couldn't delete restore finished file $check_file"

LogPrint "Wait until $check_file was created and there is no connection on the NFS-Port 2049."

# or look at /var/lib/nfs/rmtab
local nfs_connections=1
while [ ! -f "$check_file" ] || [ "$nfs_connections" -gt 0 ]; do
local used_space
used_space=$(df --total --local -h --exclude-type=tmpfs --exclude-type=devtmpf | tail -n 1 | awk '{print $3}') &&
ProgressInfo " Used storage space: $used_space"

sleep 5
nfs_connections=$(ss -tanpH state established "( sport = 2049 )" | wc -l)
done

rm -f $check_file || Error "Couldn't delete restore finished file $check_file"
@@ -0,0 +1,5 @@
# 500_stop_nfs_server.sh

rpc.nfsd 0 || :

kill $(pidof rpc.mountd) || :
@@ -0,0 +1,4 @@
# 400_verify_nfs_server.sh

# Check if at least one trusted client was specified
(( "${#NFS4SERVER_TRUSTED_CLIENTS[@]}" > 0 )) || Error "You must have defined at least one client in NFS4SERVER_TRUSTED_CLIENTS."