Skip to Content
Author's profile photo Stefan Seemann

Using a SAP HANA XS Job to create data backups at a scheduled interval

SAP HANA XS offers the possibility to schedule applications as jobs. As database backups are triggered by executing SQL commands an application can be built which calls these SQL commands. This blog will provide an overview about howto write a simple XS application which creates a database backup and to schedule it as an XS job.

The first step is to install the SAP HANA database server. In this example SAP HANA SP 9 is used.

After the installation has finished successfully the Service for the XS engine is already running. The status can be checked within SAP HANA Studio or on the command line using the command “HDB info” as user gtiadm.


To make a first call to the the XS engine use your favorite browser and type in the URL below.


So, the database is succesfully installed, up and running. The XS engine is also working.
The next step is to create an SQL user whose permissions are limited to do backups and to work with the XS engine.

In this example the name of this user is BACKUP_OPERATOR.


To verify that the user is able to create backups, logon to the database using SAP HANA Studio and create the first backup.


So the user is able to create backups. The next step is to logon to the XS Admin tool using BACKUP_OPERATOR to make sure this is working fine too.


As everything is working fine we can start to build the small SAP HANA XS application which is executing the backup command.

We also build a test application to be able to check the final backup statement and to create a backup manually.

To keep things separated I create a new workspace first.


After the studio has restarted choose the development perspective by clicking “Open Development”.


The project data will be stored in the database GTI. Due to this we have to add the database instance to the current workspace.


Finally we can create to actual project.




After clicking through all the popups the project should be created succesfully. It has no files yet.


For this project we need five files:

  1. DataBackup.xsjob
    It contains the job definition.
  2. DataBackup.xsjs
    This file is called during the job execution. It only forwards the call to the file DataBackup.xsjslib
  3. DataBackup.xsjslib
    This file contains the actual command to create the database backup.
  4. index.html
    This is a simple html file which allows us to run the backup manually.
  5. DataBackupTest.xsjs
    This is a JavaScript file which is used by file index.html

The content of the files is as follows. You can use copy and paste.:


  function getSql(prefix) {

         return “BACKUP DATA USING FILE (‘” + prefix + “_BATCH_JOB’)”;


  function getTimestamp() {

        var date = new Date();

        var year = date.getFullYear();

        var month = date.getMonth() +1;

        var day = date.getDate();

        var hour = date.getHours();

        var minute = date.getMinutes();

        var second = date.getSeconds();

       return year + “_” + month + “_” + day + “_” + hour + “_” + minute + “_” + second;


function createBackupStatement(prefix) {

        return getSql(prefix + “_” + getTimestamp());


function createBackup(prefix) {

       var sql = createBackupStatement(prefix);

       var conn = $.db.getConnection();

      var stmt = conn.prepareStatement(sql);






  var dataBackup = $.import(“DataBackup.xsjslib”);

var prefix = $.request.parameters.get(“prefix”);

  var action = $.request.parameters.get(“action”);

  if (“Create backup command” === action) {

  var sql = dataBackup.createBackupStatement(prefix);

  $.response.setBody(“</p>SQL command for data backup:</p>” + sql);


if (“Create backup” === action) {


     $.response.setBody(“Backup created successfully. Check backup directory.”);



function createBackup(input) {

       var dataBackup = $.import(“DataBackup.xsjslib”);





      “description”: “Create data backup of database GTI”,

      “action”: “Automatic_Backup:DataBackup.xsjs::createBackup”,

      “schedules”: [ {

        “description”: “Create data backup of database GTI”,

                “xscron“: “* * * * * * 59”,

                “parameter”: { “prefix”: “MyScheduledBackup” }

        } ]




      Project to create a database backup.  </p>

          <form action=“DataBackupTest.xsjs”>

               <p>Prefix for backup:<br>

                      <input name=“prefix” type=“text” size=“30” maxlength=“30”>  </p>

              <p>  <input type=“submit” name=“action” value=“Create backup command”>

                      <input type=“submit” name=“action” value=“Create backup”>

           <input type=“reset” value=“Reset”>

             </p>  </form>


To save and activate the application press the “forward”-button. After the project was activated successfully we can start a test.
The application creates a backup using a custom prefix followed by the current timestamp.



The backup location is the same as it was when the backup was created within the Studio. Different paths or the usage of backint can be achieved with different backup commands.
The last step is to use this application as an XS job. For this we have to activate the scheduler inside the XS engine.


You might have to create the parameter “scheduler” if it does not exist.

The scheduling is active once the parameter is set. It is not necessary to restart the database or the XS engine.

To schedule the application as a job we have to logon to the XS Admin.


After clicking on the field “XS Job Dashboard” the job is shown with status INACTIVE. By clicking on the job you get into the details of the job.


By clicking the button ‘Edit Schedule’ you get a pop up where you can set the job active.


After pressing the button OK, the job has the new status ACTIVE.

But the job is not scheduled yet. To schedule the job the field ‘Active’ in the upper part of the browser needs to be checked. You also have to set the password for user BACKUP_OPERATOR and a Start- and End Time.


After pressing the button “Save Job” at the bottom of your browser the status of the job will change to “SCHEDULED” or, “RUNNING”.



Using the configuration from above the backup is scheduled every 59 seconds which is very often of course.

More details about the XS job itself can be found here.

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Nicholas Chang
      Nicholas Chang

      Thanks for sharing!

      Author's profile photo Former Member
      Former Member

      Thank you, Stefan!  🙂

      Author's profile photo Former Member
      Former Member

      Hi Stefan,

      I used the above procedure to configure the backup and its running fine.

      But how can i change the backup type to BACKINT from File system.


      Rajesh K

      Author's profile photo Former Member
      Former Member

      Hi Stefan/Others,

      I have followed the same procedure but i am getting error while activating xsjob like " required object does not exist". Please let me know if i missed anything.

      Thanks and Regards,