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

I'm trying to create a script to automatically make copies to my backup disk.

The thing is that I want the script to check if the file is already in the backup disk in order to only copy files that are missing.

What I have done already:
I have no idea of what commands to use for this (or where to look for them). Somebody suggested glob and s/modules/facilities.
I have found glob but not the other one (I've searched CPAN but I'm not entirely sure I did it the right way). I also googled it but came up with nothing, then again I have such a faint idea of what to look for that it is possible i didn't look for the right terms.

Any help would be really appreciated.

  • Comment on How I move files and check if they exit in another directory?

Replies are listed 'Best First'.
Re: How I move files and check if they exit in another directory?
by shmem (Chancellor) on Jun 06, 2007 at 15:33 UTC
    Things handy are e.g. the filetest builtin operators, File::Copy, File::Find.

    But why reinvent that particular wheel? Have a look at rsync, available from the rsync web pages, which cares about existing files, timestamps, recursion and so on.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: How I move files and check if they exit in another directory?
by tirwhan (Abbot) on Jun 06, 2007 at 15:34 UTC
    The thing is that I want the script to check if the file is already in the backup disk in order to only copy files that are missing.

    Don't you also want to copy files that exist on the backup disk but have changed since the last time they were backed up? Backup is an often underestimated topic in terms of complexity, and while I wouldn't want to discourage you from writing a program for the learning experience alone, I am fairly sure that what you will produce is not as suitable for the task as existing tools out there. If you want to use Perl for this, I'd suggest searching for "backup" on CPAN and taking a look at the modules shown. Otherwise, check out unison which is a fairly light-weight yet complete way of doing what you're trying to do.


    All dogma is stupid.