1 |
Etaoin Shrdlu writes: |
2 |
|
3 |
> On Sat, 29 Jan 2011 17:45:30 +0100 Alex Schuster <wonko@×××××××××.org> |
4 |
> wrote: |
5 |
|
6 |
>>> I should have added that, to do it safely, the target should reside |
7 |
>>> higher than the source in the hierarchy, or it should be on a different |
8 |
>>> filesystem and in that case -xdev should be specified to find |
9 |
>>> (otherwise an recursive loop would result). |
10 |
>> |
11 |
>> Right, but not important in my case. I want to mount my backup drive to |
12 |
>> /mnt, cd /mnt, and duplicate all stuff soemwhere else, without taking up |
13 |
>> much space. Then I can remove the backup drive and I only have to mount |
14 |
>> it again when I need a file's content, but not for finding out which |
15 |
>> files there are and how much space they take. Well, the space already is |
16 |
>> in the file created by du -m, but I'd like to directly navigate around. |
17 |
> |
18 |
> Oh, I see now: you want the files to *look like* the real ones (eg when |
19 |
> doing ls -l etc.), but be sparse so they don't take up space? |
20 |
|
21 |
Exactly. Sorry I did not make myself clearer. |
22 |
It's working now, and I like it :) I added some more features, like |
23 |
clipping files to a maximum size. So the clone can still be very small |
24 |
compared to the original, with small files being intact and usable. |
25 |
|
26 |
|
27 |
> Ok, one way to create a sparse file of, say, 1 megabyte is using dd: |
28 |
> |
29 |
> # dd if=/dev/null of=sparsefile bs=1 seek=1M |
30 |
> 0+0 records in |
31 |
> 0+0 records out |
32 |
> 0 bytes (0 B) copied, 2.5419e-05 s, 0.0 kB/s |
33 |
> # ls -l sparsefile |
34 |
> -rw-r--r-- 1 root root 1048576 Jan 29 11:57 sparsefile |
35 |
> # du -B1 sparsefile |
36 |
> 0 sparsefile |
37 |
|
38 |
That's how I wanted to do it first, too. |
39 |
|
40 |
> Another way, already suggested, is by using truncate, eg |
41 |
> |
42 |
> # truncate -s 1M sparsefile |
43 |
|
44 |
I used this, because so I can modify a file that I created empty with cp |
45 |
--attributes-only. Keeping the attributes would have been a bit complicated. |
46 |
|
47 |
In case anyone else is interested, the script is here: |
48 |
http://www.wonkology.org/utils/clone0 |
49 |
|
50 |
wonko@weird ~ $ clone0 -h |
51 |
clone0 version 2011-01-29 |
52 |
Duplicate a file / directory hierarchy. Files are |
53 |
created as sparse files, not taking up real space. |
54 |
|
55 |
Usage: clone0 [-dhSv0] [-s size] src... dst |
56 |
|
57 |
Options: |
58 |
-d clone directory structure only, not files |
59 |
-h show this help |
60 |
-s size copy files up to size as the are, and clip larger files |
61 |
-S do not create sparse files |
62 |
-v show directories being created |
63 |
-vv show files being created |
64 |
-vvv debug output |
65 |
-0 clip files larger than size (option -s) to zero size |
66 |
|
67 |
Arguments: |
68 |
src... one or more directories to clone |
69 |
dst destination directory (will be created) |
70 |
|
71 |
|
72 |
Thanks for the input, guys! |
73 |
|
74 |
Wonko |