How to Backup Linux Installation

asb002

Member
Feb 17, 2003
122
0
0
Here's the situation: I need to wipe the Linux partitions off my drive until I can get a bigger one. I have Gentoo Linux installed, and it takes up ~6gb. I have another Linux server on my network, accessible via Samba or NFS, and I want to put some kind of tarball or perhaps a drive image of my linux install on that remote server. Any ideas?
 

cleverhandle

Diamond Member
Dec 17, 2001
3,566
3
81
Yup, I like plain old tar also. Though it probably doesn't matter, I always feel better if I can be completely outside the system when I tar it - i.e. boot to something like Knoppix and mount the drive. If you back up to NFS you may need to export your shares with "no_root_squash", since you'll want to be root in order to have read permissions over the entire system you're backing up. Maybe that's not necessary - I always have a spare disk partition so I'm just guessing. When you want to restore, just untar and (if necessary) reinstall the boot loader. For LILO, that's lilo -r /path/to/root/filesystem, don't know about GRUB.
 

manly

Lifer
Jan 25, 2000
13,589
4,239
136
Don't you have to do someting special about /dev files?

If you think about it, all you really need to preserve are /home and /etc.
 

asb002

Member
Feb 17, 2003
122
0
0
tar zcvf /path/to/new/tar/file.tar.gz /
About the tar command: Wouldn't tarring the entire / cause the tar file itself to be tarred, therefore sending it into a loop? I'm not sure if that could actually happen, but if so, how could I get around that?
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
Originally posted by: asb002
tar zcvf /path/to/new/tar/file.tar.gz /
About the tar command: Wouldn't tarring the entire / cause the tar file itself to be tarred, therefore sending it into a loop? I'm not sure if that could actually happen, but if so, how could I get around that?

Good question. I tried it and it just errored out with "file changed as we read it." Personally, I tend to tar up individual directories, and not image/restore the OS. I like reinstalling every so often, although I can't really quantify why that is. Anyways, I usually just tar up individual directories in my home directory, then /etc, /var, /root, /usr/local, and any other place I might need to, then I just arrange those in the best way to fit on cds, and then burn them.

asb002, you should look into mondo, I have heard it's really good for this type of thing.
 

StuckMojo

Golden Member
Oct 28, 1999
1,069
1
76
tar works fine
nfs mount your other machine on /mnt then:

tar cf /mnt/backup.tar --exclude mnt --exclude proc /

you can toss a j or z in there for compression if you feel you want it
the tricky part is restoring. i boot from the install floppies, partition the drive, create the filesystem, than ctrl+alt+f2 (or 3 or 4, depends on the distro on the floppies) to get a shell. then:

ifconfig eth0 192.168.0.2 netmask 255.255.255.0 up
(replace with your IP/mask)
then either nfs mount your other box again and copy the tar file over, or use wget (its on the debian floppies for sure) or ftp to ftp it over to your new /
then:
tar xf backup.tar -C /
lastly run lilo to make the system bootable, or use a boot floppy to boot and mount the drive as root, then run lilo (or grub, whatever)

i'm actually in the process of doing this "as we speak" ;)
 

asb002

Member
Feb 17, 2003
122
0
0
Thanks for all your help, I eventually dug out my Norton Ghost and used a spare drive as a clone, but I'll keep those other options in mind.
you might want to check out http://www.partimage.org/ ... its the GPL equivalent to ghost, not quite as refined, but it does work...used it several times myself.
That looks quite interesting, I'll need to try it, thanks Need4Speed.
 

cleverhandle

Diamond Member
Dec 17, 2001
3,566
3
81
Originally posted by: asb002
tar zcvf /path/to/new/tar/file.tar.gz /
About the tar command: Wouldn't tarring the entire / cause the tar file itself to be tarred, therefore sending it into a loop? I'm not sure if that could actually happen, but if so, how could I get around that?
Yes, you need some kind of trick if you're actually going to sit in / while you tar it - another reason I like to have a separate system. Like StuckMojo said, one way is use the exclude flag for tar. Another is to use SSH -

