!=========================================================================
! Copyright (C) VMware, Inc. 1986-2011.  All Rights Reserved.
!
! $Id: shrinkdbf.topaz,v 1.11.2.1 2008-02-19 04:56:46 normg Exp $
!
! Name - shrinkdbf.topaz 
!
! Description -  Script to shrink a Repository using fullBackup/fullRestore
!     The Repository must fit in a single backup file in $dbfDir .
!
!     You must be logged in as SystemUser prior to running this script.
!
!=========================================================================

expectvalue nil
expectvalue GsFile
run
(GsFile existsOnServer: '$dbfDir/backup.dat') ifTrue:
  [GsFile removeServerFile: '$dbfDir/backup.dat']
%

expectvalue System
run
System stopUserSessions.
System sleep: 5.
%

expectvalue 0
run
System voteState
%

expectvalue true
run
SystemRepository fullBackupTo: '$dbfDir/backup.dat'
%

! logout to release Gem's temporary pages
logout
login

! Use the special restore method for minimal size repository file.
!  restore will always terminate with loss of session
expectvalue true
run
SystemRepository _destroyOtAndRestoreFrom: '$dbfDir/backup.dat' 
%

! get a new session after restore
login


! Repository assumed in partial logging mode, so restore from logs not needed

! if the audit fails, exit, so we still have the backup.dat for diagnosis

iferror exit 

expectvalue true
run
((System stoneConfigurationAt: #StnNumGcReclaimSessions) < 1)
  ifTrue:[System stoneConfigurationAt: #StnNumGcReclaimSessions put: 1 ].
System startAllReclaimGcSessions .
(System stoneConfigurationAt: #StnNumGcReclaimSessions) > 0
%

expectvalue true
run
System waitForAllGcGemsToStartForUpToSeconds: 30.
%


expectvalue true
run
SystemRepository auditWithLimit:50000
%

! leave backup.dat on file system for diagnosis if needed

! logout to release Gem's temporary pages
logout

login

expectvalue %String
run
SystemRepository fileSizeReport
%

expectvalue SystemRepository
run
SystemRepository shrinkExtents
%

expectvalue %String
run
SystemRepository fileSizeReport
%
