LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-28-2008, 04:40 AM   #1
Stin
LQ Newbie
 
Registered: Feb 2008
Distribution: Redhat 7.3 Valhalla, Solaris 8, HP Tru64
Posts: 25

Rep: Reputation: 15
Linux backup/restore


Hi guys,

I'm a little stuck with writting a backup procedure to backup a redhat machine to a remote server.

What I have so far is an NFS mount to a different server where I will be sending the backups.

I've been using dd but the images are therefore HUGE!!!

What we've decided to do is use dd to backup /root and /usr
Then something like tar to take the files from the other partitions.


if /root is /dev/hda1 and /usr is /dev/hda3

I can:

dd if=/dev/hda1 of=/nfs_mount/root.img
dd if=/dev/hda3 of=/nfs_mount/usr.img
<tar for the rest of them>


Now lets say the machines hard disk goes POP! and i have to put in another. It's going to be exactly the same size, brand and type.
This new disk isn't going to know about that partition information. How do I tell it?

Many thanks in anticipation.

Stin
 
Old 05-28-2008, 05:34 AM   #2
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
Well you could take an exact copy of the whole disk with dd, and in that case you wouldn't need to worry about anything else: in case of a breakup you could just put the image back to the new identical disk and once it was written, the system ought to work like before. Drawback is the image file size, which you noticed (even if the disk usage was for example 2 gigabytes and disk size was 500 gigabytes, the image would be 500 gigabytes if you didn't make any trickery).

I would suggest using another approach than images in that case; tar is all right, but there are other options. For example dump and restore.

In the usual case you would take either one full backup and then incremental backups, or just full backups depending on how you like it, and when things got bad, you would just get a new disk (if needed), reinstall the operating system and then put back the files. This is an easy approach, as far as you remember how your partitions were laid (if it matters), and the only thing you'll be missing are the programs that were installed after the setup (those that don't get installed when the operating system is freshly installed). This can be solved by making a list of installed software and using that list with an automated package manager after re-installation, but it depends a little on which distribution you are using. For example with Debian and alike you could use dpkg to create a plaintext file which contained all your installed package names, and after re-installing the OS you could just use that list with apt-get to have it install all the software you previously had. Then just dump back the backup and it's there.

Edit your profile information and fill in the operating system (/distribution) you are using; it helps answering to distribution-specific questions.
 
Old 05-28-2008, 06:09 AM   #3
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,062

Rep: Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893
Quote:
What we've decided to do is use dd to backup /root and /usr
Then something like tar to take the files from the other partitions.
There shouldn't be much on either /root or /usr that you need to backup regularly. But that assumes that you still have access to install media (do you still have them? do you know that they haven't succumbed to bit rot? can you still find them?) and know what you did in the install.

There will still be a few files, but the simplest way to deal with that is to make copies somewhere that does get a regular backup. (You need to backup /home, but do watch out for conf files in other places that you probably want backed up, too, even if you don't want to re-install them automatically.)

For the other stuff, have you considered rsync or unison to keep a disk volume in sync and backing that up to a removable medium occasionally?

Quote:
Now lets say the machines hard disk goes POP! and i have to put in another. It's going to be exactly the same size, brand and type.
This new disk isn't going to know about that partition information. How do I tell it?
I used to keep a paper record of the partition table, but... In the interim, I've found that every time I replace an old disk with a newer one (not often...) the newer one is much larger, so I don't need the paper copy for that reason, because the disk size allows me to get 'sloppier' with the exact layout. And, provided its big enough (and fast enough), what's the problem?

It probably still is useful to keep a record, not on the disk itself, of how each partition was set up (per partition mount options, filesystem type) even though in most cases you won't need it.

Most distributions have an equivalent of the kickstart tool which can be used to clone installations, and you could also consider that, depending on what your distro provides.
 
Old 05-29-2008, 08:00 AM   #4
Stin
LQ Newbie
 
Registered: Feb 2008
Distribution: Redhat 7.3 Valhalla, Solaris 8, HP Tru64
Posts: 25

Original Poster
Rep: Reputation: 15
Thank you for the detailed response, I'll give you a little bit more background.

Please excuse my lack of knowledge, I've been navigating round unix systems for a little while now, but I'm new to the system administration side of things.

I'm looking to backup a number of Redhat machines (various releases) by mounting an NFS drive on another remote server. These redhat machines are pretty static. Nothing much changes on them over time. However they have been in the field for a few years now, and one in particular is making a strange sound. Therefore I have been tasked to back all of them up. I don't need to take regular backups. This is a once in a while thing.

My test bed is a Redhat Linx 7.3 laptop and a Sun V100 server running Solaris 8.
What I've managed to do is NFS mount a drive from the V100 and use dd to backup the RH laptop to it.

dd if=/dev/hda of=/nfs_mount/backup.img

I have successfully restored from this image by using system rescue CD booting it on the RH laptop, entering IP address, mount the NFS drive, and then:

dd if=/nfs_mount/backup.img of=/dev/sda (the system rescue cd shows it as sda).

And this works fine. However the laptop has a 40gb hdd and so the image is 40gb. This is not practical for use in the field. Therefore we decided that it would be best to use dd for /root and /usr and tar for the other partitions.

I think what I need to know now is:
  1. How to take a record of the partition table (what command to show it)
  2. What do I need to do to create the same partition table on a new disk (what commands to execute)
  3. I have a dd backup of my entire Redhat test machine, is there anything I can do to replicate swapping the disk for a brand new one and recover? can I wipe the disk clean and drill the dd/tar restore process?
  4. If, I've done dd if=/dev/hda1 to backup /root, and I need to restore that to another disk, do I need to make the partition the exact same size or can I make it larger?

If you can spare the time to help me I would greatly appreciate it.

Many thanks in anticipation.

Stin.

Quote:
Originally Posted by salasi View Post
There shouldn't be much on either /root or /usr that you need to backup regularly. But that assumes that you still have access to install media (do you still have them? do you know that they haven't succumbed to bit rot? can you still find them?) and know what you did in the install.

