LinuxQuestions.org
Help answer threads with 0 replies.
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 07-07-2008, 12:56 AM   #1
pnmanojshenoy
Member
 
Registered: Jun 2008
Location: Cochin, India
Distribution: Debian,Ubuntu
Posts: 38

Rep: Reputation: 0
Backup using dd command


Hi...


Can any one tell me how to backup a partition using dd command and also how to split the file ....
 
Old 07-07-2008, 01:41 AM   #2
BugZRevengE
Member
 
Registered: Oct 2005
Location: Australia
Distribution: Slackware & Kubuntu & CentOS
Posts: 106

Rep: Reputation: 17
I would look at:
http://www.partimage.org/Main_Page

It does what you would want, and I believe it uses dd (but am not really sure).

It does compression, splitting of the image and other useful stuff...

Hope it helps..
 
Old 07-07-2008, 02:13 AM   #3
Vit77
Member
 
Registered: Jun 2008
Location: Toronto, Canada
Distribution: SuSE, RHEL, Mageia
Posts: 132

Rep: Reputation: 17
dd if=<input_file> of=<output_file>
For example,
dd if=/dev/hda1 of=/home/user/file

It could be useful to get compressed image:
dd if=/dev/hda1 | bzip2 > /home/user/file.bz2

To split some file using dd you can:
dd if=SrcFile of=Dst1File count=10 (Take 10Kb for the 1st file)
dd if=SrcFile of=Dst2File skip 10 count=20 (Take 10-30Kb for the 2nd file)
etc

However, if your source file is an image of some partition (as in the 1st example), it'd be better just to mount it using -o loop option.
 
Old 07-07-2008, 03:03 AM   #4
pnmanojshenoy
Member
 
Registered: Jun 2008
Location: Cochin, India
Distribution: Debian,Ubuntu
Posts: 38

Original Poster
Rep: Reputation: 0
Thanks for th help...
 
Old 07-07-2008, 03:04 AM   #5
Bruce Hill
HCL Maintainer
 
Registered: Jun 2003
Location: McCalla, AL
Distribution: Funtoo
Posts: 6,926

Rep: Reputation: 128Reputation: 128
We use rsync (man rsync) for backups. If you just need an image
of a partition, dd is good. But for incremental backups, rsync might
be a better tool. You didn't state your purpose.

How To Do Eveything With DD from Linux Tutorials here at LQ is good.
 
Old 07-07-2008, 10:18 AM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
IMHO, file backups are better. I can see doing it initially after installation so that you can recover quickly due to a drive crash.

You simply need to pipe the output of dd through gzip or bzip2 and then pipe that through split to produce slices of the compressed image. To restore, cat together the parts; pipe through gunzip or bunzip2 and pipe the output to the input of dd.

One problem with this approach is if you burn the slices on a CD or DVD. You will need to manually cat each file to the end (>>) and make sure you don't get any of the discs out of order. If you are backing up to an external drive or a network drive, this wouldn't be a problem.

The compression phase may not be worth it if you don't first zero out unused disk space.
E.G.
freeBlocks=$(df /boot | awk '{print $4}')
dd if=/dev/zero of=/boot/zerofile bs=1024 count=$$(freeBlocks-1))
rm /boot/zerofilee

This can make a dramatic change in filesize for a near empty partition that contains deleted files.

One other thing. If the image is for an entire disk, then use "fdisk -l <image-file>" to determine the starting point in (512 byte) blocks. Next use losetup an offset to the start of the partition you want to mount.
 
Old 07-07-2008, 10:26 AM   #7
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 115Reputation: 115
trying to split a partition using dd isn't all that easy. Easier just to pipe the output of dd to the split command.

Here is how I do it:

dd conv=noerror,sync if=/dev/hda | split -b 100000000 - /destpath/filename.img

This will image the entire contents of hda to a destination path with filenames filename.img.aa, filename.img.ab, etc and each file will be exactly one hundred million bytes long.

I usually use this command sequence when I am recovering a hard drive.
 
Old 07-09-2008, 10:27 AM   #8
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE 42.1_64+Tumbleweed-KDE, Mint 17.3
Posts: 3,950

Rep: Reputation: Disabled
Quote:
Originally Posted by jschiwal View Post
...The compression phase may not be worth it if you don't first zero out unused disk space.
E.G.
freeBlocks=$(df /boot | awk '{print $4}')
dd if=/dev/zero of=/boot/zerofile bs=1024 count=$$(freeBlocks-1))
rm /boot/zerofilee

This can make a dramatic change in filesize for a near empty partition that contains deleted files....
Just a little hint or addition: Some file systems reserve space for root in the case that the file system / partition is filled to capacity (around 5 % of the total, can be adjusted) and needs space for maintenance. So your suggestion should be carried out by root, as I understand the situation.

Last edited by JZL240I-U; 07-09-2008 at 10:53 AM.
 
Old 07-09-2008, 10:40 AM   #9
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 234Reputation: 234Reputation: 234
Let me emphasize that dd is not a good way to perform backups. It's great for creating images to transfer, move around to another location/server, etc. But if you want backups to recovery from a disaster, look into the many alternatives out there that specialize in actual backups. dd is more of an imaging tool, not backup tool.
 
Old 07-09-2008, 11:04 AM   #10
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE 42.1_64+Tumbleweed-KDE, Mint 17.3
Posts: 3,950

Rep: Reputation: Disabled
Seconded. Just for the record I use rsnapshot reniced and triggered by fcron for backups.
 
  


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 Command in HP-UX sunram Other *NIX 5 05-05-2008 01:54 PM
Backup and Restore Command jimmete Amigo 4 06-07-2006 09:02 PM
dd backup and restore command jimmete Red Hat 4 06-07-2006 04:13 AM
Will this command backup my box? BBlalock Linux - Newbie 2 05-02-2004 01:14 PM
backup command ust Linux - General 1 03-16-2004 01:34 PM


All times are GMT -5. The time now is 10:37 PM.

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