473,508 Members | 2,346 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4459
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
7739
by: bmgz | last post by:
I am have made a simple script that moves all desktop clutter (ie files that are not *.lnk) to a specified folder eg. c:\myhome\mydocs\desktopdebris\2003-12-16 ...
1
2978
by: Todd7 | last post by:
I am writing a python program to load a pdf file into an IEHtmlWindow which displays it through adobe acrobat reader 7. Depending on the buttons the user clicks, the program moves it to another...
2
2093
by: BartlebyScrivener | last post by:
I'm working on various backup scripts, using filecmp and shutil. When I run a script to copy files to a mapped network drive, shutil creates a backup file with a date of 2002 or so. If I use...
6
14536
by: Antoine De Groote | last post by:
Google tells quite some things about it, but none of them are satisfactory. I'm on Windows, and shutil operations (e.g. move, copy) throw Permission denied all the time, for the source files. It...
5
18895
by: Ben Sizer | last post by:
I need to copy directories from one place to another, but it needs to overwrite individual files and directories rather than just exiting if a destination file already exists. Previous suggestions...
10
3307
by: Robert Dailey | last post by:
Hi, I'm trying to create a Python equivalent of the C++ "ifstream" class, with slight behavior changes. Basically, I want to have a "filestream" object that will allow you to overload the...
10
3188
by: yinglcs | last post by:
Hi, Is there a c library which does shutil.copy2() in python? Basically copy a file from 1 directory to another? import shutil import os shutil.copy2(r"C:\test\test",r"C:\test1\test")
4
3257
by: Roopesh | last post by:
Hi, I have a multithreaded application. There are two threads, T1 and T2. Suppose that there are two folders A, B. Thread T1 fetches data from network and creates files in folder A and after...
4
2592
by: klia | last post by:
hello folks i am trying to tweak the current codes so that later when i call it from the terminal i can provide sourcefile and the destination file rather being fixed in the code. because now i...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7382
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7042
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7495
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5052
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1556
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.