thanks ! the copy function works but i have troubles.. I used a scheduled task to backup the index. for the test , a backup is made all the 15 secondes. and sometime , in the backup process, when i clean a directory with : Directory target=FSDirectory.getDirectory(selected_backup_dir, true); i have a Exception : java.io.IOException: couldn't delete segments at org.apache.lucene.store.FSDirectory.create(FSDirectory.java:166) at org.apache.lucene.store.FSDirectory.<init>(FSDirectory.java:151) at org.apache.lucene.store.FSDirectory.getDirectory(FSDirectory.java:132) at lab.crip5.ECR.cocoon.components.IndexBackupJob.backup(IndexBackupJob.java:13 5)
the exception happend sometimes my backup function is simple : private void backup (String index_to_backup) throws Exception { getLogger().info("begin backup index "+index_to_backup+" at "+new Date()+"..."); // get the directory of the index Directory source=index_manager.getIndex(index_to_backup).getDirectory(); // select target backup directory File target_backup_dir=select_backup(index_to_backup); // clean the old index Directory target=FSDirectory.getDirectory(new_backup_dir, true); // backup copy(source, target); target.close(); getLogger().info("end backup index "+index_to_backup+" at "+new Date()+"...ok"); } ----- Original Message ----- From: "Nicolas Maisonneuve" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, January 15, 2004 3:21 PM Subject: Fw: Betreff: Copy Directory to Directory function ( backup) > > ----- Original Message ----- > From: "Nick Smith" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Thursday, January 15, 2004 2:58 PM > Subject: Betreff: Copy Directory to Directory function ( backup) > > > > Hi Nico, > > This is the method that I use for backing up my indices... > > > > Good Luck! > > > > Nick > > > > /** > > * Copy contents of <code>dir</code>, erasing current contents. > > * > > * This can be used to write a memory-based index to disk. > > * > > * @param dir a <code>Directory</code> value > > * @exception IOException if an error occurs > > */ > > public void copyDir(Directory dir) throws IOException { > > // remove current contents of directory > > create(); > > > > final String[] ar = dir.list(); > > for (int i = 0; i < ar.length; i++) > > { > > // make place on disk > > OutputStream os = createFile(ar[i]); > > // read current file > > InputStream is = dir.openFile(ar[i]); > > > > final int MAX_CHUNK_SIZE = 131072; > > byte[] buf = new byte[MAX_CHUNK_SIZE]; > > int remainder = (int)is.length(); > > while (remainder > 0) { > > int chunklen = (remainder > MAX_CHUNK_SIZE ? MAX_CHUNK_SIZE : > remainde! > > is.readBytes(buf, 0, chunklen); > > os.writeBytes(buf, chunklen); > > remainder -= chunklen; > > } > > > > // graceful cleanup > > is.close(); > > os.close(); > > } > > } > > > > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]