471,353 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,353 software developers and data experts.

shutil.copy2 error

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)
else:
logfile.write(" File exists. Skipping.
\n")
logfile.flush()
except (IOError, os.error), why:
logfile.write("\n\nError copying " + SOURCE_DIR +
x + " to " + DEST_FILE + "\n\n")
logfile.write("\n" + str(why) + "\n")
logfile.flush()
STATUS = "FAILED"
except:
logfile.write("\n\nUnhandled error in CopyNewFiles\n\n")
logfile.write("SOURCE_DIR = " + SOURCE_DIR + "\n")
logfile.write("DEST_DIR = " + DEST_DIR + "\n")
logfile.flush()
STATUS = "FAILED"

Sep 24 '07 #1
3 4289
On Sep 24, 7:34 am, Horse <jbutu...@gmail.comwrote:
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.

Karthik
else:
logfile.write(" File exists. Skipping.
\n")
logfile.flush()
except (IOError, os.error), why:
logfile.write("\n\nError copying " + SOURCE_DIR +
x + " to " + DEST_FILE + "\n\n")
logfile.write("\n" + str(why) + "\n")
logfile.flush()
STATUS = "FAILED"
except:
logfile.write("\n\nUnhandled error in CopyNewFiles\n\n")
logfile.write("SOURCE_DIR = " + SOURCE_DIR + "\n")
logfile.write("DEST_DIR = " + DEST_DIR + "\n")
logfile.flush()
STATUS = "FAILED"

Sep 24 '07 #2
On Sep 24, 6:34 pm, Karthik Gurusamy <kar1...@gmail.comwrote:
On Sep 24, 7:34 am, Horse <jbutu...@gmail.comwrote:
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.

Karthik
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.

Sep 25 '07 #3
In message <11**********************@19g2000hsx.googlegroups. com>, Horse
wrote:
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.
Could it be the connection to the Samba server has gone down temporarily?
Sep 25 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Todd7 | last post: by
2 posts views Thread by BartlebyScrivener | last post: by
6 posts views Thread by Antoine De Groote | last post: by
10 posts views Thread by Robert Dailey | last post: by
10 posts views Thread by yinglcs | last post: by
4 posts views Thread by Roopesh | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.