public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
From: Alex Schuster <wonko@wonkology.org>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] Cloning a directory hierarchy, but not the content
Date: Sun, 30 Jan 2011 00:51:08 +0100	[thread overview]
Message-ID: <4D44A7EC.5020203@wonkology.org> (raw)
In-Reply-To: <201101291917.p0TJHaR8024274@dcnode-02.unlimitedmail.net>

Etaoin Shrdlu writes:

> On Sat, 29 Jan 2011 17:45:30 +0100 Alex Schuster <wonko@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	other threads:[~2011-01-30  0:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-29 13:58 [gentoo-user] Cloning a directory hierarchy, but not the content Alex Schuster
2011-01-29 13:54 ` Etaoin Shrdlu
2011-01-29 14:27   ` Alex Schuster
2011-01-29 14:36     ` Etaoin Shrdlu
2011-01-29 16:45       ` Alex Schuster
2011-01-29 18:59         ` Etaoin Shrdlu
2011-01-29 23:51           ` Alex Schuster [this message]
2011-01-29 14:39 ` Florian Philipp
2011-01-29 19:31   ` Alex Schuster
2011-01-29 21:14     ` Florian Philipp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D44A7EC.5020203@wonkology.org \
    --to=wonko@wonkology.org \
    --cc=gentoo-user@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox