Why?


Search This Blog

Saturday, October 22, 2016

CentOS 7 rescue, backup, and restore using ReaR

CentOS 7 rescue, backup, and restore using ReaR

I will be using a server i have already setup as my backup server. The client server we are working on in this post will use the backup server to store its rescue image and tar file on. This backup server is connected via 10Gb Ethernet and has 8 WD 3TB NAS drives in btrfs Raid10 on a Supermicro SAS/SATA controller. The btrfs on this backup server is also replicated to another server. So if a Linux client crashed i have what i need to restore from my backup server. If the back server crashes before i get the client rebuilt i can fall back on the replicated files the other machine. I also have a disaster recovery document for the backup server that allows me to have it fully rebuilt and able to restore files back on to it in less than an hour.

Now on your client machine install files so we can create rescue images. lftp is needed to so we can sftp the image to the backup server if wanted. In this post i will be using nfs as i have this setup already on my backup server.

# yum -y install rear genisoimage syslinux lftp nfs-utils

ReaR is configured in the /etc/rear/local.conf file. Specify the rescue system configuration by
adding these lines:

OUTPUT=output format
OUTPUT_URL=output location


Substitute output format with rescue system format, for example, ISO for an ISO disk image or USB for a bootable USB.

Substitute output location with where it will be put, for example,
file:///mnt/rescue_system/ for a local filesystem directory or
sftp://backupuser:password@192.168.10.100/directory/ for an sftp directory or.
nfs://192.168.10.100/backup_dir/ for a nfs share.

Example1:
OUTPUT=ISO
OUTPUT_URL=sftp://backup:password@192.168.10.100/backup_dir/


Example2:
OUTPUT=ISO
OUTPUT_URL=nfs://192.168.10.100/backup_dir/


In the exmaple2 above i create the rescue ISO image on the server 192.168.10.100 using my nfs share /backup_dir.

Make rescure image with:

# rear -v mkrescue

Now look under /backup_dir on server 192.168.10.100 and you will see the newly created directory of your machine name with the ISO image in it.

If you like you can verify that you can boot from the ISO. Burn it to a CD/DVD, or like me, just create a new vm image and have this as the ISO CD/DVD and set to boot on start.

I can now boot off the rescue ISO but this does not do me much good if lets say i had a drive crash and all my files are gone. So say i have replaced the drive and I will also need to restore them to have a functional system again.

So lets add the option in the /etc/rear/local.conf file to tar a backup file. Our /etc/rear/local.conf file already contains the following:

OUTPUT=ISO
OUTPUT_URL=nfs://192.168.10.100/backup_dir/


Now lets append:

BACKUP=NETFS
BACKUP_PROG=tar
BACKUP_URL=nfs://192.168.10.100/backup_dir/
BACKUP_PROG_COMPRESS_OPTIONS="--gzip"
BACKUP_PROG_COMPRESS_SUFFIX=".gz"
BACKUP_PROG_EXCLUDE=( '/tmp/*' '/dev/shm/*' '/mnt/*' )
BACKUP_OPTIONS="nfsvers=3,nolock"


So the complete file looks like:

OUTPUT=ISO
OUTPUT_URL=nfs://192.168.10.100/backup_dir/
BACKUP=NETFS
BACKUP_PROG=tar
BACKUP_URL=nfs://192.168.10.100/backup_dir/
BACKUP_PROG_COMPRESS_OPTIONS="--gzip"
BACKUP_PROG_COMPRESS_SUFFIX=".gz"
BACKUP_PROG_EXCLUDE=( '/tmp/*' '/dev/shm/*' '/mnt/*' )
BACKUP_OPTIONS="nfsvers=3,nolock"


So i am using tar for my backup program, my backups will stored via nfs share to my backup server under the /backup_dir/, i will gzip the tar with extension .gz, and exclude /tmp/*, /dev/shm/*, and /mnt/* from the backups.

Lets test. Now run:

# rear -v mkbackup

After completed you should see the not only the rescue Image under /backup_dir/ on the backup server, but now the backup.tar.gz file as well.

Now to go through the rescue and restore procedure.

In this example i will use my vSphere ESXi 60 server and create a new image for this. I have uploaded the rescue ISO to a datastore and have the image mount this ISO at boot, so i can boot from it.

After the vm image is booted i am presented with the ReaR menu.

I choose Recover and press enter.
Login as root (no password required).
At the # prompt type in:

# rear recover
 
If asked if you want to restore your backup say y.

Now reboot server and login.

Enjoy!

No comments:

Post a Comment