473,569 Members | 3,040 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(SO URCE_DIR, DEST_DIR):
global STATUS
try:
os.chdir(SOURCE _DIR)
for x in os.listdir(SOUR CE_DIR):
int_time = os.stat(x)[stat.ST_CTIME]
str_time = time.ctime(int_ time)
if datetime.date.f romtimestamp(in t_time + 0.00) >
YESTERDAY:
try:
DEST_FILE = os.path.join(DE ST_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 4463
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(SO URCE_DIR, DEST_DIR):
global STATUS
try:
os.chdir(SOURCE _DIR)
for x in os.listdir(SOUR CE_DIR):
int_time = os.stat(x)[stat.ST_CTIME]
str_time = time.ctime(int_ time)
if datetime.date.f romtimestamp(in t_time + 0.00) >
YESTERDAY:
try:
DEST_FILE = os.path.join(DE ST_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(SO URCE_DIR, DEST_DIR):
global STATUS
try:
os.chdir(SOURCE _DIR)
for x in os.listdir(SOUR CE_DIR):
int_time = os.stat(x)[stat.ST_CTIME]
str_time = time.ctime(int_ time)
if datetime.date.f romtimestamp(in t_time + 0.00) >
YESTERDAY:
try:
DEST_FILE = os.path.join(DE ST_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************ **********@19g2 000hsx.googlegr oups.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
7744
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 ---------------------------------------------------------------------------- ----------------- import re, os, time, shutil os.chdir(os.environ+os.environ+"\\Desktop") DESKTOP =...
1
2983
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 subdirectory with a new name. I am using python 2.4 with wxpython 2.6 on a windowsxp machine. I encounter a permission denied error when trying to...
2
2097
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 shutil.copy2 it copies the dates of the original files, but creates folders with similary old dates and times. Anybody ever seen that before? My...
6
14543
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 seems that this is the case for all my files. But what I don't understand is that yesterday it still worked. I didn't change anything on my system...
5
18908
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 have focused on looking at the source for copytree, but it has several places where exceptions can be raised, and the documentation for the shutil...
10
3315
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 '<<' and '>>' operators to stream out and stream in data, respectively. So far this is what I have: class filestream:
10
3197
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
3263
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 creating each file, it moves the file to folder B, using shutil.move(). Thread T2, takes files from folder B and processes it. Note: Only the...
4
2598
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 have to specify the sourcefile and the destinationfile in codes and not left to be specified from the terminal. i want to be able to do this. ...
0
7619
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6290
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5228
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.