I'm doing some data recovery from a hard disk. The disk has about 300GB of data on it, but I lack another hard drive that has 300GB of free space.
I have three HDs, with 150, 40, and 120 GB free.
For the creation of the first chunk, I was considering doing the following:
sudo dd if=/dev/sdf1 bs=4096 count=150G | gzip > img1.gz
What should I run on the other machines to "pick up where I left off"?
It is my command line:
It will create 2GB files in this fashion:
Restore:
Hope it helps.
You probably want to consider using
tar
, as KPWINC says, but to answer your question directly, you want to usedd
's "skip" option.If your first command, as stated, is:
Then your second would be:
and third:
That said, I'm not sure that the "GB" suffix does what you're intending. I think it just does raw math on the root number it follows, not figure out how to get that many gigabytes from the block size you've given. I would do something like this:
just to be sure of the math.
Oh, and make sure that your device isn't changing underneath you as you copy it. That would be bad.
A simple solution might be to just use "/usr/bin/split". It just breaks files up into pieces. You can use "-" as the input file name to read from standard input. The nice thing about split is that it is simple, it doesn't affect the toolchain in any real way and you can "join" the files by just using "cat" to glob them back together (or pipe them to another app).
tar
I tar might solve your issue. It has the ability to break up files into multiple volumes.
Check out this link:
http://paulbradley.tv/44/
From the page:
A couple of things here. First, the command you listed probably won't work as you're expecting. It looks like you're trying to hit 150GB, but you need to factor in both the block size and the count (count is the number of blocks of block size). So if you want 150GB, you might do
bs=1GB count=150
. You could then pick up where you left off by adding askip=150
to skip 150 blocks (each of 1GB) on your second run. Also, to have gzip send its output to standard out, you need to pass it the-c
option.However, before you do that, a couple of other questions. Are you using dd here because the filesystem is corrupted/damaged/etc and you need a bit-for-bit exact disk image copy of it? Or are you just trying to get the data off? A filesystem-aware tool might be more effective. Particularly if the source filesystem isn't full. Options include tar, or you might want to look into something like Clonezilla, Partclone, Partimage, or for a more Windows-specific option to directly access a Windows filesystem, Linux-NTFS (note the previously mentioned tools can handle Windows filesystems to various degrees, too).
If you are set on operating on the partition with a non-filesystem aware program, then using your dd line (as modified above to be correct) will likely work. It's hard to say how well it will compress, but it should be smaller than the original filesystem. If you have read-write access to the original filesystem, it would be worth filling up the free space with a file written from /dev/zero to zero out the unused space before saving it with dd. This will enhance gzip's ability to compress the free space in the disk image.
To operate on the second chunk, just add a
skip=XXX
bit to your second dd invocation, where 'XXX' is equal to thecount=
value you gave it the first time. If you wanted to do 150GB on your first one and 40 on your second, you might do:sudo dd if=/dev/sdf1 bs=1GB count=150 | gzip -c > img1.gz
followed by:
sudo dd if=/dev/sdf1 bs=1GB skip=150 count=40 | gzip -c > img2.gz
Comming late for the party, but I had to do such a script to backup an unknown file system on a FAT32 stick.
This simple script works for me:
EDIT: Have uploaded a basic backup restore script that uses dd, pigz or gzip compression and splits files into chunks that can be set at commandline. Script found here: github.com/deajan/linuxscripts