Etaoin Shrdlu writes:

> On Sat, 29 Jan 2011 17:45:30 +0100 Alex Schuster <wo...@wonkology.org>
> wrote:

>>> I should have added that, to do it safely, the target should reside
>>> higher than the source in the hierarchy, or it should be on a different
>>> filesystem and in that case -xdev should be specified to find
>>> (otherwise an recursive loop would result).
>>
>> Right, but not important in my case. I want to mount my backup drive to 
>> /mnt, cd /mnt, and duplicate all stuff soemwhere else, without taking up 
>> much space. Then I can remove the backup drive and I only have to mount
>> it again when I need a file's content, but not for finding out which
>> files there are and how much space they take. Well, the space already is
>> in the file created by du -m, but I'd like to directly navigate around.
> 
> Oh, I see now: you want the files to *look like* the real ones (eg when
> doing ls -l etc.), but be sparse so they don't take up space?

Exactly. Sorry I did not make myself clearer.
It's working now, and I like it :) I added some more features, like
clipping files to a maximum size. So the clone can still be very small
compared to the original, with small files being intact and usable.


> Ok, one way to create a sparse file of, say, 1 megabyte is using dd:
> 
> # dd if=/dev/null of=sparsefile bs=1 seek=1M
> 0+0 records in
> 0+0 records out
> 0 bytes (0 B) copied, 2.5419e-05 s, 0.0 kB/s
> # ls -l sparsefile 
> -rw-r--r-- 1 root root 1048576 Jan 29 11:57 sparsefile
> # du -B1 sparsefile
> 0     sparsefile

That's how I wanted to do it first, too.

> Another way, already suggested, is by using truncate, eg
> 
> # truncate -s 1M sparsefile

I used this, because so I can modify a file that I created empty with cp
--attributes-only. Keeping the attributes would have been a bit complicated.

In case anyone else is interested, the script is here:
http://www.wonkology.org/utils/clone0

wonko@weird ~ $ clone0 -h
clone0 version 2011-01-29
Duplicate a file / directory hierarchy. Files are
created as sparse files, not taking up real space.

Usage: clone0 [-dhSv0] [-s size] src... dst

Options:
  -d      clone directory structure only, not files
  -h      show this help
  -s size copy files up to size as the are, and clip larger files
  -S      do not create sparse files
  -v      show directories being created
  -vv     show files being created
  -vvv    debug output
  -0      clip files larger than size (option -s) to zero size

Arguments:
  src... one or more directories to clone
  dst    destination directory (will be created)


Thanks for the input, guys!

        Wonko

Reply via email to