Following instructions will demonstrate how to create a full .iso image backup of a live CentOS 7 linux server.
There are many tools that can create an image of an entire Linux operating system, however, there is not many of them that are free and can do the hot transfer (backup while the Linux is running). One of the best tools I’ve tested is a Mondo Rescue free disaster recovery software. It supports Linux and FreeBSD and it is packaged for multiple distributions (Red Hat, RHEL, Fedora, CentOS, OpenSuSE, SLES, Mandriva, Debian, Ubuntu and Gentoo).
Backup to .ISO Image
Following instructions are for CentOS 7 (64-Bit).
First we need to cd to /etc/yum.repos.d and download the MondoRescue repository:
# cd /etc/yum.repos.d/ # wget ftp://ftp.mondorescue.org/rhel/7/x86_64/mondorescue.repo
When the repository was added, let’s install Mondo using yum:
# yum install mondo
Now we have two options, we can either run the Mondo Rescue in an interactive manual format, or use the command line to do so. I’ll briefly cover both methods.
SSH to your servers as a “root” user and run a mondoarchive command:
Once executed, you’ll see a following interactive screen. Use arrow buttons and enter button of your keyboard to select the backup destination for your .iso image.
Typically you’d want to backup to a Hard disk or a USB key:
Follow rest of the instructions. You’d be asked to:
- enter the full path name to the directory for your ISO Images
- type of compression (bzip2,bzip, gzip or lzo)
- how much compression (I usually select maximum)
- size of each ISO image in MB – I typically use the default DVD size (4480)
- name of ISO image file (this can be any file name)
- what parts of file system you want to backup (paths can be separated by ‘|’ character) – I’ll typically use an option ‘/’ which is a full OS backup
- option to exclude the file system that should not be in the backup (also separated by ‘|’ for multiple paths) – note: “/tmp” and “/proc” are always excluded
- enter temporary directory path (here I usually just type ‘/tmp’) – this is where the temporary files are created during backup
- scratch directory path (leave on the default setting)
- backup extended attributes (just press enter here)
- select YES to Verify your backup
- when you come to question about a ‘stable standalone Linux Kernel’ just click “Yes”
- Select “Yes” to proceed further. This is where backup with start and depending on the size of your Centos install it may take anywhere from minute to hours to complete.
As you see, instructions are very self explanatory and you shouldn’t run into any issues following them.
Command Line Mode
SSH to your servers as a “root” user and run a mondoarchive command similar to this one.
Note: you’ll need to adjust it to your needs:
mondoarchive -O -V -i -s 4480m -d /mnt/windows/share_data -I / -E /mnt/windows/share_data -T /tmp -9
Above command will do following:
-O – Means: Do a backup.
-V – Instructs Mondo to verify the results.
-i – Select .ISO image backup as a form of backup format.
-s – Size of ISO images – In my case 4480 is a DVD size.
-d – The destination where each ISO image file will be saved. In my case: /mnt/windows/share_data (this is a windows network share mounted into Centos 7 and also the destination for my backups). If you want to learn how to mount a windows drive to Linux, follow these step by step instructions on How to mount a windows share on CentOS 7 (RHEL). In any case, you can create a backup into any folder on the existing drive (same drive that’s being hot backed up) – just make sure to later exclude that destination from a backup.
-I – Specifying ‘/’ (same as in the interactive mode) will back up the whole system (with exception of excluded paths).
-E – This is what you want excluded from a backup and that is typically the destination of a backup, so in my case: /mnt/windows/share_data
-T – location of the temp directory. I usually point to /tmp folder which is by default also excluded from a full system backup.
-9 – Instructs Mondo to use maximum compression (this can be any value, but maximum compression will result in the smallest possible ISO images).
Note, if you want to create an incremental backup instead of a full backup, add additional option switch to above line:
-D – This will instruct Mondo to create a differential backup on top of original full backup created using options above.
Once entered into terminal, you’ll see similar screens to these. Attaching couple of screenshots:
Once you enter above command (edited to your liking), backup with start and depending on the size of your Centos install it may take anywhere from minute to hours to complete.
Scheduled backups using command line and cron:
As you can imagine, the biggest advantage of running in a command line mode is the ability to schedule a backup using cron job.
All you need to do is to create a simple backup.sh application shell script and save it somewhere in Linux your file system:
#!/bin/bash mondoarchive -O -V -i -s 4480m -d /mnt/windows/share_data -I / -E /mnt/windows/share_data -T /tmp -9
Once backup.sh is created, schedule it using a cron job. To add it to your cron jobs, simply type the following command in the Linux shell prompt:
and add in the line:
0 1 * * * sh /home/backup.sh
Above means: Run backup.sh script at 1:00 am on every day of every month. Or in other words:
- 0: Minute (0-59) – 0 minute
- 1: Hours (0-23) – at 1 AM
- *: Day (0-31) – of every day
- *: Month (0-12 [12 == December]) – of every month
- *: Day of the week(0-7 [7 or 0 == sunday]) – of every day of the week
- + path to where I’ve saved the script: /home/backup.sh
You can adjust this to your liking.
If you’re using Webmin, it’s even easier, simply schedule it like this to run Daily (at midnight):
Restore from .ISO Image
Now that we’ve created an .ISO backup of our entire CentOS 7 Linux in either interactive of manual (command line) mode (instructions above), you’re probably asking how to go about restoring the system from the image in case you need to do a disaster recovery.
You have couple of options to do this. You can either:
- restore entire system
- or only restore the files and folders you want
In any case, all you have to do is to burn all of the .ISO images created during backup onto DVDs and then insert the first .ISO disc into the DVD drive. As soon as the Linux boots from the first .ISO DVD, you’ll be greeted by the following options:
As you can see, your restore options are: NUKE, INTERACTIVE, COMPARE and EXPERT.
Option ‘NUKE’ is a bare metal restore. This is a fully automated restore in which the hard drive and all its file-systems will be completely destroyed and re-created from the backup to the exact same state it was backed up from.
Another option is to type: ‘INTERACTIVE’ and select what you want to restore: full automatic restore, one or more files or folders – interactively, or run a compare only.
Mondoarchive in interactive mode looks like this:
This option will not restore anything – it’ll just compare current OS to the one in your backup (thus called: compare). This is the option to choose in order to verify the viability of your backup or to also discover which files have changed since the last backup.
EXPERT mode allows you to enter into a command line mode and completely control every aspect of the restore – while it gives you the most options, it’s too complicated to be covered in this article.