l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2004 Mar 21 16:51

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
[vox-tech] Script to push changes to a directory tree...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vox-tech] Script to push changes to a directory tree...

  After the last lugod meeting, Tim asked about a way to "sync" a target 
directory with some source directory.  While most everyone suggested
rsync was the way to go, Tim didn't like rsync because it would take
"too long".  In Tim's case the primary way he modifies the source data set 
is to rename files or directories.  Rsync would consider those renames 
that to be a delete old and add new, instead of a "rename".


  Anyway, if I remember the problem description correctly Tim was certain 
that files would only be changing on the source drive, if they changed 
four things could happen:

- A file could Move from one location to another.
- A dir could Change names.
- A file/dir could be Added.
- A file/dir could be Removed.

Files would Never be Changed.


So anyway... I thought this was interesting enough


msimons@salomon:~/perl$ ./push_tree -vn ./source ./dest/
make directory ./dest/dir1/
make directory ./dest/dir2/
move file ./dest/file1 to ./dest/dir2/file1
copy file ./source/dir2/file to ./dest/dir2/file
move file ./dest/old.dir1/old.zap to ./dest/dir1/zap
move file ./dest/old.dir1/zip to ./dest/dir1/zip
nuke file ./dest/nuke1
nuke directory ./dest/ndir1/
nuke directory ./dest/old.dir1/

The script supports two options:
  -n : don't really change anything
  -v : print out what you plan to do

The script requires two arguments:
  <source_dir> <target_dir>

The script does three things badly:
  - target directory missing.
  - uses "cp -p" instead of opening file inside perl
  - renamed directories result in 
    a mkdir, rename of each file, rmdir; instead of one rename.

The way it operates is to index source and target directories building 
a hash for each dir of file = timestamp/size, dir = timestamp.

Then loops over the two has a few times... applying changes in the
order they make sense.
vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.