jbuturff at gmail.com
Tue Sep 25 02:49:11 CEST 2007
On Sep 24, 6:34 pm, Karthik Gurusamy <kar1... at gmail.com> wrote:
> On Sep 24, 7:34 am, Horse <jbutu... at gmail.com> wrote:
> > I've written a python script that copies a nightly Oracle backup file
> > to another server. Every couple days, the script fails with this
> > error message:
> > Error copying Q:/Oradata/GISPROD/Backups/3UISN35R_1_1 to s:/gisprod/
> > backups/3UISN35R_1_1
> > [Errno 22] Invalid argument
> > Here's the code for the function I'm running. The path names are all
> > correct, and it works *most of the time*. It only fails about once or
> > twice a week. Anyone know where I can get more info on this "errno 22
> > invalid argument"?
> > def CopyNewFiles(SOURCE_DIR, DEST_DIR):
> > global STATUS
> > try:
> > os.chdir(SOURCE_DIR)
> > for x in os.listdir(SOURCE_DIR):
> > int_time = os.stat(x)[stat.ST_CTIME]
> > str_time = time.ctime(int_time)
> > if datetime.date.fromtimestamp(int_time + 0.00) >
> > YESTERDAY:
> > try:
> > DEST_FILE = os.path.join(DEST_DIR, x)
> > logfile.write(" Copying " + SOURCE_DIR + x + "
> > to " + DEST_FILE + "\n")
> > logfile.flush()
> > if not os.path.isfile(DEST_FILE):
> > shutil.copy2(x, DEST_FILE)
> I'm not sure of the error; but one possibility is that the source-
> directory contents may be modified by some other process, while you
> are looping here copying one-by-one the files.
> So a file 'x' could be present at the time you enter loop, but gone by
> the time you try the shutil.copy2. Again this is just a guess...
> Yet another possibility is 'x' is not a regular file (say in unix it
> could be a named pipe).. you can try adding a check for x (like
> os.path.isfile(x)) and copy only regular files.
Thanks for the ideas, I will look into if there is anything else using
these files (maybe a system level backup they hadn't told me
about??). Otherwise, these files are perfectly valid, I can go back
on the ones that error and manually copy them by hand to the
destination folder. I should've mentioned earlier, but this is
running on a windows 2000 system, and the destination folder is a
samba share on a Linux server.
More information about the Python-list