Skip to content

Commit

Permalink
improvements; cleanup; rename NFS_SERVER to NFS4SERVER
Browse files Browse the repository at this point in the history
  • Loading branch information
codefritzel committed May 3, 2023
1 parent 5420f90 commit 2cb90f1
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 77 deletions.
6 changes: 3 additions & 3 deletions doc/rear.8.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ 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=*NFS_SERVER*::
This is a restore only method. ReaR starts a nfs server in the restore stage and
provides the to be restored filesystems as nfs share. Another
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:
Expand Down
15 changes: 9 additions & 6 deletions usr/share/rear/conf/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2170,7 +2170,7 @@ COPY_AS_IS_EXCLUDE_NBKDC=()
####

####
# BACKUP=NFS_SERVER
# BACKUP=NFS4SERVER
##
# Note: This is for restore via NFS server, where another computer can connect to the rescue system via NFS and push
# the backup files onto the disks after ReaR prepared and formatted them.
Expand All @@ -2179,13 +2179,16 @@ COPY_AS_IS_EXCLUDE_NBKDC=()
#
# ReaR will wait for a signal file to appear to indicate that the file transfer is complete.
#
REQUIRED_PROGS_NFS_SERVER=("rpc.nfsd" "rpc.mountd" "exportfs" "ss")
NFS_SERVER_EXPORT_OPTS="rw,no_root_squash,async,no_subtree_check"
NFS_SERVER_TRUSTED="*"
NFS_SERVER_MODULES=("nfs" "nfsd")
REQUIRED_PROGS_NFS4SERVER=("rpc.nfsd" "rpc.mountd" "exportfs" "ss" "nproc")
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=( myserver 172.16.76.0/24 )
NFS4SERVER_TRUSTED_CLIENTS=()
# this file is relative to $TARGET_FS_ROOT/
# it will be deleted after restore
NFS_SERVER_RESTORE_FINISHED_FILE=rear-restore-done
NFS4SERVER_RESTORE_FINISHED_FILE=rear-restore-done


####
Expand Down
13 changes: 13 additions & 0 deletions usr/share/rear/prep/NFS4SERVER/default/400_prep_nfs_server.sh
Original file line number Diff line number Diff line change
@@ -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."
14 changes: 0 additions & 14 deletions usr/share/rear/prep/NFS_SERVER/default/400_prep_nfs_server.sh

This file was deleted.

41 changes: 41 additions & 0 deletions usr/share/rear/restore/NFS4SERVER/default/300_start_nfs_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 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=$(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
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!"
Debug "nfsd startet with $nfs_threads threads."

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

LogPrint "NFS-Server started successfully."
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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
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"
35 changes: 0 additions & 35 deletions usr/share/rear/restore/NFS_SERVER/default/300_start_nfs_server.sh

This file was deleted.

This file was deleted.

0 comments on commit 2cb90f1

Please sign in to comment.