New To Linux? A Full Disk Backup Plan: Step-By-Step

General support questions
Post Reply
desertcat
Posts: 843
Joined: 2014/08/07 02:17:29
Location: Tucson, AZ

New To Linux? A Full Disk Backup Plan: Step-By-Step

Post by desertcat » 2018/11/05 02:11:53

INTRODUCTION:

Backups. Back in the day when the Linux Kernel was between 2.1 and 2.2, and using Linux was akin to living back in the days of the Wild, Wild, West, the byword was “backups”. You always made sure you had a current backup in the event something took down your machine. In the intervening years Linux has become ever easier to use, so much so that it is as easy if not easier to use than Windows. Gone are the days that when a new upgrade comes along you need to do a total re-install of the OS, rather now you simply “roll the system over” to the next version and be on your Merry Way. That said, for reasons unknown, I still make a backup before any major change that could potentially take my workstation down. "Rolling a system over" comes with its own pitfalls as I found out when I went to Roll Over CentOS 7.4 => 7.5. In all the years I have had to restore my machine from my backup exactly twice: Once back around 2001, and the second time when I tried to roll over the machine from CentOS 7.4 to CentOS 7.5. I was saved because I had a recent backup of 7.4.

For those who are new to Linux it can not be emphasized enough to backup your system. There are many, many ways to backup your system, and there are many, many programs out there that can do either full or partial backups; some totally automated, some manual. My system uses two FULL backups of the ENTIRE disk, unless I am preparing to do something that might take the entire machine down, in which case I do a FULL backup just before I set off into the wild blue yonder. The first Full Disk Backup is done just BEFORE a New Release is to come out -- such as right now; the second Full Disk Backup is made right AFTER the machine has successfully updated, I've made my tweaks, etc., and I'm relatively sure the system is stable. In addition I do automated weekly backups of all my partitions, just in case I accidentally toast a partition.

Today there are two points where you might suffer from a catastrophic failure: during and right after a major roll over. With the advent of the release of CentOS 7.6 within the next several weeks now is the time to start thinking about backing up your ENTIRE CentOS 7.5 disk. If worse comes to worse, you simple restore CentOS 7.5 from your backup.

For my automated backups I use a program called Backupninja. To install run yum install backupninja. It just gets easier, and easier.

To do a FULL backup of the ENTIRE disk is a little more complex, but not that much more. The following is a Step-By-Step method to backup your ENTIRE disk.

WHAT YOU WILL NEED:

1) You will need a Second Drive on to which you will store your backup.
2) You will need either a “Live” CD/DVD, such as any CentOS Live CD/DVD or – my favorite which everyone should have – KNOPPIX (currently available as KNOPPIX 8.2)

PROCEDURE:

(The following uses my machine as an example, simply modify for your machine. /dev/sda is the drive that contains my CentOS 7.5 and which I want to backup; /dev/sdb1 is the drive I which to backup to.)

Step 1: Shutdown your machine and boot with either your Live CD/DVD or KNOPPIX disk.

Step 1a: When KNOPPIX (or live CD/DVD) comes up start a terminal and type su.

Step 1b: Type fdisk -l and make sure that your BACKUP DRIVE (Destination) and the DRIVE THAT IS TO BE BACKUP can both be seen (WARNING: MAKE SURE YOU KNOW WHICH IS WHICH!!!)


Step 2: Mount the drive you want to backup to [ In my case it is a 2TB HDD that contains just a single partition and is labeled as /dev/sdb1]

COMMAND: mount /dev/sdb1 /mnt



Step 3: COMMAND: cd /mnt


Step 4: Issue the command that will start the backup:

COMMAND: dd if=/dev/sda conv=sync,noerror bs=64K | gzip -c > CentOS-7.5-1804_leopard_20181104.dd.gz


Simplified format: dd if=/dev/drive-to-be-backed-up conv=sync,noerror bs=64K | gzip -c > CentOS-Major_Release.x-year-and-month_machine-name_date-of-backup.dd.gz

Let it fly!! The backup will take a couple of hours depending on its size. I usually start the process just before I go to bed, and by morning it has finished. You will see the newly created backup when you look at your Backup drive. Now if you get hosed you can recover!!

hunter86_bg
Posts: 2019
Joined: 2015/02/17 15:14:33
Location: Bulgaria
Contact:

Re: New To Linux? A Full Disk Backup Plan: Step-By-Step

Post by hunter86_bg » 2018/11/05 05:00:21

I prefer the LVM snapshot method, which I use for my workstations.
So , high level description is something like this:

1. Verify you will have enough space which will be used by the snapshot. If you are tight in space , you can snapshot LV by LV instead of parallel backup of all LVs.
2. Create your LVM snapshot ( be sure that automatic snapshot expansion is configured on the system)
3. Mount your snapshot
4. Copy all your data from the snapshot to external media
5. Umount and Discard your snapshot and repeat the process for all LVs
6. Finally create full disk dump of your boot (you can always umount your /boot & /boot/efi ) via dd util

Note: If you backup DBs with this method, you need to set the DB in 'read lock' mode for the period the LV is created. It is the same approach that Virtualization engines take (a.k.a. quiesce).

Post Reply