# Backup / Copy hdd

## PietdeBoer

Hey guys,

i've got this fileserver and im workin on some backup issue

the OS hdd is just a single disk, wich i would like to backup to an identical disk without having to buy an expensive raidcontroller.

so i have the OS disk: sda1, 2 and 3 and the backup disk: sdb1, 2 and 3 , both scsi 36GB and on the same controller

my goal is to backup sda 1on1 to sdb.. (i know that can be done with inserting a knoppix cd and dd sda to sdb but i would like the server to backup while its online)

i was thinking about using dd, but i dont know if thats possible while the server is running from the same disk as its making a backup from...

i thought of a raid1 controller.. but i found these to expensive for just a home fileserver

so what would you guys suggest?

thx in advance!

----------

## richard.scott

Hi,

What about doing this to copy your partitions:

```
sfdisk /dev/hda -d | sfdisk /dev/hdb
```

This is assuming your old drive is /dev/hda and your new drive is /dev/hdb. Change as required.

Then emerge partimage and use that to copy the data over?

----------

## merlijn

Why not just use software raid? It won't cost you a penny, and the difference in speed should be minimal.

And with software raid you can make all the data partitions raid1 and the swap raid0 to get some more speed.

----------

## PietdeBoer

how can i boot from software raid1?

----------

## merlijn

 *PietdeBoer wrote:*   

> how can i boot from software raid1?

 

You just create the raid devices (you will need raid1 ext2 for /boot, any other raid can't be used for /boot) and treat them as if they were regular disks. Say you have sda1 as boot, sda2 as swap and sda3 as /, you create the devices nodes /dev/md1 for sda1 and sdb1 for boot, /dev/md2 the same for swap and /dev/md3 for /.

You can now just proceed with a normal installation and use /dev/md1-3 in /etc/fstab and add the kernel parameter root=/dev/md3.

Whenever your machine will bootstrap, it will read the kernel from just one disk (this works because the data is mirrored, so it is exactly the same as if it where not part of any raid array), but whenever you mount /boot/ again from /dev/md1 any changes will be applied to both disks. I also think you will need to setup grub for both your disks (or just the one you will need to boot from).

Hope this answers your question.

----------

## PietdeBoer

ok

so my current setup is sda as boot+os disk and sdb empty

i'll install raid1 on my running configuration

edit grub and fstab

reboot, and stuff should work?

----------

## richard.scott

 *PietdeBoer wrote:*   

> ok
> 
> so my current setup is sda as boot+os disk and sdb empty
> 
> i'll install raid1 on my running configuration
> ...

 

Yikes!!! Nope.....you can't convert a running system from a standard file system to be RAID1 You need to insert the raid layer between the filesystem and disk drive partitions. This requires you to unmount and backup your current filesystem.

Have a look at this Raid Howto on the Wiki

----------

## Akkara

Just a quick reminder that raid1 doesn't completely cover the need for backup.  It only saves you from a  single hard disk failure. There's many other sources of failure that requires a true separated-in-time (and ideally, in space) backup:

- The oops I didn't mean to delete that file(s).  A subset of those is the "omg the most recent emerge update totally messed my system; help!" - nice to have a backup to restore from in case you need to be getting work done and don't have a lot of time to spend messing with emerge.

- The power spike (or fire, flood, etc.) taking out both disks at once.

- Filesystem corruption - could be from a subtle kernel bug (e.g., that rare xfs corruption on some early versions of the 2.6.17's), or from a random bit-flip from marginal or failing ram, alpha-particle hit, etc.

...and so on.

----------

## PietdeBoer

thx for your answer

i know raid1 doesnt cover all the possible failures

but now my fileserver is running on one os disk, wich concers me ofcourse

i want to build in some more security, and with the options i have i thought it would be better to dd or something similiar the hdd to a backup hdd.. so i have  a lot more security then i have now... or am i wrong?

the best idea would be to install a tapestreamer or backup the whole disk over internet.. wich could be a nice option if its possible to backup live disks

i thought of the solution to mount the disks readonly at night once a week and dd the disk over to my backup disk.. how do you guys think about this?

i know the software is gonna complain but my best guess is that the server will keep on running and only spit out some ugly logs when filesystems come backup RW..

----------

## merlijn

The best thing about linux is that basically everything is possible.   :Cool:   The question is what is the best setup for your cause. You mentioned in the first post that this is about a 36gb drive, if you want to very very safe it is rather cheap these days to buy some webhosting with such amounts of space and just use it as remote storage. Which will cover pretty much any disaster apart from a nuclear attack that takes out the entire country.

You should really think about valuable this data is to you, and what the consequences would be if all were lost (which can always happen). As already mentioned raid1 will (in most cases) cover the worry about a drive failure, which is probably the most occurring "disaster". Also any changes on the machine will be backupped immediately, so you eliminate the odds of having to revert to an older version.

If you decide to go with some backup plan that does not involve raid, I wouldn't remount the filesystems. All you really need to backup are the things you would need to restore your system as it were before, meaning only a few dirs would have to be backupped (/home/, /etc/, /root/ (maybe) and /var/lib/portage/world, perhaps /var/log/ or anything you specifically need). None of these should give any problem being copied while the filesystem is mounted read/write. If you want a backup of everything as a starting point, I would suggest booting a livecd and just tarring your whole / up.

Hope this answers your questions.

----------

## PietdeBoer

thx for your answer

correct me if im wrong:

you cant backup a whole disk containing the os and boot sectors while system is running

my best option for a full backup would be to shutdown my server and dd the disk to a backup disk using a livecd and then move that disk to some place safe so also fire will be excluded etc

* i still daily backup my docs/home/etc etc via rsync to an external server (just to cover that nuclear holocaust hehe)

i have 2 identical backup disks so i can keep for example 2 months of backups when a backup is made every month

or i can choose to make a backup before and after a major soft/hardware change 

what do you guys think is the best.. scheduled backups like every month/week or backups when changes are made to the system???

so when the os drive fails, the only things i have to do is replace it with the latest backup disk and move back data via rsync wich i backupped to the external server.

----------

## Cyker

RAID1 is good if you want failure tolerance - If one disk dies the system will continue to work.

It will not protect from data corruption however, and isn't generally considered a 'backup' in the strictest sense.

Using stuff like dd is *highly discouraged* for live filesystems. The resulting image copy will likely be corrupt where changes have occurred during the raw read.

Slightly better is just to do a bulk cp with whatever switches retain permissions, ownership, sticky bits etc., but again if a file is changed during the copy problems can occur.

There is no 100% safe way to snapshot a live drive (Unless Linux has an equivalent to Windows' Shadow copy), but file copy is better than raw image.

----------

## jexxie

LVM2 could do this, but we're getting into the realm of 'too complicated'

----------

