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

File::Copy - locked files

by packetstormer (Monk)
on Feb 11, 2013 at 15:58 UTC ( #1018170=perlquestion: print w/ replies, xml ) Need Help??
packetstormer has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

Would anyone know how, or if, File::Copy deals with open/in use files - specifically on a Windows OS? I am creating an app to backup files/folders but I am concerned about files that are locked or in use.

Has anyone any suggestions?

Comment on File::Copy - locked files
Re: File::Copy - locked files
by kennethk (Monsignor) on Feb 11, 2013 at 16:32 UTC

    Have you tried copying locked/in use files? Fortune favors the bold.

    C:\>perl -MFile::Copy -e "copy 'file1.txt', 'file2.txt'" C:\>

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Re: File::Copy - locked files
by ww (Bishop) on Feb 11, 2013 at 17:11 UTC
    Not a good idea!

    Wait for the lock to be released. Otherwise you may be putting an incomplete or outdated file into your backup collection. As with all backups, shortcomings don't usually get to be a big problem... until you actually need the backup, by which time, it's too late to fix the problem.


    If you didn't program it by toggling in binary, it wasn't programming!

      Agreed!

      What about files that are in use though, continually (or close to). Is there any accepted method for dealing with this type of thing? Suppose it's a small Access database with a lock on it (in use by a Windows service that is always running!). Is there any shadowing copying libraries for Perl!?

        Recent Windows versions have a special service (Volume Shadow Service? Use Google!) for this problems, it allows you to take some kind of snapshot of the filesystem. All modifications after the snapshot do not affect your program, so you can safely copy files from a mounted filesystem. Of course, this service can't guarantee that all open files are in a consistent state.

        Regarding your locked Access database: Shut down the service, then backup or make at least a copy of the database file, then restart the service and exclude the original, locked file.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2014-07-28 12:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (196 votes), past polls