diff --git a/doc/rear.8.adoc b/doc/rear.8.adoc index 968702c38c..2d3bce7f88 100644 --- a/doc/rear.8.adoc +++ b/doc/rear.8.adoc @@ -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: diff --git a/usr/share/rear/conf/default.conf b/usr/share/rear/conf/default.conf index 7dcc64770a..3855ad78c5 100644 --- a/usr/share/rear/conf/default.conf +++ b/usr/share/rear/conf/default.conf @@ -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. @@ -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 #### diff --git a/usr/share/rear/prep/NFS4SERVER/default/400_prep_nfs_server.sh b/usr/share/rear/prep/NFS4SERVER/default/400_prep_nfs_server.sh new file mode 100644 index 0000000000..7139ca586d --- /dev/null +++ b/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." diff --git a/usr/share/rear/prep/NFS_SERVER/default/400_prep_nfs_server.sh b/usr/share/rear/prep/NFS_SERVER/default/400_prep_nfs_server.sh deleted file mode 100644 index 2b627361bf..0000000000 --- a/usr/share/rear/prep/NFS_SERVER/default/400_prep_nfs_server.sh +++ /dev/null @@ -1,14 +0,0 @@ -# 400_prep_nfs_server.sh -# -# prepare stuff for NFS_SERVER -# - -PROGS+=("${PROGS_NFS_SERVER[@]}") - -REQUIRED_PROGS+=("${REQUIRED_PROGS_NFS_SERVER[@]}") - -MODULES_LOAD+=("${NFS_SERVER_MODULES[@]}") - -if is_false $NFS_SERVER_V4_ONLY; then - REQUIRED_PROGS+=("${REQUIRED_PROGS_NFS_SERVER_V3[@]}") -fi diff --git a/usr/share/rear/restore/NFS4SERVER/default/300_start_nfs_server.sh b/usr/share/rear/restore/NFS4SERVER/default/300_start_nfs_server.sh new file mode 100644 index 0000000000..166d987e80 --- /dev/null +++ b/usr/share/rear/restore/NFS4SERVER/default/300_start_nfs_server.sh @@ -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." diff --git a/usr/share/rear/restore/NFS4SERVER/default/400_restore_with_nfs_server.sh b/usr/share/rear/restore/NFS4SERVER/default/400_restore_with_nfs_server.sh new file mode 100644 index 0000000000..4074fbd9ec --- /dev/null +++ b/usr/share/rear/restore/NFS4SERVER/default/400_restore_with_nfs_server.sh @@ -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 :/ ' 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" diff --git a/usr/share/rear/restore/NFS_SERVER/default/500_stop_nfs_server.sh b/usr/share/rear/restore/NFS4SERVER/default/500_stop_nfs_server.sh similarity index 100% rename from usr/share/rear/restore/NFS_SERVER/default/500_stop_nfs_server.sh rename to usr/share/rear/restore/NFS4SERVER/default/500_stop_nfs_server.sh diff --git a/usr/share/rear/restore/NFS_SERVER/default/300_start_nfs_server.sh b/usr/share/rear/restore/NFS_SERVER/default/300_start_nfs_server.sh deleted file mode 100644 index 6c058ea349..0000000000 --- a/usr/share/rear/restore/NFS_SERVER/default/300_start_nfs_server.sh +++ /dev/null @@ -1,35 +0,0 @@ -# 300_start_nfs_server.sh - -# same options works for mountd -local nfsd_opts="--no-udp --no-nfs-version 3" -local cpu_cores=$(grep ^cpu\\scores /proc/cpuinfo | uniq | cut -d ':' -f 2 | xargs) -# 4 threads per cpu core -local nfs_threads=$(( $cpu_cores * 4 )) -# 8 are the standard and should be the minumun -if [[ "$nfs_threads" -lt 8 ]]; then nfs_threads=8; fi - -# add all mountpoints to /etc/exports -while read mountpoint junk ; do - options="$NFS_SERVER_EXPORT_OPTS" - if [[ $mountpoint == "/" ]]; then - options+=",fsid=0" - else - options+=",nohide" - fi - - if ! grep -q "${TARGET_FS_ROOT}${mountpoint}" /etc/exports; then - echo "${TARGET_FS_ROOT}${mountpoint} $NFS_SERVER_TRUSTED($options)" >> /etc/exports - fi -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 - -Print "NFS-Server started successfully." diff --git a/usr/share/rear/restore/NFS_SERVER/default/400_restore_with_nfs_server.sh b/usr/share/rear/restore/NFS_SERVER/default/400_restore_with_nfs_server.sh deleted file mode 100644 index 4b19e4e6a0..0000000000 --- a/usr/share/rear/restore/NFS_SERVER/default/400_restore_with_nfs_server.sh +++ /dev/null @@ -1,19 +0,0 @@ -# 400_restore_with_nfs_server.sh - -local check_file=$TARGET_FS_ROOT/$NFS_SERVER_RESTORE_FINISHED_FILE - -Print "Mount the nfs share: 'mount -t nfs -o nfsvers=4 :/ ' and restore all files to mounted destination." -Print "Create the $check_file file when the restore is completed and umount the share." - -rm -rf $check_file - -Print "Wait until $check_file was created and there is no connection on the NFS-Port 2049." - -# or look at /var/lib/nfs/rmtab -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 -rf $check_file