-- DBBackupRoutine.RMD
-- Database Backup Routine
-- Author: A. Razzak Memon
-- Date Created: May 13, 2010
-- Supported Versions: 7.6, Turbo V-8, R:BASE eXtreme 9.0 (32/64)

LABEL Start
   CLS
   SET VAR vCaption TEXT = ' Backup Entire Database'
   SET VARIABLE vDialogMessage TEXT = +
   ((CHAR(013))+' You Have Selected to Backup the Entire Database!')
   DIALOG .vDialogMessage vYesNo vEndKey Yes +
   CAPTION .vCaption ICON STOP +
   OPTION TITLE_FONT_COLOR RED +
   |TITLE_FONT_NAME VERDANA +
   |TITLE_FONT_SIZE 10 +
   |TITLE_BOLD OFF +
   |BUTTON_OK_CAPTION &Continue +
   |BUTTON_CANCEL_CAPTION C&ancel +
   |BUTTON_FONT_COLOR GREEN +
   |THEMENAME R:BASE Rocks!
IF vYesNo = 'No' OR vEndKey = '[Esc]' THEN
   GOTO Done
ENDIF
-- Define Global Variables
   SET VAR vDBName TEXT = NULL
   SET VAR vFolderName TEXT = NULL
   SET VAR vBackupFileName TEXT = NULL
   SET VAR vDirectoryFileName TEXT = NULL
   SET VAR vYesNo TEXT = 'YES'
   SET VAR vEndKey TEXT = NULL
   SET VAR vPause3Message TEXT = NULL
   SET VAR vPause4Message TEXT = NULL
-- Step 1
LABEL GetDBName
   IF (CVAL('DATABASE')) <> 'RRBYW14' OR (CVAL('DATABASE')) IS NULL THEN
      CONNECT RRBYW14 IDENTIFIED BY NONE
   ENDIF
   SET VAR vDBName = (CVAL('DATABASE'))
-- Step 2
LABEL CheckBackupFolder
IF (CHKFILE((CVAL('CURRDIR'))+'\Backup')) <> 1 THEN
   MD Backup
ENDIF
   SET VAR vFolderName = ((CVAL('CURRDIR'))+'\Backup')
-- Step 3
LABEL BackupFileName
   -- Backup File Name Format:
   -- DatabaseName_CurrentDate_CurrentTime.BKP
   -- DatabaseName_CurrentDate_CurrentTime.LOB
   -- Procudure Used: UNLOAD Command
   SET VAR vBackupFileName = +
   ((CVAL('DATABASE'))+'_'+(FORMAT(.#NOW,'MMDDYYYY_HHNN'))+'.BKP')
-- Step 4
LABEL ConfirmData
   CLS
   SET VAR vDialogMessage = +
   ((CHAR(013))+'Database:'+(CHAR(009))&.vDBName+(CHAR(013))+ +
    'Backup Folder:'+(CHAR(009))&.vFolderName+(CHAR(013))+ +
    'Backup Files:'+(CHAR(009))&.vBackupFileName+'.BKP and'&.vBackupFileName +
    +'.LOB')
   CLS
   DIALOG .vDialogMessage vYesNo vEndKey YES +
   CAPTION ' Please Confirm Everything' +
   ICON APP +
   OPTION THEMENAME R:BASE Rocks!
   IF vEndKey = '[Esc]' OR vYesNo = 'No' THEN
      GOTO Done
   ENDIF
-- Final Step
LABEL DoBackup
   CLS
   SET VAR vPause3Message = +
   ((CHAR(013))+'Database Backup Routine in Process - Please Wait ...')
   PAUSE 3 USING .vPause3Message +
   CAPTION .vCaption +
   ICON APP +
   OPTION GAUGE_VISIBLE ON +
   |GAUGE_COLOR 2708091 +
   |GAUGE_INTERVAL 10 +
   |MESSAGE_FONT_NAME VERDANA +
   |MESSAGE_FONT_SIZE 10 +
   |MESSAGE_FONT_COLOR RED +
   |THEMENAME R:BASE Rocks!
   SET VAR vDirectoryFileName = (.vFolderName+'\'+.vBackupFileName)
   SET VAR vPause4Message = +
   ((CHAR(013))+'Now Creating'&.vDirectoryFileName)
   PAUSE 4 USING .vPause4Message +
   CAPTION .vCaption +
   ICON APP +
   OPTION MESSAGE_FONT_NAME VERDANA +
   |MESSAGE_FONT_SIZE 10 +
   |MESSAGE_FONT_COLOR RED +
   |THEMENAME R:BASE Rocks!
   OUTPUT .vDirectoryFileName
   SET NULL -0-
   UNLOAD ALL
   OUTPUT SCREEN
   PAUSE FOR 2
   SET NULL ' '
   CLS
   PAUSE 2 USING 'Backup Process Completed Successfully!' +
   CAPTION .vCaption +
   ICON Confirm +
   BUTTON 'Press any key to continue ...' +
   OPTION MESSAGE_FONT_NAME VERDANA +
   |MESSAGE_FONT_SIZE 10 +
   |MESSAGE_FONT_COLOR GREEN +
   |BUTTON_COLOR WHITE +
   |BUTTON_FONT_COLOR GREEN +
   |THEMENAME R:BASE Rocks!
LABEL Done
CLS
CLEAR VAR vDBName,vFolderName,vBackupFileName,vDirectoryFileName,vCaption, +
vDialogMessage,vYesNo,vEndKey,vPause3Message,vPause4Message
RETURN