User Tools

Site Tools


linux:backup_rear

Backup all linux servers on a central server

Packages also available for linux x84_64, ppc64 and ppc64le

http://relax-and-recover.org/

REAR will generate a bootable iso file (minimum image <100M), to recover your system, and a compressed tar file containing all other data.

First install rear and dependencies:

[root@rhlab1 ~]$ yum -y install mkisofs genisoimage attr bind-utils rear

Configure rear using a NFS v4 mount point on nfssrv:

[root@rhlab1 ~]$ cat /etc/rear/local.conf
# Default is to create Relax-and-Recover rescue media as ISO image
# set OUTPUT to change that
# set BACKUP to activate an automated (backup and) restore of your data
# Possible configuration values can be found in /usr/share/rear/conf/default.conf
#
# This file (local.conf) is intended for manual configuration. For configuration
# through packages and other automated means we recommend creating a new
# file named site.conf next to this file and to leave the local.conf as it is.
# Our packages will never ship with a site.conf.
OUTPUT=ISO
BACKUP=NETFS
BACKUP_URL=nfs://nfssrv/export/backup/linux
#
ONLY_INCLUDE_VG=( ca )
EXCLUDE_MOUNTPOINTS=( /data )
BACKUP_PROG_EXCLUDE=( '/tmp/*' )

Test a backup using validation on each step:

[root@rhlab1 output]$ rear -v -d -S -c /etc/rear mkbackup
Relax-and-Recover 1.17.2 / Git
Using log file: /var/log/rear/rear-rhldapr1.log
Press ENTER to include '/etc/rear/os.conf' ...
Press ENTER to include '/usr/share/rear/conf/Linux-ppc64le.conf' ...
Press ENTER to include '/usr/share/rear/conf/GNU/Linux.conf' ...
Press ENTER to include '/etc/rear/local.conf' ...
Press ENTER to include '/usr/share/rear/init/default/01_set_drlm_env.sh' ...
....

For production backup use, remove validation option and or verbose and debug:

$ rear -v -d -c /etc/rear mkbackup

Rear supports also most backup software like Bacula, TSM… A full sample config file is located in /usr/share/rear/conf/default.conf

Sample config file using TSM (dsm.opt and dsm.sys must be register):

[root@rhlab1 output]$ cat /etc/rear/local.conf
OUTPUT=ISO
#BACKUP=NETFS
#BACKUP_URL=nfs://systemh/export/backup/linux
#
ONLY_INCLUDE_VG=( ca )
EXCLUDE_MOUNTPOINTS=( /data )
#
BACKUP=TSM
COPY_AS_IS_TSM=( /etc/adsm/TSM.PWD /opt/tivoli/tsm/client /usr/local/ibm/gsk8* )
COPY_AS_IS_EXCLUDE_TSM=( )
PROGS_TSM=(dsmc)
# Should the result from mkrecover/backup saved via TSM
TSM_RESULT_SAVE=y
# TSM archive management class definition
TSM_ARCHIVE_MGMT_CLASS=
# if TSM server confirms the backup was successful (to preserve space on the local system)
TSM_RM_ISOFILE=y
# where to copy the resulting files to and save them with TSM
TSM_RESULT_FILE_PATH=/opt/tivoli/tsm/rear

To exclude specific folders or files add the following line into the config file

BACKUP_PROG_EXCLUDE=( ${BACKUP_PROG_EXCLUDE[@]} '/var/www/html/*' '/software/*' '/repo/*')

On AIX server (or linux), configure NFSv4 Ex:

[root@aixsrv1]/export/rear# cat /etc/exports
/export/rear -vers=3:4,rw,root=linux1:linux2:10.0.0.123
[root@aixsrv1]/export/rear# cat /root/scripts/rear.sh
#!/bin/ksh93
#set -x
################################################
#@(#) Create a rear backup for all linux clients
################################################
# version 1.0
#############################################

dir=`dirname $0`
. $dir/.env

rearbackup="linux1 linux2"
rearpath=/export/rear

HOSTNAME=$(hostname -s)

dest="test@yahoo.fr"
sender="${HOSTNAME}@yahoo.fr"

errlog=$logpath/${sn}_err.out
detail=$logpath/${sn}_detail.out
start_time=$(date "+%d-%m-%Y %H:%m")

#------------------------------------------------
usage ()
{
echo "Usage: "$0 [linuxname1,linuxname2...]
echo "\t<linuxname> is optional"
echo "\twithout parameters will create rear backup for all known linux partitions on local site"
echo "\tIf you add a specific linux, then only that linux will be saved"
exit 1
}

#------------------------------------------------
initialize ()
{
cat /dev/null > $errlog
cat /dev/null > $detail
cat /dev/null > $logname
}

#------------------------------------------------
mkrear ()
{

for client in ${rearbackup}
do
    ssh $client "/usr/sbin/rear mkbackup"
    if [ $? -ne 0 ]
    then
      echo "Rear backup for $client failed" >> $errlog
    else
      size=$(du -sg $rearpath/$(echo ${client}|cut -d. -f1)/ | awk '{print $1}')
      echo "Rear backup size"
      echo "$size GB $rearpath/${client}"

      print "***** mksysb Successful on host $client *****"
      print "Successful rear on host $client : size $size GB" >> $logname
      echo
    fi
done
}


#------------------------------------------------
sendemail ()
{
echo "###############" > $logname.tmp
echo "### $HOSTNAME ###" >> $logname.tmp
echo "###############" >> $logname.tmp
echo "\tRear started at: ${start_time}" >> $logname.tmp
#echo "\tRear ended at: "$(date "+%d-%m-%Y %H:%m") >> $logname.tmp
if [ -s $errlog ]
then
  echo "\n######## Failed rear ########" >> $logname.tmp
  cat $errlog >> $logname.tmp
  echo "Detailled error on $HOSTNAME $detail"
fi
echo "\n######## Successful rear ########" >> $logname.tmp
cat $logname >> $logname.tmp
echo | mailx -a $logname.tmp -r "$sender" -s "Report rear on $HOSTNAME" $dest
#test -f $logname.tmp && rm $logname.tmp
}

#############################################
# main
#############################################

case "$*" in
  help|-h|-help) usage ;;
esac

initialize
mkrear $* > $detail 2>&1
sendemail
linux/backup_rear.txt · Last modified: 2021/11/04 11:53 by manu