<SNIP>

Most distributions have an equivalent of the kickstart tool which can be used to clone installations, and you could also consider that, depending on what your distro provides.

Last edited by Stin; 05-29-2008 at 08:07 AM. Reason: wierd formatting
 
Old 05-29-2008, 08:56 AM   #5
Stin
LQ Newbie
 
Registered: Feb 2008
Distribution: Redhat 7.3 Valhalla, Solaris 8, HP Tru64
Posts: 25

Original Poster
Rep: Reputation: 15
OK so I've done a little digging:

Quote:
Originally Posted by Stin View Post
I think what I need to know now is:
  1. How to take a record of the partition table (what command to show it)
  2. What do I need to do to create the same partition table on a new disk (what commands to execute)
  3. I have a dd backup of my entire Redhat test machine, is there anything I can do to replicate swapping the disk for a brand new one and recover? can I wipe the disk clean and drill the dd/tar restore process?
  4. If, I've done dd if=/dev/hda1 to backup /root, and I need to restore that to another disk, do I need to make the partition the exact same size or can I make it larger?
Stin.

1. How to take a record of the partition table (what command to show it)

I did an fdisk -l and got this:

[root@Armada ssh]# fdisk -l

Disk /dev/hda: 255 heads, 63 sectors, 4864 cylinders
Units = cylinders of 16065 * 512 bytes

Device______Boot___Start_______End_____Blocks________Id__System
/dev/hda1___*______1___________6______48163+______83__Linux
/dev/hda2__________7___________3444___27615735____83__Linux
/dev/hda3__________3445________4701___10096852+___83__Linux
/dev/hda4__________4702________4864___1309297+____f___Win95 Ext'd (LBA)
/dev/hda5__________4702________4750___393561______83__Linux
/dev/hda6__________4751________4831___650601______82__Linux swap
/dev/hda7__________4832________4864___265041______83__Linux

[root@Armada ssh]#

What does this tell me?
It looks like this laptop had windows 95 on at some point. It looks like its overlapping with /dev/hda5,6,7.
If I remove the /dev/hda4 (win95) partition, it removes /dev/hda5 hda6 and hda7.

to get around this can I use dd to backup each of these partitions 5 6 7 and then re-write the partion table to get rid of the win 95 partition, then restore them?


***EDIT*** Do I need to bother with hda6 if it is swap?


LOL! DON'T TRY THIS AT WORK KIDS!!!!

