LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-17-2014, 10:10 AM   #1
Torben Friis
Member
 
Registered: Oct 2008
Posts: 71

Rep: Reputation: 15
backup with dd


Hi,
I have tried to search on dd and found nothing.
I want to occasionally backup my entire disk (clone, disk image or iso image). The disk contains Windows and linux with several sda's.
What is the dd commands for backing up and restoring?
I assume that to back on a new replacement disk I have to use a live version of Linux.
Can anyone help?
best regards
torben
 
Old 08-17-2014, 11:09 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
this mite help:
http://www.linuxquestions.org/questi...6/#post5146111

be triply sure that your source and destination are correct or you will erase your data beyond recovery. dd is very unforgiving and assumes you are an expert.

Last edited by schneidz; 08-17-2014 at 11:12 AM.
 
Old 08-17-2014, 12:30 PM   #3
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
You can certainly backup with dd, but it is very low level. i.e., if you have a one terrabyte disk and you're only using 4Gb of it, your backup will still be one terrabyte in size. If you really really want an entire disk image, dd can do that. Just make sure you really want this.

The most common reason you would restore from a backup is from a human error - you accidently deleted a file that you didn't mean to, and you just want to restore that one file. A disk image is not a good way to handle this. A disk image is good when your original disk goes up in flames and you are replacing the entire disk. Even then, you don't really need an image of the entire original disk, you (usually) only need a copy of the parts of the disk that were actually in use. Plus, disk images are quite slow to create. Say you just did an image backup last week, and now this week you want to do another backup. But you've only changed a handful of files on your computer. A disk image has no concept of that, and will backup the entire kit-and-kaboodle all over again.

You might want to Google "Linux backup solutions" before diving in with dd, just so you understand all the options and pluses/minuses of each method.
 
1 members found this post helpful.
Old 08-18-2014, 02:56 PM   #4
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,974

Rep: Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623
One can use dd with some compression and tricks to make copies. As above, you would be better off usually with a file based solution. I only use dd for an unusual OS that can't easily be copied.
 
Old 08-18-2014, 03:28 PM   #5
SW64
Member
 
Registered: May 2014
Distribution: Slackware
Posts: 262

Rep: Reputation: 123Reputation: 123
Quote:
Originally Posted by Torben Friis View Post
What is the dd commands for backing up and restoring?
I assume that to back on a new replacement disk I have to use a live version of Linux.
Yes, it is best to boot off a live CD/DVD if you wish to make a bit-for-bit copy of the drive that has the operating system installed. But booting off the live CD/DVD is not necessary if you are just imaging a CD or an USB drive to your computer, for example.

Assuming that 'sdb' is a blank equivalent-size or bigger drive than 'sda', the 'dd' command for backing up a drive to another drive is:
Code:
dd if=/dev/sda of=/dev/sdb conv=notrunc,noerror
That will make an exact copy of the first drive onto the second drive: the Windows partitions, the Linux partitions, everything on that first drive.

To restore, just switch around the drives:
Code:
dd if=/dev/sdb of=/dev/sda conv=notrunc,noerror
What you are probably looking to do is something like this:
(This example assumed you are running off a live disc and have an external hard drive mounted.)
Code:
dd if=/dev/sda of=/external/drive/name_of_image.img conv=notrunc,noerror
That will save the drive's image as a file to the external drive.

The restore command would be like this:
Code:
dd if=/external/drive/name_of_image.img of=/dev/sda conv=notrunc,noerror
You can even mount the image file you made with the 'dd' command so you can go in and copy over the needed files:
Code:
mount -o loop /external/drive/name_of_image.img /mnt/something
cd /mnt/something
cp I_need_this.jpg I_need_that.doc /to/somewhere/else
Of course, do not blindly enter the examples into your console or data loss will most likely result. Look up and adjust your command's 'if=' and 'of=' locations accordingly.

I got my start with the 'dd' command from this excellent post:

http://www.linuxquestions.org/questi...ommand-362506/

There are tons of useful examples in that post. Be sure to read up on using the 'bs=' option in your command to make the transfer go a little faster. Setting this differ from one computer to another so I intentionally left this option out in the examples. The examples will still work -- just painfully slow if the source is a very large file/drive. Do read up on why 'conv=notrunc,noerror' is necessary, too.

Entering 'man dd' in your console will give you on-hand information about the 'dd' command and all of its options. That is, assuming your man pages have been installed. If man pages are not available, googling 'man dd' also worked, too.

My advice?

Practice, practice, practice. Especially the restoration part. Use an usb drive or even a floppy drive if you still have one somewhere. The smaller the drive is, the sooner you can find out if you were successful or not (dd has no progress bar). Practice on a computer where you can afford to reinstall the operating system back on from an OS installation disk. Don't have a spare computer to practice on? Install VirtualBox (http://www.virtualbox.org/) or another similar visualization program and practice from within.

Do not practice on your everyday computer with all your documents, pictures, or whatever important irreplaceable data it might have. There is far too much risks of data loss when practicing the 'dd' command.

Once you're comfortable with using the 'dd' command and once you have ensured that you have at least one alternative backup copy of your important data, you can then use the 'dd' command to back up and restore your important data with. Even if you've gotten comfortable with using dd, it is highly recommended to practice or test a new 'dd' command setup before you put it into real world uses. Do confirm that you can restore back or access the image file after a successful backup with the 'dd' command.

'dd' should never be used casually. Double-check and triple-check your 'dd' commands before hitting that 'Enter' button. 'dd' is cold and merciless when mistakes are made on important data.

For the purpose of backing up my important data on a regular basis, I have moved on from 'dd' to 'rysnc' and sometime even just plain old 'cp'. On the Windows machines, I uses the 'robocopy' command. While the 'dd' command is very good and important tool to know, Haertig's post included many of the reasons for my switching over. Mainly, it is just easier, better use of backup storage space, eat up less time, and more reliable in the long run.

Good luck!

Last edited by SW64; 08-19-2014 at 12:19 PM.
 
  


Reply



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
Today is World Backup Day – a friendly reminder to backup and check restores jeremy Linux - News 0 03-31-2014 11:42 AM
[SOLVED] Backup, shrink backup and modify MBR of backup jps1x2 Linux - General 1 12-17-2013 05:03 AM
Newbie trying to write a simple backup script to backup a single folder Nd for school stryker759a Linux - Newbie 2 09-16-2009 08:52 AM
LXer: Automatic backup for sporadically connected clients with Box Backup LXer Syndicated Linux News 0 08-29-2008 08:40 PM
Backup system ala rdiff-backup, but without mirror and with dst encryption dr_dex Linux - Software 0 08-04-2008 03:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:45 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
Open Source Consulting | Domain Registration