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

I need to copy an Access 2000 database from a Windows NT web server to an InfoServer just once a day.
I assume I can do this by copying the Access 2000 database to the InfoServer using a Perl Script running on the Windows Task Scheduler.
If the copy is the way to go, our web server does not have File::Copy module so I am trying to use the below script to do the job. Please advise if I have this correct and this can be done with an Access 2000 database?
use strict; my $filename = "myDatabaseName.mdb"; open(FILEOPENED, $filename) || die "Can't open file: $filename \n"; while ($line = <FILEOPENED>) { print "$line \n"; my $cmd = "copy H:currdir\\$line \\\infoserver\\destinationDir"; + print "$cmd\n"; my $result = system($cmd); if ($result) { warn qq(Couldn't execute "$cmd"!\n); next; } } close(FILEOPENED);

Replies are listed 'Best First'.
Re: Copy Database to another location
by Errto (Vicar) on Feb 06, 2006 at 20:34 UTC

    This is pretty close, but there are a couple of changes you'll probably need to make. First, be sure to chomp $line after reading it in. Otherwise it will generally have a newline at the end of it and this will mess up your copy command. Second, UNC paths start with a double backslash (\\), which means that if you want to write one in a double-quoted string in Perl you need to write it with four backslashes (\\\\); your code only has three. Finally, IIRC copy.exe does not support UNC paths on some older versions of Windows. Unfortunately I don't have anything older than XP in front of me to test with. If you run into this problem then you'll need to map the path to 'infoserver' as a network drive.

    By the way, File::Copy is now a core module, so if your Perl is recent enough you have it already.

Re: Copy Database to another location
by neilwatson (Priest) on Feb 06, 2006 at 20:34 UTC
    This does not seem like a good idea to me. What will happen to the database if a record is altered while the copy is in progress? The copy will not be exact. Why are you copying the db? If it is for backup, then I would check the Access help files for proper backup options.

    Neil Watson
    watson-wilson.ca

Re: Copy Database to another location
by InfiniteSilence (Curate) on Feb 06, 2006 at 21:38 UTC
    Some points:
  • I like neilwatson's comments. They make sense. Make sure you are doing this when no one should be using the database.
  • Microsoft Access keeps rollback data in hidden tables within itself and its cleanup utilities for this have been historically bad. That means you will have to run a macro within it to force it compress itself, like:
    #!/usr/bin/perl -w use strict; use Win32::OLE; my ($acc) = Win32::OLE->new("Access.Application"); $acc->{Visible} = 1; $acc->OpenCurrentDatabase("c:\\temp\\foo2.mdb"); $acc->DoCmd->RunMacro("mcroSayHello"); 1;

    Read the docs on how to create a macro or just use this code: 495924.

  • Lastly, I would probably check the file size on the target to ensure you actually moved everything over. You can use WMI or something for that.
  • Celebrate Intellectual Diversity

      Thanks for all your recommendations!
      I think I will just use the Document file that is output from the Cold Fusion Front end which will give me the records I need. Then use this Script to transfer the Document file to the infoserver. This works but was wondering how I can check if the copy was successful?
      use strict; my $listFile = "C:\\theDoc.doc"; my $listFile2 = "\\\\theinfoServer\\dir\\"; open(LIST, $listFile) || die "Cant open $listFile : $!"; while(<LIST>) { #Can I put a Exception statement for this system command? I am not +familiar with Exceptions in Perl system("copy $listFile $listFile2 > nul"); } close(LIST); print "Successfully copied\n";