I backed up those 2 partitions OK (5 & 7) deleted 4 (which also took out 5, 6 & 7 due to the overlap, then I created a new 4th partition the same size a what 5 was, but it wouldnt let me create any more. It said i must free up more space but when I did a verify, itsaid I had plenty left.
So I thought I would reboot. Which coincidently meant I tried to boot with no swap.
It did not like it. I'm now restoring the whole thing from a backup and i'll hopefully be back to square 1.

Last edited by Stin; 05-29-2008 at 09:41 AM. Reason: changes white space
 
Old 05-29-2008, 10:16 AM   #6
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
Are you sure you made the 4th partition extended? There's still the limit on these things that you can have only four primary partitions, or if you want more, you must make one primary partition into an extended one and create the rest of the partitions inside of that extended one..

I would still not try to do the backups based on that exact partition information; rather I would just use some utility (be it dump, tar, cpio or something else) to back up the actual data and label the backups so that in the future you would be free to make new partition layouts and just put the actual data where it is needed.

Linux should be able to work without swap partition too, but only if you take that into account right from the start (i.e. don't try to do swapon if there is no swap partition), or if you use a file instead of a swap partition. Not that it's always a good idea, but it should be possible.

The bottom line is, I guess, that whenever you take backups, try to take only the parts you actually need (i.e. if you have installation discs for software anyway, don't take backups of that software then) and try to make the backups so that they are independent of the underlying system's details like partitions. It eases up putting them back if the new environment isn't exactly like the old one.

Good luck with your..."experiments" having a virtual machine for "trying things out" wouldn't be a bad thing, you know?
 
Old 05-30-2008, 04:09 AM   #7
Stin
LQ Newbie
 
Registered: Feb 2008
Distribution: Redhat 7.3 Valhalla, Solaris 8, HP Tru64
Posts: 25

Original Poster
Rep: Reputation: 15
Hi there, and thanks for the help.
I think that was my problem.

So looking at that partition table Win95 is the extended partition, and the others are within it, so this is OK?

I didnt have much luck with dump, though I have used tar OK. I think I only really need to use dump, on /root and /usr. The rest I will use tar.

I'm not smart enough to use virtual machines. I might try it though. Other people get on really well with them.
Thanks agian for the help.

The more I learn the less I seem to know. If you know what I mean?
 
Old 05-30-2008, 04:44 AM   #8
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
Be sure to read the info manual on the tar command. There is a section on incremental backups using a timestamp option.

You also didn't say what the filesystems are that you are using. Some filesystem such as xfs have there own dump programs that can perform incremental dumps. I think that xfs-dump can be used on a live system as well.

If you backup an image, perform a dump, or a tar backup, you should identify the date & source in the filename, or include that info in a containing folder. If several backed up images are named usr.img that wouldn't be much help. If the filesystem where the backups are stored allows it, you can store name=value attributes which you could use to save information about the backup as well. This is what beagle does when it indexes a file:
Code:
getfattr -d *
# file: apps
user.Beagle.AttrTime="20080530091642"
user.Beagle.Fingerprint="02 x65U3PZEo0OohQvwE3O9rg"
user.Beagle.MTime="20060905085207"
user.Beagle.Uid="2MafUkNup0+mwBaGVbikMA"
If you do create an image of a partition, you can pipe the output through gzip or bzip2. To restore, simply read the file with zcat or bzcat and pipe the output into the input of the dd command. The dd command without options simply takes the input from stdio and outputs in to stdout unless you use the if= or of= options.

You could also use dd to create a backup of the MBR. I would recommend saving a printout of "sudo /sbin/fdisk -l" as well.

If you use dd to backup an image, make sure that the system isn't live.

When restoring incrementally, you need to be aware of a potential problem. What about the case where a file was deleted between backups. An incremental restore may leave this file in place when you want it should be deleted. This may depend on your tar version and the options used. Reading either the star or dar documentation in the past, it was claimed that restoring from tar incremental backups wouldn't delete files. However the tar info file I have indicates otherwise:
Code:
   When extracting from the incremental backup GNU `tar' attempts to
restore the exact state the file system had when the archive was
created.  In particular, it will _delete_ those files in the file
system that did not exist in their directories when the archive was
created.  If you have created several levels of incremental files, then
in order to restore the exact contents the file system  had when the
last level was created, you will need to restore from all backups in
turn.
This deletion may require the --listed-incremental option when creating the backup.

One last thing that I must mention is to check whether your version of tar, or whatever backup solution you use also backs up security attributes, file attributes and file acls. You may need to use star instead, but I think the recent tar command incorporated these improvement.

Last edited by jschiwal; 05-30-2008 at 04:51 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Backup and restore linux depam Linux - Software 22 12-30-2006 07:55 PM
XP Backup/Restore from Linux failed - Help please!!! clint_in_sydney Linux - Hardware 6 08-10-2006 09:08 AM
How to backup & restore the MBR in linux? sgzlit Linux - Newbie 7 03-02-2005 09:07 PM
Need to backup then restore a linux partition stuart Linux - General 5 07-16-2004 07:30 AM
How to backup and restore a working Linux System redwolf Linux - General 3 07-27-2003 08:01 PM


All times are GMT -5. The time now is 06:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration