Asynchronous Backup of Databases

image_pdfimage_print

As of Jedox 6.0 SR3, it is possible to use IDatabase.backup method inside a Jedox Integrator Server job of type Groovy to execute a backup of databases. Such a job can then be scheduled or triggered on a regular basis to produce a backup of each database without the need to shutdown any of the services. Backup runs asynchronously in non-blocking mode, hence regular work should not be impacted. For every database, a separate ZIP archive will be produced containing the database itself plus the System database. Both of these are in a committed state – all journals are processed and no archives are present in a zip file which, when used, speeds up startup times of the database server. Use the zip-backup OLAP parameter to influence the compression level used.

Assuming there is a connection of type Jedox called localhost_demo which points to database Demo, a bare minimum groovy script which backups Demo database to a file Demo.zip inside Data directory could look like this:

IDatabase db = OLAP.getDatabase("localhost_demo");
db.backup("Demo.zip");

A more comprehensive script which backups all the databases for a specific connection and adds timestamp suffix to archive name is included in the Integrator Sample project “ETLTasks” in the setup, and looks similar to the code below:

// path to backup directory - data directory will be used if empty
String backupDirPath = "${BackupDirPath}";
// definition of helper function for backing up single DB
def backupDb(db, backupDirPath){
      // get current date/time
    Date dateNow = new Date();
    String newDate = dateNow.format( 'yyyyMMdd_HHmm' );
    // get suffix for backup file
    String suffix = "_" + newDate + ".zip";
      String dbN = db.getName();
      String fileName = backupDirPath + dbN + suffix; 
      if (dbN != "System")
      {
        LOG.info("Starting backup of database: '" + dbN + "'.");
        LOG.info("Trying to write filename: '" + fileName + "'.");
        try
        {
              db.backup(fileName);
              LOG.info("Finished backup of database: '" + dbN + "'.");
        }
        catch (pExc)
        {
              LOG.error(pExc);
        }
     }

IConnection conn = OLAP.getConnection("OlapTarget");
if (conn != null)
{
  LOG.info("_______________________________________________________________________________");
  for(IDatabase db:conn.getDatabases())
  {
    backupDb (db, backupDirPath);
  };
  LOG.info("_______________________________________________________________________________");
}
else
{
  LOG.error("No connection defined.");
}

It relies on at least the JedoxGlobal connection OlapTarget being properly set. By default, if the backupDirPath variable is not set, the backup job will write a ZIP file in the data directory of Jedox OLAP server; otherwise, the directory specified as a value for the backupDirPath variable is used. For this variable, forward slashes must be used as separators between directory names; backslashes are not allowed. The format of the archive name is <DB_NAME>_<DATE_TIME>.zip, e.g. Demo_20160321_1536.zip. Please note that the user running the Jedox OLAP Server service/process must have write access to the target directory to be able to create the output file.

image_pdfimage_print
Was this post helpful?
NoYes (+4 rating, 4 votes)
Loading...