Posts Tagged tar

LCOD – 8.10.05 – How to net backup/restore using tar|ssh|dd

Ok, so you read the dd LCOD and tried it out, but you have a 250GB drive and only about 10GB data.. so you’d prefer if you only read the files that were actually there, and not your 100GB of deleted data.

Well, here’s what I do. On the computer to be backed up I boot a linux live cd (such as knoppix from knopper.net), and mount the disks, on say, /mnt/disk and since I use gentoo I have /boot seperate and mount it on /mnt/disk/boot, so I only have to take 1 image/backup.

Then I make sure networking is up.. it all goes something like this

Code:
mkdir /mnt/disk
mount /dev/hda3 /mnt/disk
mount /dev/hda1 /mnt/disk/boot
cd /mnt/disk
tar -zcvf – * | ssh user@192.168.0.XThis e-mail address is being protected from spam bots, you need JavaScript enabled to view it dd of=/home/user/backup.tar.gz

Then we get the prompt to accept the key, put in our password and wait. The v in the -zcvf will give us verbose output, if you just want to wait you can omit it and not see each file as it goes. This will create a tar archive of all the files in that directory, gzip it and put it to standard out, which redirects to ssh to 192.168.0.X as user “user”, and then pipes it to the dd which puts it into the file /home/user/bakcup.tar.gz

Now, on to the restore part… So you have this image, and you want to put it onto another computer.. Well this is kind of like installing gentoo, so boot to your trusty linux cd, open a console and follow these steps..
create your partitions using fdisk (here’s an fdisk howto http://www.tldp.org/HOWTO/Partition/partition-5.html)

Now I’m going to assume you’ve made /dev/hda1 as your /boot /dev/hda2 as your swap and /dev/hda3 as your / (root) partition.

To format your disks use the mkfs commands like this

Code:
mke2fs /dev/hda1
mkreiserfs /dev/hda3
mkswap /dev/hda2

now that you have your disks setup, lets mount them, its just like above is we use /mnt/disk as the mount point, and run our restore, which is just like the above command but reversed… note you could probably use cat instead of dd… and a > instead of dd on the creating side above..

Code:
mkdir /mnt/disk
mount /dev/hda3 /mnt/disk
mkdir /mnt/disk/boot
mount /dev/hda1 /mnt/disk/boot
swapon /dev/hda2
cd /mnt/disk
ssh user@192.168.0.XThis e-mail address is being protected from spam bots, you need JavaScript enabled to view it dd if=/home/user/backup.tar.gz | tar -zxvpf  -

note: the – at the end of the the tar command means standard in/out

So now you’ve got your data restored exactly as the system was at last shutdown, on a new file system. If you changed your disk layout, you’ll want to update /etc/fstab and the final thing we need to do is reinstall grub so the system boots to it. To do that we need to chroot, just like a gentoo install
assuming your disks are still mounted on /mnt/disk

Code:
chroot /mnt/disk /bin/bash
grub
root (hd0,0)
setup (hd0)

Assuming your disk is 0,0 (first IDE drive, slice is /boot)
You can use the tab key in grub to see what disks are available, so type root (hd
and hit tab
and it’ll say 0,1,2 or something telling you which disks are available

That’s it, now exit the shell and reboot like this

Code:
exit
cd /
umount /mnt/disk/boot
umount /mnt/disk
swapoff /dev/hda2
reboot

don’t forget to remove the CDROM when you reboot (knoppix will eject it and ask you to hit enter once its out)

Now you should get your old OS booted back up, FYI if you’re imaging lots of systems you may want to edit your config files for your network if you’re not using DHCP (/etc/conf.d/net on gentoo) so the machines don’t all try to come up with the same IP address.


When imaging systems with server services, specifically SSH, is that you should change your server key, in fact, it’d be best if you deleted your keys BEFORE you created your image, so that when the server boots up it’ll generate its own keys upon starting SSH. Having your SSH private keys in any type of unsecure location is a BAD idea…

to delete your keys simply

Code:
/bin/rm /etc/ssh/*key*

, , , , ,

No Comments

Easy AdSense by Unreal