Backup any linux Distro

Before you start

Most external hard disks come pre-formatted with a m$-based filesystem. A unix-based filesystem will be far more reliable, as well as faster to read/write.

In case you want to reformat your external hard disk, these are the commands :

Code:
#
# # NOTE : Format an external hard disk away from a m$ based filesystem, as user root :
# # NOTE : The disk will no longer be usable under m$ windows, because m$ windows
# # NOTE : will only read filesystem types FAT and NTFS.
#
# # NOTE : Once you've plugged the disk in, you should know the device/partition. 
# # NOTE : eg /dev/sdb1. Unmount the disk first, and don't get the wrong disk.
#
# umount /dev/sdb1
# fdisk /dev/sdb
#
# # NOTE : (in fdisk, use the keystrokes d to delete partitions, n for new partition, 
# # NOTE : t for type of partition (should be type 82) and w to write the changes. 
# # NOTE : m will give you help, p will print the partition layout.
#
# mkfs.ext4 /dev/sdb1
# tune2fs -L MyExternal /dev/sdb1
#

	

Some basics first

To back up linux (and any operating system), it is critical that the operating system is not in use at the time you take the backup.

This means booting the computer from another device; CD/DVD is most common, USB can also be used.

The neatest method I have found is to boot from a knoppix DVD. Knoppix is a complete linux distro on DVD that simply works.

Knoppix information and downloads are here.

Booting knoppix

Chuck the Knoppix DVD in, reboot the PC. (You may need to change your bios settings to make the DVD the primary boot device.)

Given the knoppix boot screen :
Either press return and knoppix will boot with default options. (Recommended).
I have a telly as my monitor, so I type 'knoppix 800x600' to boot into my unusual screen resolution.
At the boot screen, there is a < help > option for all the knoppix boot parameters.

Once Knoppix has booted, you will get a desktop. Start a terminal.


Mounting your own disks

I have three hard disks, called /dev/sda, /dev/sdb and /dev/sdc.

My operating system is under partition /dev/sda2, and I have plenty of space available on /dev/sdb2.

So I use these commands at the terminal command prompt:
You will need to modify these commands to suit your own system and partitioning setup.

Code:
#
# su - root
#
# mount /dev/sda2
#
# mount /dev/sdb2
#
# cd /media/sda2
#
# tar cvf /media/sdb2/BACKUP_1.tar *
#
#	

My operating system is currently 7 Gb, so I get a 7 Gb .tar file. I don't bother compressing it; it takes less than 10 mins.

DON'T forget to run those commands as root. "tar" will take the existing file permissions when run as root. If you run the tar command as non-root, you will lose the existing file permissions, thus making the backup worthless.

Restoring a Backup

Perhaps the most critical part; proving that the backup is valid, sound, worthwhile. I've tested this several times, by neccessity :-).
Be very careful when deleting. It is so easy to be in the incorrect directory when running a 'rm -rf ' command. The difference between 'rm -rf ./*' and 'rm -rf /*' is dramatic. And yes, I have made mistakes before. It's not a pretty outcome. Double check each command before you press return.

Reboot the PC into knoppix again, and start a terminal as before.

The most critical part is deciding whether to delete the existing operating system (recommended), or not. It all depends on how badly you have messed up the existing system.

The most powerful command in linux, as root, is arguably rm -rf /*

Desist the temptation to run this command !!
You are likely to make a reboot 'troublesome'.
Instead, go into each directory at the root level and remove the operating system one directory at a time, like this :

Again, you will need to modify these commands to suit your own system and partitioning setup.

Code:
#
# su - root
#
# mount /dev/sda2
#
# mount /dev/sdb2
#
# cd /media/sda2
#
# cd bin
# rm -rf ./*
#
# cd ../boot
# rm -rf ./*
#
# cd ../etc
# rm -rf ./*
#
# cd ../usr
# rm -rf ./*
#
# cd ../sbin
# rm -rf ./*
#
# ## note : perform the above commands, cd and rm, for each other directory
# 
# cd /media/sda2
# tar xvf /media/sdb2/BACKUP_1.tar
#
#	
Page hits : 1317