title: LotusNotes Script: backup All server database
body: <p>today i tried to do a copy of a database(design and documents) by doing right click on database-> New copy... and i see that the new copy of database have smallest dimension of the source database (source database 900mb and the new copy 170mb).
  I see also that if i access in the new copy of this database the size passes form 170mb to 400mb (i think is because notes create index...)
  But i need to copy database only to create a backup so the size is important because i have to do daily backup and to consulted it only in particoular case.</p>
  
  <p>So i built an agent to do this copy but the result is not the same, the new copy have the same dimension of the source database.
  <strong>Is there a trick to obtain the same "compression" of right click on database-> New copy...  but with script code ?</strong></p>
  
  <p>I post the code that i use but without  that compression:</p>
  
  <pre><code>Dim Db As NotesDatabase
      Dim Ws As New NotesUIWorkspace
      Dim Session As New NotesSession
      Dim DbDir As NotesDbDirectory
      Dim AllDocs As NotesView
      Dim SourceDb As NotesDatabase   
      Dim ArchiveDb As NotesDatabase
      Dim SourceDoc As NotesDocument
      Set Db=Session.CurrentDatabase      
      Set DbDir=Session.GetDbDirectory(Db.Server) 
      Set SourceDb = DbDir.GetFirstDatabase(DATABASE)
  
      Do While Not SourceDb Is Nothing                    
              Print"BackUp Database "+Cstr(SourceDb.FileName)
              Gosub BackUpDatabase
          Set SourceDb = DbDir.GetNextDatabase
      Loop
      Exit Sub    
  BackUpDatabase:
      If SourceDb.IsOpen=False Then Call SourceDb.Open( "", "" )
      Set ArchiveDb = SourceDb.CreateCopy( "", "C:\Test\"+Cstr(Day(Date))+"-"+Cstr(Month(Date))+"-"+Cstr(Year(Date))+"\"+SourceDb.FilePath)
  
      Set AllDocs = SourceDb.CreateView( "@AllDocs", "SELECT @All" )  
      Set SourceDoc=AllDocs.GetFirstDocument      
  
      Do While Not SourceDoc Is Nothing
          Call SourceDoc.CopyToDatabase(ArchiveDb)
          Set SourceDoc=AllDocs.GetNextDocument(SourceDoc)
      Loop
      Call AllDocs.Remove()
      Return
  </code></pre>