tar czf - * | ssh othermachine "cat > /path/to/backup/file.tgz"

which is easier IMO than messing around with NFS and exports. You can umount /proc before starting too, so no need to define exclusions.

edit: formatting is kind of bad - note the "-" after the f. That's sending tar's output to standard out, i.e. to SSH through the pipe.
 

drag

Elite Member
Jul 4, 2002
8,708
0
0
I've copied Linux from a floppy to a ancient laptop a long time ago. I don't remember all the details...
/dev/ folder is for special files... you can run a script that is usually suplied by the distro. Something like mkdevdir or something, but since gentoo uses the devfs demean all that stuff is handled automaticly...

If you just tar the / directory you are going to try to eat the /proc directory and that isn't going to work. Since the proc directory has virtual files holding the information of of proccesses you are going to try to copy a file that is monitoring the copy as it tries to copy itself... (It's not going to work)

The same may be true with the tmp, but that you don't have to worry about.
/etc/
So if you want to back up your entire OS, just make a tar ball of /boot /etc /home /lib /bin /sbin /root /usr /var the kernel if it wasn't already in /boot

Then to restore it you untar then into the root directory, make /tmp /proc /mnt/* /dev directories. Run the makedev script if you need to. Edit the /etc/fstab and /etc/lilo.conf or the /boot/grub stuff to match your new configuration if need be. Then re-run grub or lilo and you should be set.

You can probably do this all from your gentoo install cd.

I am not sure though if you need to do something extra for the /proc or /dev files... I think that it should figure it out on it's own, I am probably missing a couple other details. So you may want to test it out before if it's critical information.

However, that being said:
Most of the important stuff is you have /home folder (maybe /root, too, but it realy shouldn't be) and the /etc/ folder. All your user spefic setups and configs are in your home folder hidden in .folder files. (the . before the file name makes then normally hidden) And the /etc/ is for system wide configuration files. I'd personally just back those 2 up, because they probably take the most work for you to set up. If you didn't have all that much done in the /etc/ folder like setting up Apache with a special setup I wouldn't even back that up. The rest of the stuff can be regenerated automaticly on a reinstall. Then after you untar the install tarball and install that OS over again then download your /home tarball and untar it in the right spot. I do that when I install so I don't loose my information. Then you have to do the chown and chgroup stuff so that the files will be owned by you (your uid and guid numbers are the important information for file ownership, your login name is just for human convienance)

Just when you reinstall Gentoo and you made a backup of /etc/, make sure that you don't enable it to overright the /etc/ files automaticly if you untar it before the install!

ALso for niceties you can make a backup of all your downloaded and stored files you downloaded and installed in your /usr/portage/distfiles That's were all those tarballs you downloaded to install Gentoo are stored. If you back those up and then put them back in the same spot during the next install you don't have to re-download them. Out of a 6-gig install they probably take up close to 2 gig of that space. That way you can save a bit of load off of the mirrors, plus save yourself the time of re-downloading over a gig of information again.
 

TonyRic

Golden Member
Nov 4, 1999
1,972
0
71
/proc is not an issue if you are booted to another distro ala knoppix or even RH CD1 and chroot your environment. But, as stated above you would want to exclude the mounted destination disk. I missed that part. If devfs is used then /dev is not an issue either.

I never thought of piping through ssh like cleverhandle suggested. HMMMMM, now I have a couple scripts to fix. ;)
 

Chaotic42

Lifer
Jun 15, 2001
35,383
2,502
126
If you have a bunch of stuff mounted, use -X to stay on the / filesystem. Also make sure you preserve the permissions. I speak from experience here!
 

drag

Elite Member
Jul 4, 2002
8,708
0
0
Also a nice ssh trick is used for peircing firewalls. If you have 2 servers behind a nat firewall, or one that has extremely hard to get around rules, but you can login externally thru ssh you can setup a pppd connection over ssh and do all your telnet/ftp/http etc etc stuff in perfect privacy.... :) very usefull.

Also scp is great.