Is it possible, to only rsync the filenames? I have a storage box and want the filenames (and their paths) added to another box. I'm currently creating each file with touch (they'll be created with a 0 byte size). It takes too long and was wondering if this could be automated with rsync.

If not, is there any other tool which allows this? Or would I need to code something custom?

  • Something like this? find . -type d > direcotries find . -type f > files and on remote cat direcotries | xargs -I this mkdir this cat files | xargs -I this touch this – week Nov 12 '12 at 16:02
  • Why create empty files? What's the point of having so many empty files? – unforgettableid Nov 15 '12 at 18:15
  • @unforgettableid The empty files are simple .iso files, which are needed for the SolusVM control panel on the master. However I want one central repo for the ISO's, which will then be rsynced to all the noded while the master only has empty files (needed for control panel to function). – Devator Nov 15 '12 at 18:57
  • 1
    @Devator: OK, so you say the actual ISOs are stored in a directory on an ISO-storage PC. Well, perhaps you could use file-sharing software to mount that directory on the master PC. Would that eliminate your need to periodically sync the filenames? If not, why not? – unforgettableid Nov 29 '12 at 1:55
  • 1
    @unforgettableid It actually might yes, I'll look into that. Thanks! :) – Devator Dec 4 '12 at 9:37

If your aim is to create empy files, than a template may be created like so:

FILES=$1 # original structure
TMPL=$2  # where to create empty files
[[ -d $FILES ]] || exit 1
[[ -d $TMPL ]] || mkdir -p $TMPL || exit 1

cd $TMPL
find "$FILES" -type d -printf "$TMPL%p\0" | sort -z |xargs -0 -L 1000 mkdir -p
find "$FILES" -type f -printf "$TMPL%p\0" | xargs -0 -L 1000 touch

This creates the directory of every file from the original tree and touches the files in the folders created under TMPL.

After creating a "mirrored" folder with only empty files, it can be rsynced to any host like any other folder:

rsync -av -e 'ssh -p 22 -l username' \
    /template/structure remotehost:/backup/templates/

The -e option is optional if the username is the same on both hosts and if sshd runs on the default port. Pay attention to what happens when you specify a trailing slash on both or either of the from and to parts. It is significant. The remotehost parameter, may be an ip address instead of an alias.

  • @Devator have a look at my revised answer – Ярослав Рахматуллин Nov 17 '12 at 2:16
  • Thanks, going to use this :) Figured it already regarding rsyncing the empty folder. Cheers! – Devator Nov 18 '12 at 17:48
  • If you additionally want to include symlinks add the following line to the end of the script find "$FILES" -type l -printf "ln -s %l $TMPL%p\0" | xargs -0 -L 1000 sh -c – Florian Feldhaus Jun 21 '13 at 9:38

rsync itself doesn't seem to have an option to only create files. However, you could try various ways rather than using touch manually:

  • rsync the directory tree, then run find on the root of that tree and echo "" > into each file
  • use find to get a list of directory trees, then use mkdir -p on each element of that list (possibly reverse-sorting beforehand to minimise the number of syscalls) and then use touch on a similarly created list of files.

I would, however, go with the first option if the space is available, as it preserves permissions and access rights (given appropriate arguments to rsync).

  • Yes, I'd like to do the first one, but space is the problem. :( – Devator Nov 12 '12 at 16:28
  • Maybe running it only on parts of the directory tree at a time would solve that problem? – Claudius Nov 12 '12 at 17:48
  • No, there's not enough space. – Devator Nov 12 '12 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.