RE: Copy Directory to Directory function ( backup)

2004-01-15 Thread Nicolas Maisonneuve

- Original Message - 
From: "Nicolas Maisonneuve" <[EMAIL PROTECTED]>
To: "Lucene Users List" <[EMAIL PROTECTED]>
Sent: Thursday, January 15, 2004 3:58 PM
Subject: Re: Betreff: Copy Directory to Directory function ( backup)


> 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.(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 dir, erasing current contents.
> > >*
> > >* This can be used to write a memory-based index to disk.
> > >*
> > >* @param dir a Directory 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]



Re: Copy Directory to Directory function ( backup)

2004-01-15 Thread Nicolas Maisonneuve
hmm, yes
but i don't want open a indexWriter for this
and there is the performance question when the index is big

- Original Message - 
From: "Karsten Konrad" <[EMAIL PROTECTED]>
To: "Lucene Users List" <[EMAIL PROTECTED]>
Sent: Thursday, January 15, 2004 2:20 PM
Subject: AW: Copy Directory to Directory function ( backup)



Hi,

an elegant method is to create an empty directory and merge
the index to be copied into it, using .addDirectories() of
IndexWriter. This way, you do not have to deal with files
at all.

Regards,

Karsten

-Ursprüngliche Nachricht-
Von: Nicolas Maisonneuve [mailto:[EMAIL PROTECTED]
Gesendet: Donnerstag, 15. Januar 2004 13:28
An: [EMAIL PROTECTED]
Betreff: Copy Directory to Directory function ( backup)


hy ,
i would like backup a index.

1) my first idea  is to make a system copy of all the files
but in the FSDirectory class,  there is no public method to know where is
located the directory. A simple methode like
public File getDirectoryFile() {
return directory; would be great;
}
2) so i decide to create a copy(Directory source, Directory target) method
i seen the openFile() and createFile method but after i
but i don't know how use it (see my function  , this function make a
Exception )

private void copy (Directory source, Directory target) throws
IOException {
String[] files=source.list();
for(int i=0; i