Written by Robert -
It's always a good idea to have a systembackup. Normal backups are fine, but being able to recover an entire system is very useful.
For this situation I'm going to use mondo rescue, to provide me with a recoverable system. The advantage of this software is that it creates a bootable iso file that you can use to restore the system with. This can be burned on CD's, DVD's or just regular USB drives.
In this case I'm using this on CentOS 6. I need to add the right sources for it to work.
cd /etc/yum.repos.d/ wget ftp://ftp.mondorescue.org/rhel/6/x86_64/mondorescue.repo
Now let's update yum:
After this, we should be able to install mondo from the repository:
yum --nogpg install mondo
The reason we use the nogpg option, is because there is a small mistake in the repo where it shows the wrong key.
Adding a place where it can place the backups
I prefer to use sshfs for this purpose, since the storage I'm going to put the backups on has proper ssh support. To enable it on CentOS6, we need to enable fuse:
Before we can install sshfs, we need to enable the epel-release:
yum install epel-release
After that, we can install sshfs:
yum install sshfs
Now that's installed, we can create a directory where we can mount the sshfs share on:
Let's mount the share. In my case, the IP I'm putting the backups on is 10.10.205.134 and the user is root (it's just a local test). The directory on the computer that makes the backup is /mnt/backup and the device with the storage has the disk where I wish to place the backup on, mounted to /mnt/sda:
sshfs firstname.lastname@example.org:/mnt/backup /mnt/sda
Now the folder is mounted, you can verify that you can make and remove files on the share. If that all works, we can create a backup
Backing up the system
Mondo creates several different ways to make a backup. Because I'm using an sshfs mount, I will be using Hard Disk as the option:
Now we can select the location of the backups. This is where the bootable ISO images will be located:
The type of compression is personal. For me, the default option is good.
Maximum compression can take time, but it saves disk space.
The size is also something you need to define yourself. You can use the stock 4480 or you can change the size of it to something else. In this case I'm going to change it to 14000 but you can easily make it larger if you are going to use an external disk.
Now we can change the name to something you can recognize. You can use the server name, the ip address or something else that you can later recognize.
In most cases, it's best to use the / as the directory you wish to backup. There are exceptions, but changing this will result in a not bootable iso.
Here you can select all the folders you don't wish to backup. Be careful with this.
The temporary folder has to be located on the current system. This can't be in the sshfs folder that we mounted before.
You can put the scratch location on the sshfs share, like I'm doing here.
Extended attributes can be useful, especially with SElinux. This will take some extra time.
Your current kernel.
I'm a big fan of verification, especially with backups.
After pressing Yes, the backup will start.
When it's done, you should end up with a nice iso image that contains the data.
Restoring is pretty easy. I'm using virtualbox for testing purposes in which I can boot directly of ISO. In other cases you might have to burn this to a DVD, put it on a harddisk or usb stick, and boot from there. After booting the iso (use the first iso first), you get to see the menu.
It's pretty clear what the options are. I'm running this in a fresh virtual machine, so I'm going to just nuke it.
After it's done you get a screen similar to this:
Type exit to reboot and you should get a screen similar to this:
Your restore is complete, your device is back up and running. Just check your logs for errors and use the machine.
Now we know what options we want, we can use the options to create a nice way to do this without all the menu's.
First we are going to take the settings above and run this as a command.
You can find the options here: http://www.mondorescue.org/docs/mondoarchive.8.html
mondoarchive -O -V -p centos-mondo-backup$(date '+%d-%b-%Y') -i -E "/mnt" -I "/" -N -d '/mnt/backup' -s '14000m' -9 -G -S '/mnt/backup' -T '/tmp' -z #-O = create backup #-V = verify #-p = prefix name #-i = use ISO images #-E = directories to exclude #-I = path to backup #-N = exclude network directories #-d = backup device #-s = Maximum size #-9 = compression level 9, maximum compression #-G = use gzip because it's faster #-S = path of the scratch directory #-T = path of the temp directory #-z = save extended attributes
Putting it all together
We can now make a simple script to create a full system backup
#!/bin/bash # # Mount sshfs (this requires the use of ssh keys) sshfs email@example.com:/mnt/backup /mnt/sda # # Create the backup mondoarchive -O -V -p centos-mondo-backup$(date '+%d-%b-%Y') -i -E "/mnt" -I "/" -N -d '/mnt/backup' -s '14000m' -9 -G -S '/mnt/backup' -T '/tmp' -z #-O = create backup #-V = verify #-p = prefix name #-i = use ISO images #-E = directories to exclude #-I = path to backup #-N = exclude network directories #-d = backup device #-s = Maximum size #-9 = compression level 9, maximum compression #-G = use gzip because it's faster #-S = path of the scratch directory #-T = path of the temp directory #-z = save extended attributes # # Unmount share umount /mnt/backup # # Send log file to mail address mail -s 'Mondo full backup' firstname.lastname@example.org < /var/log/mondoarchive.log # # Done!
Now add this line to your crontab and you have automated a full backup of your device.