Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Directory replication

by crabbdean (Pilgrim)
on Mar 03, 2004 at 15:58 UTC ( [id://333558]=perlquestion: print w/replies, xml ) Need Help??

crabbdean has asked for the wisdom of the Perl Monks concerning the following question:

Hiya Monks, I want to replicate one directory (and sub-dirs) to another, and only copy files that have changed. Surely someone must have come up with a solution for this already. I've looked around but haven't found anything - or am I just being blind?! And possibly stupid? Oh holy monks, point me in the right direction. (bowing) Thanks

Dean

PS. All else failing I'll write my own, just don't want to go re-inventing the wheel.

Programming these days takes more than a lone avenger with a compiler. - sam

Replies are listed 'Best First'.
Re: Directory replication
by b10m (Vicar) on Mar 03, 2004 at 16:04 UTC

    Your best bet would be rsync, IMHO

    --
    b10m

    All code is usually tested, but rarely trusted.
Re: Directory replication
by matija (Priest) on Mar 03, 2004 at 16:09 UTC
    The most efficient way of doing this I've found so far, has been rsync - it does several clever things, and is very, very usefull for remote sync/backup.

    The Perl interface to rsync is here.

Re: Directory replication
by Tomte (Priest) on Mar 03, 2004 at 16:03 UTC

    not perl, but assuming your on un*x (edit:and replication is not remote):

    cp -au olddir/ newdir/
    should do the trick (with GNU cp that is, don't no nothing else... ;-)

    regards,
    tomte


    Hlade's Law:

    If you have a difficult task, give it to a lazy person --
    they will find an easier way to do it.

Re: Directory replication
by jbware (Chaplain) on Mar 03, 2004 at 17:25 UTC
    Another windows solution is robocopy; I prefer it over xcopy for robustness and functionality. For syncing, you'll want to look at the /MIR switch that will also removes files as appropriate so both dirs actually are the same.

    -jbWare
      That's a great little solution. I'll keep that in mind (in fact I have two other problems I can apply it to) but unfortunately one of the problems requires install on a Win95 machine for which Robocopy isn't compatible.

      Dean

      Programming these days takes more than a lone avenger with a compiler. - sam
Re: Directory replication
by BrowserUk (Patriarch) on Mar 03, 2004 at 16:59 UTC

    If your on windows

    system( 'xcopy /s /y /d /u srcdir destdir' );

    You might not want the /u and you might want /e instead of /s. Help xcopy for more.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
Re: Directory replication
by Crian (Curate) on Mar 03, 2004 at 16:54 UTC
    If you could live with a non-Perl-solution && you are using one of these in this abbey not very high ranked operating systems made in Redmond, you could use the synchronisation ability of the tool "Total Commander" http://www.ghisler.com (not included in those os'es - of course).

    I use it to keep copys of working directorys on my usb stick up to date (and to ftp changed files to my web site).
Re: Directory replication
by waswas-fng (Curate) on Mar 03, 2004 at 17:11 UTC
    Also you can use RSync -- it is made to do just this (locally or remotely).


    -Waswas

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://333558]
Approved by halley
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 23:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found