1. HOWTO Backup/Restore with RAID and LVM
- HOWTO: back from Ubuntu formussome alternative
- LVM Snapshots can also be used but not for perminant backups.
This is how I do it.
To backup is simplicity itself, as it is Linux and not M$ Windows
we just need to tar/zip up the files and it's job done! I use this script and run it with sudo backup.sh.
#!/bin/bash
####################################################
#
# Setup some environment variables to save time later
# if I needto change destination or type of backup, Just change the varaible
# once and all the commands change. Saves making mistakes![]()
#
####################################################
DEST=/data # destination dir path, where the data is going to be stored
MACH=`hostname` # Find hostname of the machine being backed up
DIR=/backup_$MACH # subdirectory where the backup is to be stored
TAR_CMD="sudo tar" # the command to create the tar file
TAR_OPT=zcvpf # command line switches for tar command
TAR_EXT=.tgz # file extension we we knowe thatit is a tar gzip file.
TAR_EXCL="--exclude-from=/home/richard/bin/exclude-from"
# if the mounted drive where the backup file will be stored does not exist, mount it
if [ ! -d $DEST$DIR ] ; then
sudo mount -a
mkdir $DEST$DIR
fi
####################################################
#
# copy some files I may need. it just keeps them handy.
# they also come in handy when playing around on another machine. (Good reference material)
#
####################################################
cd /home/richard/bin
cp *_${MACH}.sh exclude-from $DEST$DIR cd /etc
cp fstab exports samba/smb.conf $DEST$DIR
cd /boot/grub
cp menu.lst $DEST$DIR
####################################################
#
# Now to start the Backup process
#
####################################################
cd /
FILE=root
$TAR_CMD $TAR_OPT $DEST$DIR/${MACH}_$FILE$TAR_EXT $TAR_EXCL \ ./bin ./cdrom* ./etc ./initrd* ./lib* ./root ./sbin ./srv ./vmlinuz* &
for FILE in home boot var usr
do
$TAR_CMD $TAR_OPT $DEST$DIR/${MACH}_$FILE$TAR_EXT ./$FILE $TAR_EXCL $BACK done
cd /data
for FILE in popfile wine www
do
if [ -d $FILE ] ; then
$TAR_CMD $TAR_OPT $DEST$DIR/${MACH}_$FILE$TAR_EXT $TAR_EXCL ./$FILE fi
done
cd $DEST$DIR
for FILE in root boot home usr var popfile wine www
do
if [ -e ${MACH}_$FILE$TAR_EXT ]; then sudo chown richard:richard ${MACH}_$FILE$TAR_EXT fi
done
echo All Done...
Line-by-line description:
- Run as a bash shell script.
- Setup some variables with script defaults. This way if you decide you want to change the destination.
- DEST=/data # destination dir path, where the data is going to be stored
- MACH=`hostname` # Find hostname of the machine being backed up
- DIR=/backup_$MACH # subdirectory where the backup is to be stored
- TAR_CMD="sudo tar" # the command to create the tar file
- TAR_OPT=zcvpf # command line switches for tar command
- TAR_EXT=.tgz # file extension we we knowe thatit is a tar gzip file.
- TAR_EXCL="--exclude-from=/home/richard/bin/exclude-from"
directory you only have to change in one place. Saves unnecessary problems if you miss an occupancies.
- $TAR_OPT this is what it means
- z compress the file with gzip, use j for better/slower compression with bzip2
- c copy the data into the tar file
- v verbose, so we see stuff happening
- p to preserve permissions etc.
- f tell tar to output to a file.
- --exclude = "do not tar this directory
- finally the ./ tar up everything in this directory and below.
- Check that the destination directory is mounted. I'm going over the network to another linux box.
- Save some config files I always have to change. these come in handy when playing around with stuff so I keep them handy.
- Change directory to root.
- We are going to back up the '/' or root directory but only the subdirectories listed. This is backed up in the background.
- Next we have loops to backup home boot var and usr
- Then we change directory to /data and backup popfile .wine and www (my off-line scratch box web site)
That is all there is to the backup. You will need to change which directories you backup and where you put the generated files.
2. HOWTO restore my backup
The restore is a little bit tricky. So pay attention. 
I am assuming we are putting back the backups to empty disks. The first problem is how do we get booted up. I use the system rescue CD. It has everything I need and it's updated regularly. Home page for SystemRescueCD
Place the CD into your CD/DVD player, you can boot from it can't you? (You may needto tweak some BIOS settings if you cannot.
Once presented with the command line to boot up the SystemRecuseCD I normally use something like this
rescue64 dolvm2
After a minutes or two your machine will spring into life. If you want a pretty Xwindows GUI interface use
startx
2.1. Partition the blank disks.
Use gparted to create blank partitions as necessary. Remember for LVM logical partitions do not put a filesystem on the partition, Yet!
For my system, 3x250Gb hard drives, dual booting with that other OS. I always put the MS-doz on the first partition on the drive and make it a Primary. So my three drives looked like this when this was written.
- /dev/sda1
- 250 Mb - /boot partition. (Note this is Megabytes in size)
- Primary
- Beginning
- Reisersfs (This has a file system as it is the boot partition)
- bootable ON
- Label - boot
- 1 Gb - less 250Mb Swap
- Logical
- Beginning
- SWAP
- 209 Gb - LVM Physical partition. (make a note of the device name /dev/sdaX)
- Logical
- all remaining space
- LVM
- 250 Mb - /boot partition. (Note this is Megabytes in size)
- /dev/sda2 & /dev/sda3
- 1 Gb Swap
- Logical
- Beginning
- SWAP
- 209 Gb - LVM Physical partition.
- Logical
- all remaining space
- LVM
- 1 Gb Swap
With the partitions all created we can create the LVM stuff. From the above i will have three partition all with around 209 Gb of free space. Now to put these all together as one striped partition (RAID0) of around 627Gb.
2.2. Create the physical volumes
We need to initialise the free partitions on the three disks so they can be used by LVM. It is a little like formatting a drive. (All data will be lost, although after using gparted they are most probably blank anyway. 
Use the following to see a list of all block devices and remind yourself of the device name for the partitions to use.
sudo lvmdiskscan
sudo pvcreate /dev/sda6 /dev/sdb5 /dev/sdc5
You can use the following commands to see the physical volumes once they havw been created.
sudo pvscan
sudo pvdisplay
2.3. Create a Volume group
We want to create one big new LMV volume group from the three physical volumes we just initialised above. to create a volume group called vg01 out of the physical volumes /dev/sda6 /dev/sdb5 /dev/sdc5. You may need to change the device names. Run the command below and you should have an Uncle Bob. *grin*
sudo vgcreate vg01 /dev/sda6 /dev/sdb5 /dev/sdc5
To see the volume group you just created use these commands
sudo vgs
sudo vgdisplay
Sometimes when you boot from the SystemRescureCD it does not make the LVM volume group available. This is not a big problem as you can do it yourself with the following command
sudo vgchange -a y vg01
2.4. Create the logical volumes (within the Volume group)
Now for the good part where we create the logical volumes that we will then put a file system on and mount as root, usr home etc.
Note: It is really very simple to make LVM logical volumes bigger and if you use reisersfs you can do it while the file system is mounted and even in use at the time. (Although it's better not to be copying data to it)
To create a root partition of
- that is 5Gb in size
- with striping across three disks
- a block size of 32K
- calling the new logical volume lv_root
- carving it out of volume group vg01
sudo lvcreate -L 5G -i2 -I32 -n lv_root vg01
Repeat for the other logical volumes These are what I usually start with and go from there.
| Size | Striping | Block | Name | VolumeG |
| 5G | -i2 | -I32 | -n lv_usr | vg01 |
| 5G | -i2 | -I32 | -n lv_var | vg01 |
| 5G | -i2 | -I32 | -n lv_home | vg01 |
| 50G | -i2 | -I32 - | n lv_data | vg01 |
There are some nice commands to display the logical volumes just to make sure. The first command will show how name stripes you are using.
sudo lvs -o +stripes
sudo lvdisplay
and also to see logical groups and how they are setup.
sudo lvs
sudo lvdisplay
As with volume groups the logical volumes sometines end up unavailable this can be fixed with the following.
sudo lvchange -a y /dev/vg01/lv_root
2.5. Finally putting a file sytem on.
Almost there we need to put a file system on the plogical volumes we just created. I like to use a lable for each partition. I find it easier to work out which partition is which in the fstab file. Which do you prefer
LABEL=root ...
UUID=34a54a33-3b43-f53d45345 ...
To format the logical partitions
sudo reisersfs -lable root /dev/vg01/lv_root
sudo reisersfs -lable home /dev/vg01/lv_home
sudo reisersfs -lable var /dev/vg01/lv_var
sudo reisersfs -lable usr /dev/vg01/lv_usr
sudo reisersfs -lable data /dev/vg01/lv_data
2.6. Mounting the logical partitions
Mount the partitions so that you can get to each mount point to restore the data as necessary. In the root partition make the following as they are mount points or are not backed up. Also tmp needs the sticky bit set.
sudo mkdir -p /mnt/root /mnt/home /mnt/usr /mnt/var /mnt/data
sudo mount /dev/vg01/lv_root /mnt/root
sudo mount /dev/vg01/lv_home /mnt/home
sudo mount /dev/vg01/lv_usr /mnt/usr
sudo mount /dev/vg01/lv_var /mnt/var
sudo mount /dev/vg01/lv_data /mnt/data
cd /mnt/root
sudo mkdir -p boot data dev home mnt opt proc sys tmp usr var /run var/lock /media/c_win /media/d_win /media/e_win
sudo chmod ag+w,a+t tmp
2.7. Restore the data back to the partitions
For the root partition you need to be in /mnt/root when you issue the untar command. For all other partitions you chould cd to /mnt and then untar the data.
cd /mnt/root
sudo tar zxpf /opt/linux32_data/linux60_root.bz2
cd /mnt
sudo tar zxpf /opt/linux32_data/linux60_usr.bz2
Check that fstab is correct and pointing at the right place for each mount point. Do the same for /boot/grub/menu.lst
2.8. Now to put grub back on.
I am going to give you the commands and then I will explain them later.
linux32 it is 'root (hd1,0)' & 'setup (hd0)'.
linux60 it is 'root (hd0,1)' & 'setup (hd0)'.
Ok, now to explain, what is going on. You need to open a grub shell, this will get you a "grub>" prompt.
sudo grub
At grub>. enter these commands to find where the grub stage1 files is stored.
find /boot/grub/stage1
This will return a location. If you have more than one, select the installation that you want to provide the grub files. Next, THIS IS IMPORTANT, whatever was returned for the find command use it in the next line (you are still at grub>. when you enter the next 3 commands)
Note: When setting root (XXXX) or setup (XXX) (hd0,0) means the first drive and the first partition. (hd2,1) means the third drive and the second partition). For setup (hd0) with no drive means the MBR and not a boot sector of a drive.
Set root to point to where you grub stage1 files are and setup will write the boot sector files to either the MBR or the boot sector you choose. Again use the value from the find command i.e. if find returned (hd0,1) then you would enter root (hd0,1)
root (hd1,0)
Next enter the command to install grub to the mbr
setup (hd0)
Finally exit the grub shell
Reboot.
3. HOWTO Back up with Partimage for backing up Windows
The documentation is really bad for Partimage, only tells you the obvious stuff :-(
Boot with the SystemRescue disk then run net-setup eth0 to setup the network.
net-setup: eth0
Ip: 192.168.0.7
Gateway: 192.168.0.1
Names server: 192.168.0.5
Bcast: 192.168.0.255
Mask: 255.255.255.0
DNS: 212.69.36.3 & 212.69.40.3
ifconfig to check everything is sorted out.
Try ping 192.168.0.5 just to check we have them talking ok. Make a directory to mount the remote directory where we are going to store the image and then mount the remote directory.
mkdir /backup
mount 192.168.0.5:/data -t nfs /backup
save image to /backup/disk_image/some_name no need for an extension as .000 , .001 will be added as the image is created.
press f5, f5 enter description if required, ok the experimental thingy. and you are off and imaging.
Partimage is really very good, better than Ghost4linux which I found to be unreliable and painfully slow very much like the commercial program with a similar name. Partimage produces smaller images but is a little slower than Acronis.