Skip to Content

Introduction

There is a need to schedule a backup using cron. Cron is driven by a crontab (cron table) file, a configuration file that specifies shell commands to run periodically on a given schedule.  The SAP note 1651055 (https://service.sap.com/sap/support/notes/1651055) provides a backup script and PDF that explains how to use the script.

The backup.sh file provided by the script will execute a backup, it will also show you a list of log files that can be deleted because they are included in a backup.  The script does not delete the log files.  This blog post will show you how to configure the script, how to execute the script and provide 2 additional scripts that can be used to clean up old log files.

Everything shown below can be watched on a recording available from https://sap.na.pgiconnect.com/p93414224/.  If the link above is problematic the same information is available from https://scn.sap.com/docs/DOC-45655.

Please read note 1651055 and the attached pdf before proceeding.

You can find out more details about SAP HANA Database Backup and Recovery topics at Note 1642148 – FAQ: SAP HANA Database Backup & Recovery (S-user required).

You should review note https://service.sap.com/sap/support/notes/1950261 – “HANA Database Backup Policy Recommendations and Regular Backup Script “

Script Prerequisites

Before the script can be executed you need to use hdbuserstore to create a user store key that will be used to logon to the SAP HANA DB.  The hdbuserstore file is install with the HANA client files.  You execute the program as ndbadm.

The syntax of the command looks like

/usr/sap/hdbclient/hdbuserstore SET <KEY> <ENVIRONMENT> <USER> <PASSWORD>

Where:

– <KEY> is the identifier for the entry; can be freely chosen

– <ENVIRONMENT> defines the SAP HANA Database system in the form <hostname>:<port> where <port> is the SQL port of the indexserver process, i.e. 3<instance>15, <instance> being the two-digit instance number of the SAP HANA Database

– <USER> is the name of a SAP HANA Database user

– <PASSWORD> is that user’s password in SAP HANA Database

It looks like:

hdbuserstore.set.PNG

After the user store key is created, you can verify it exists using hdbuserstore list.

hdbuserstore.list.PNG

We are ready to configure the script.

Script Configuration

Download the script to your HANA Linux server.  I recommend keeping it in /usr/sap/NDB/home/scripts.  You will have to use the mkdir command to create the scripts directory.  I recommend keeping it here because it is central location with a clear naming providing information about the files contained within.

After you have the script uploaded to the SAP HANA server you need to set proper permissions.  This is done with the chmod command.  You also need to make sure it is owned by ndbadm and a member of the sapsys group, this is done with the chown command.

chmod 754 backup.sh

chown ndbadm:sapsys backup.sh

The script can now be executed, but execution will fail because we have not added our user key store to the script.  We add the user key to the script using the vi command.  In side the script we press the forward slash ‘/’ to execute a search.  In the search box we enter USE_HDBUSERSTORE and press enter to execute the search.

searchVI.PNG

The first occurrence of the term will be in the comments.  We need to change the value of USE_HDBUSERSTORE to TRUE and set USERSTORE_KEY to name of the key we created, the example key name is DUNCAN.

A few lines below we need to change USERSTORE_KEY to value of the key we created in the prerequisite section.  The example user store key name is DUNCAN.  Save you changes and exit vi.

hdbUserStoreInBackup.sh.png

The script stores the results of the executed backups in a HANA schema.  This is defined in the script with property STATS_SCHEMA.

STATS_SCHEMA.PNG

Script Configuration for version 4

The steps above are for the earlier versions of backup.sh.  Checking in note 1651055 we see that version 4, and later, come with a configuration file called backup_config_template.cfg.  The script is now called using backup.sh config_file=backup_config_template.cfg.  You can pass additional parameters after the configuration file.

Setting Configuration file for backup.sh

In backup_config_template.cfg you need to make the following changes.

In the SAP System ID of the SAP HANA Database Instance set the following fields:

  1. SID=NDB
  2. Instance=00
  3. Hostname=$HOST

At this time Business One only runs on a HANA DB with a SID of NDB and an instance number of 00.  If this changes replace step 1 and 2 with the values for your system.  Step 3 can be assigned to $HOST or you can hardcode your hostname.  I prefer to use Operating System variables because they are updated automatically if the hostname changes.

In the hdbsql and (if used) hdbuserstore information section make the following changes:

  • Confirm USE_HDBUSERSTORE=TRUE
  • USERSTORE_KEY=<key value>, in the example shown above we set USERSTORE_KEY=DUNCAN

In the statistics into database tables set the following:

  • STATS_SCHEMA=<Schema to create tables to track your backup history

When the backup is executed 2 z tables are created.  These tables are used to provide information about the backups.  I generally use SBODEMOUS but you can use a company DB, or create a backup schema.  The schema referenced most exist before you call the script.

If you do not want to track any information about the backup history leave STATS_SCHEMA blank and set WRITE_STATS_TO_TABLE to FALSE.  I would not recommend this.

Changes to backup.sh for version 4

The backup.sh script from note 1651055 is delivered as is, and is not supported by the SAP Support Team.  The note requires that you acknowledge this by changing the following lines in backup.sh.

  • 312: change the value of a varaible named I_ACKNOWLEDGE_THAT_THIS_SCRIPT_IS_NOT_SUPPORTED_BY_SAP to “YES”.
  • 1237:  change the value of a varaible named   I_ACKNOWLEDGE_THAT_I_MAY_NOT_OPEN_SAP_SUPPORT_MESSAGES_REGARDING_THIS_SCRIPT to “Yes”.
  • 1326: change the value of a varaible named I_ACKNOWLEDGE_THAT_THIS_IS_THE_FINAL_VERSION_OF_THIS_SCRIPT to “Certainly”.

You can use vi to jump directly to the line number but put +<line number> after the name of the file to be edited for example vi backup.sh +312.

After making these changes you can execute the script using backup.sh –config-file=backup_config_template.cfg the start of the script is the same as what you see below.  Note that with version 4 you also include the config-file.

Executing a backup

On the command line enter backup.sh.  The script will start after a built in delay as elapsed.

startBackup.sh.png

Verify the backup

It is possible you might see errors when the backup completes, like those shown below, and you want to verify it was successful.

BackupErrors.PNG

The backup is verified using backup.sh -ld.

backup-ld.PNG

This shows that the backup was successful and I can ignore the generated errors.

Backup log file cleanup

In order to get a list of logfiles that can be deleted post backup you execute backup.sh -ll –backup-id=<backup ID>.

We would use backup.sh -ll –backup-id=1374691689165 to get a list of logs that can be deleted post backup.

backup-ll.PNG

*|more is used here to prevent the output from overflowing the screen.  You do not need it and I will show a script that can be used to automatically cleanup these files,

Now, we have successfully execute a backup and seen the list of files that can be removed, how can this be automated?  I would propose the creation of 2 scripts, one is scheduled in cron the other is called by the scheduled script.  The scripts are GetLastBackup.sh and LogCleanUp.pl.

GetLastBackup.sh:

GetLastBackup.PNG

Here is the code for GetLastBackup.sh

#!/bin/sh

LASTBACKUP=`backup.sh -ld | sed -r  ‘s/^[^0-9]*([0-9]+).*/\1/’ | sed -r  ‘s/[^0-9]*//’|head -2|sed ‘/^$/d’`
#echo “LASTBACKUP =” $LASTBACKUP
#Build import file for Perl clean-up script
`backup.sh -ll –backup-id=$LASTBACKUP>logsToDelete.txt`
#Call Perl script to remove logs no longer requried
LogCleanUp.pl

This is an sh shell script that uses a regular expression to get the last backup ID.  The last backup ID is used as a parameter for backup.sh -ll which redirects output to a file named “logsToDelete.txt”.  The logsToDelete.txt file is used as an input parameter for LogClean.pl which deletes all listed files.

LogCleanUp.pl:

LogsToDelete.PNG

Here is the Perl code:

#!/usr/bin/perl

if ($argc!=0){
        $inFile = $ARGV[0];
}else{
        $inFile = “logsToDelete.txt”;
}

open(logfile,$inFile) ||die(“Opening “, $inFile, ” file failed\n”);
$position=0;

foreach $line (<logfile>){
        chomp ($line);
        #$line=~ s/[/”/]//g;
        $line =~ s/”//g;
        $deleteCmd=”rm “.$line;
        $result=system($deleteCmd);
        if ($result==0){
                print $line, “file deleted\n”;
                $position++;
        }
}

print $position, ” log files deleted\n”;


If you want to be notified if nothing is deleted add the code below to the end of the script.

if ($position == 0)

{

$TODAY = localtime();

$mailCmd = “echo \”0 Log files deleted\” |mail -s \”$TODAY LogCleanUp.pl  deleted no files\” yourEmail@companyName.com“;

system($mailCmd);

}


The code shown above will use the mail service on the Linux server to send a mail to you when no logs are deleted.  It requires that the Linux mail service be configured to send mails to internet users.  I used the localtime function to get the current date.  I provided no parameters so the date variable will be populated with a date like Wed Jul 29 12:13:09 2015.  If you would like a different date format visit http://www.tutorialspoint.com/perl/perl_date_time.htm for the options.

This is a simple Perl script that takes 1 command line argument, the name of the file containing the list of files to delete.  If no argument is provided it defaults to logsToDelete.txt.  It applies a few regular expressions to each line of the file and executes a delete.  The output looks like:

DeleteOutput.PNG

*More is shown because the script was executed with |more so output could be captured you will not see it when you run the scripts

Before you can run these scripts you need to execute chmod 754 LogCleanup.pl and chmod GetLastBackup.sh.

After the first run of these scripts it is common to see rm: cannot remover file this occurs because the list of log files no longer required is not updated post delete.  The space is freed.  The backup runs as expected but the references are left.

The Perl script’s last output is how many files were remove.

DeleteCount.PNG

How to schedule the jobs

In Linux we use cron to schedule jobs.  We edit the cron using the command crontab -e.  This command execute vi on the cron table.  Note Linux only supports editing the crontab using crontab -e manually editing the table will not work.

crontab-e.PNG

*Note –retention=8 sets the retention time period for the backup.  It is not required.  The sample shown above is from an internal sandbox system and few backups are required

The numbers before the path to the script provide the frequency and time the job should run. The graphic below shows what each position means.

cronTimeValue.png

After adding the jobs to the crontab you can verify the settings using crontab -l

crontab-l.PNG

How do I confirm it worked?

So far this document has shown you how to schedule the backup.sh script from note 1651055 via the cron tab.  The cron tab will regularly run the job to take a backup.  Everything up to this point will execute flawlessly but it does not do any error checking.  If you would like to receive alerts if the backup script exits with a non-zero return code, or one of the backup files is found to be inconsistent then you should use the script shown below.

ScriptToCheck.png

Please replace your.address@yourCompany.com with a valid email address.  In the cron tab you should schedule this script instead of backup.sh.  This script calls backup.sh.  GetLastBackup.sh should remain.

Troubleshooting

If you receive an error like “/usr/sap/NDB/home/scripts/GetLastBackup.sh: /usr/sap/NDB/home/scripts/backup.sh: /bin/bash^M: bad interpreter: No such file or directory” the file has Windows special characters in it for new line, or cartridge return that are not recommend by Linux.  You can fix this using dos2unix <scriptname> for example dos2unix backup.sh.


To report this post you need to login first.

70 Comments

You must be Logged on to comment or reply to a post.

  1. Srinivas Kakarla

    Duncan,

    Your blog helped in automating the weekly backups of SAP HANA instances. Thanks for that. I scheduled cron jobs to execute the backup.sh script which was tweaked to meet our requirements.

    Now I am looking at achieving the alerting mechanism also by sending an email post a successful/failed backup. I am planning to implement one of these:

    1. A cron job to check the status of backup and delete the oldest backup (8 weeks) if successful and also send the status to the recipients

    2. A database trigger to execute a procedure based on the backup status and mail the status.

    Any thought?

    Thanks & Regards,

    Srinivas K.

    (0) 
    1. Duncan Speidel Post author

      Hi Srinivas K.,

      The pdf attached to the note gives a lot of parameters that you can set.  One of them is retention. The retention parameter is number of days to keep a backup.  If you set the parameter to 56 it would keep backups for 8 weeks.  This would eliminate the need for a backup cleanup job.

      You could check the OS return code and send a mail based off that.  You could create a something like:

      #! /bin/bash

      /usr/sap/NDB/home/scripts/backup.sh  –retention=56 -q -p

      if $? != 0

        mail root@host -S”backup success”

      else

        mail root@host -S”backup failure”  

      fi

      The script above is first past, it might require some tweaks but I think it will provide the email functionality you require.

      Best regards,

      Duncan


      (0) 
      1. Srinivas Kakarla

        Thanks Duncan,

        I just eexecuted the backup script with the command 

        /usr/sap/NDB/home/scripts/backup.sh  –retention=56 -q -p and the backup files were created as  backup_<SID>_COUNT_51_databackup_0_1.

        I couldn’t interpret the value 51. I have the last 8 sets of backups of this instance in the same folder but they have different naming convention.

        Please advise,

        Thanks one again for your time.

        Regards,

        Srinivas K.

        (0) 
        1. Duncan Speidel Post author

          Srinivas K.,

          The script creates  backup_<SID>_COUNT_XX_databackup_0_1, where XX is an arbitrary number that keeps the name unique.  This ensures the backup is not overwritten.

          Best regards,

          Duncan

          (0) 
  2. Srikar Vankadaru

    Hi Duncan

    This script is just awesome. Thanks for sharing this piece 🙂 🙂

    Can you please share some script to enable below functionality in a mail:


    1. Success or Failure

    2. Failure cause

    3. Disk space before and after

    4. List of all backups present

    5. Email address(es) to send

    6. A succinct email subject line with enough info to ignore mail or dive deeper

    Thanks

    Sri

    (0) 
    1. Duncan Speidel Post author

      Hi Sri,

      Below is my response.

      1. Success or Failure

      You can check the value of $? if it is not 0 generally the application did not successful exit.

      2. Failure cause

      Will be provided by the back up script

      3. Disk space before and after

      Use the df utility

      4. List of all backups present

      Read the pdf attached to the note

      5. Email address(es) to send

      Use an internet search engine, like Google, for the syntax of the send mail command

      6. A succinct email subject line with enough info to ignore mail or dive deeper

      See point 5

      Best regards,

      Duncan

      (0) 
  3. Adria Caireta

    Hi Duncan,

    First thanks for this document.

    Is there a script to keep only a fixed number of backups and delete old?, Example only keep the last 7 backups and delete the rest.

    Best regards.

    Adrià

    (0) 
    1. Duncan Speidel Post author

      Hi Adrià,

      I am planning to publish a scrip that can meet your requirements, not sure when.  Until then you can backup house keeping in the HANA studio.  In the administrators prospective double click on backup and go to the Backup Catalog tab.  In the backup catalog right click on the oldest backup you wish to keep and select Delete Older backups.  On the next screen select Catalog and Backup location, confirm that File System is checked.

      SpecifyBackupSettings.PNG

      The next screen presents total size and what will be deleted.  It is possible that the size shown is greater than the size of the file system.  This happens because you have deleted files from the OS but not the reference to said file in the DB.  You can download a list of the files.

      ReviewBackupSettings.PNG

      Click finish.  You can script housekeeping but it is not as effective as this.

      Best regards,

      Duncan

      (0) 
      1. Adria Caireta

        Hi Duncan,

        Already knew this method, but for a customer must be an automatic process.

        I hope as early as possible publication of this valuable script.

        Thank you very much for your support.

        Best regards,

        Adrià

        (0) 
  4. Grzegorz Niecka

    Dear Duncan,

    I’m assuming that this described procedure backups HANA instance only…

    …and what about automated/scripted export and then backup only one selected schema/database ?

    (0) 
      1. Grzegorz Niecka

        Dear Duncan,

        exporting/importing procedure is known to me also with rename option, which is greatly improved in rev69.03.

        My concern is about automated backup of customers DB (schema) – similiar to “maintenance plan” from SQL MGM studio – when I can choose there DB to backup, choose backup destinantion and “clean old backup” task.

        For me as SAP B1 administrator it is more important to secure/backup customers DB (schema) than HANA configuration what is described in this tutorial.

        Reasuming: I want to schedule automated daily backup (export) of customers database (schema) instead HANA configuration.

        Regards

        GN

        (0) 
        1. Duncan Speidel Post author

          Hi GN,

          The backup discussed on this blog posting makes a full HANA backup of all schemas and the HANA configuration. 

          If you’d like to backup just one schema and not all you can export a single schema.  You can script it using cron.  You would have 2 scripts the first would have a .sql extension. It would look something like:

          \connect -n <hostname> -i 00 -u SYSTEM -p <password>;

          export “SBODEMOGB“.”*” as binary into ‘/home/SBODEMOGB‘ with replace threads 10;


          The second would be .sh and do nothing but call hdbsql would the input file argument and pass the first script.  Something like:

          hdbsql -I import.sql

          The scripts above were written from memory and not tested.

          Best regards,

          Duncan

          (0) 
  5. Adria Caireta

    Hi Duncan,

    I have two questions:

    1. Is there a script to clear the last backups automatically? without having to go to HANA Studio.

    2. If the first point is not possible, I need to generate a script to copy the latest HANA backup files to a shared directory (windows). My problem is, how do I get the last backup files (Data and log) I should copy?

    Thanks very much.

    King regards.

    Adrià

    (0) 
    1. Duncan Speidel Post author

      Hi Adri,

      The clean-up steps shown above should be run periodically because they clean-up things that are missed when you do manual clean-ups.  I do not have a script automate the steps above.

      I was previously asked for a script that would only keep the last backup taken.  That script can be found below.

      #!/bin/sh
      source /home/ndbadm/.sapenv.sh
      #Check if oldbackup directory exists if not create it
      BACKUPDIR=/usr/sap/NDB/HDB00/backup/data/

      if [ ! -d “/usr/sap/NDB/HDB00/backup/data/oldBackups” ]; then
              mkdir /usr/sap/NDB/HDB00/backup/data/oldBackups
              fi
      #Move old backups to oldBackups
      cd $BACKUPDIR
      mv * oldBackups
      #Take a backup
      /hanamnt/NDB/HDB00/scripts/backup.sh –retention=8  -q -p

      #Delete old backups
      cd $BACKUPDIR/oldBackups
      rm -f *

      You can create something similar to the above that moves the latest backup to a timestamp directory and then copy the timestamp directory to your windows storage.

      Hope this helps.

      Duncan

      (0) 
      1. Adria Caireta

        Hi Duncan,

        Thanks very much for your helpful.

        But I try to run the script and gives me error in the command line’source /home/ndbadm/.sapenv.sh‘ the error message is ‘Not found file or directory…’

        King regards.

        Adria

        (0) 
      2. Duncan Speidel Post author

        Hi Adria,

        The system I wrote this script for set the ndbadm home directory to /home/ndbadm/.  That is not the normal location.  The normal location is /usr/sap/NDB/home. Assuming you did not change the home directory, for ndbadm, when you installed HANA this should work.  The line becomes source /usr/sap/NDB/home/.sapenv.sh.  You can test the line from the command prompt.  I designed this to run using the ndbadm context.

        Best regards,

        Duncan

        (0) 
        1. Adria Caireta

          Thanks very much Duncan.

          I’ve only had to add “-r” to the rm command to delete subdirectories oldBackups.

          That work!

          I modified the crontab to run this script first (CleanUp.sh) and then run GetLastBackup.sh and then copy backup files to mounted windows shared folder.

          Best regards,

          Adria

          (0) 
      3. Hendra Prakasa

        Hi Duncan,

        thank you for this script,

        but instead of moving all the file to external folder, I wanted to copy file & keep the existing file backup on the server.

        how to do that?

        I know cp -fr \sourcepath \destpath

        but it will make longer if we copy all the files, I got retention for 14 days.

        how to select only the recent created backup file to copy to external folder

        (0) 
        1. Duncan Speidel Post author

          Hi Hendra,

          I would suggest that you create a script to call the backup.sh.  In that script I would created a directory with a time stamp for a name.  After the directory is created I would call backup.sh.  When it finishes the script can copy the backup files to the directory with the time stamp for a name.  You can create the directory on any storage attached to the Linux server.

          Best regards,

          Duncan

          (0) 
  6. Innovation Center

    Hello Duncan,

    Just would like to say thank you for the steps you have provided in this blog. This has been very useful in creating the HANA backup strategy in our Innovation Center.

    With the release of SPS09 and Multi-Tenancy, there is the need to backup the container as well as each tenants. Since each tenants will have it’s own port range, I am thinking to add a new entry in hdbuserstore for each tenant then create a new backup script for each tenant, would that be the correct approach in a Multi-Tenant Database Environment?


    Thanks and Regards,

    Vj

    (0) 
    1. Duncan Speidel Post author

      Hi VJ,

      I have just started reviewing multitenancy with SP9.  My current understanding is the early releases of SP 9 will offer Multiple Components One Database (MCOD), the MCOD version will not support tenant specific backups.  When you take a backup all tenants are included.  When you restore all tenants are restored.  The plan is to replace MCOD with Multi-tenant Database Containers (MDC).  The MDC concept will support tenant backups, it will also isolate users, admins and catalog.

      I hope this provides the answer that you seek.

      Best regards,

      Duncan

      (0) 
      1. Innovation Center

        Hi Duncan,

        Good day to you!

        Thanks for the information. According to what I’ve read and understood in the SAP SPS09 Delta Docs while the container (SystemDB) holds all tenants, it is important that both are backed up regularly hence the challenge now of using the backup script provided in SAP Note 1651055 . With regards to implementing the HANA backup script via cron, since each Tenants will have their own services (indexservers, scriptserver, etc.) using their own port range outside of 3XX15, and each tenant will have an isolated users which I believe can be registered via hdbuserstore individually.

        I haven’t fully tested yet this scenario but I guess I’ll have to create additional Tenants in our Labs to be able to test if creating a new backup script and registering each Backup users in each Tenant via hdbuserstore will work. Basically, a dedicated backup script and hdbuserstore entry for each Tenants.

        Thanks!

        Vj

        (0) 
    1. Duncan Speidel Post author

      Hi Luis,

      The backup described on this blog will backup all the schemas that are part of your HANA DB.  Everything returned by  select * from “SYS”.”SCHEMAS”;   will be included in the backup.

      If you have other doubts please provide more details.

      Best regards,

      Duncan

      (0) 
  7. Luis Enrique Flores Gonzalez

    Hello Duncan

    Thank you for answering my question, I share that already perform the checks and backups already working.

    Now all I have a problem running the GetLastBackup.sh file indicates that I did not find the directory, enter the edit that route must be added for you to start working?

    regards

    (0) 
    1. Duncan Speidel Post author

      Hi Luis,

      In some situations, depending on how the path variable is defined, you need to use explicit paths.  A call to `backup.sh -ll –backup-id=$LASTBACKUP>logsToDelete.txt` becomes `/usr/sap/NDB/home/scripts/backup.sh -ll –backup-id=$LASTBACKUP>logsToDelete.txt`. 

      Best regards,

      Duncan

      (0) 
      1. Luis Enrique Flores Gonzalez

        Hello Duncan

        Modify agree .sh comments you make me the code I remain as follows:

        ************************************************** *****

        #! / bin / sh

        LASTBACKUP = `/ usr / sap / NDB / home / scripts / backup.sh -ld | -r sed ‘s / ^ [^ 0-9] * ([0-9] +) * / \ 1 /.’ | -r sed ‘s / [^ 0-9] * //’ | head -2 | sed ‘/ ^ $ / d’

        #echo “LASTBACKUP =” $ LASTBACKUP

        #Build Import file for Perl clean-up script

        -ll /usr/sap/NDB/home/scripts/backup.sh `–backup-id = $ LASTBACKUP> logsToDelete.txt`

        #CALL Perl script to remove logs no longer requried

        LogCleanUp.pl

        ************************************************** *****

        When I run the scrip gives me the following messageCaptura.JPG

        (0) 
        1. Duncan Speidel Post author

          The error shown below is because the file has special DOS characters not recognized by the Linux OS.  You can fix using one of the following 2 methods:

          1. dos2unix GetLastBackup.sh
          2. perl -i -pe’s/\r$//;’ GetLastBackup.sh

          Best regards,

          Duncan

          (0) 
  8. Kevin Joyner

    At line 1294

    else

      DUMMY=$(echo ${INSTANCE} | grep -e [^0-9]);

      if [ $? -eq 0 ]; then

        # at least one non-numeric character in instance number

        ERROR_CODE=20

        ERROR=”Script Parameterization: non-numerical instance given: ${INSTANCE}”

        break;

      fi

      ping -c 1 ${HOSTNAME} &> /dev/null

      if ! [ $? -eq 0 ]; then

        # specified host name cannot be given

        ERROR_CODE=20

        ERROR=”Script Parameterization: cannot ping host name: ${HOSTNAME}”

        break;

      fi

    fi

    if ${NSTANCE]  is numeric won’t this always throw an error?

    Shouldn’t it be?

    else

      DUMMY=$(echo ${INSTANCE} | grep -e [^0-9]);

      if ! [ $? -eq 0 ]; then

    (0) 
    1. Duncan Speidel Post author

      Hi Kevin,

      The code in the delivered script works.  Countless people are using it with modifying the section you reference.  The check for non-numeric in the ID is working.

      Best regards,

      Duncan

      (0) 
      1. Kevin Joyner

        That’s good to hear.   I was just a bit mystified that when I do

        echo 01 | grep-e [^0-9]

        I get a return value of 0 for success.   The next line in the script then says if my return value is zero, throw an error.  So I get

        “Scrip Parameterization: non-numerical instance given: 01”

        However

        echo AB | grep [^0-9]

        returns ‘AB’  which is most definitely not numeric and not zero and therefore passes the check.

        (0) 
    1. Duncan Speidel Post author

      I’m guessing that the script contains special windows characters not reconized by Linux.  You can fix this using dos2unix backup.sh.

      Best regards,

      Duncan

      (0) 
      1. Hendra Prakasa

        Hi Duncan,

        Hi

        Thank you for your response, yes, after I convert using dos2unix, the command executed successfully, but I got stuck on this keystore, INVALID value for KEY

        SNAG-0112.jpg

        SNAG-0113.jpg

        I’ve created the backup user using this script, what step I’m missing ?

        Create role BACKUP_ADMIN_ROLE;

        /* System privilege required to create/restore backups */

        grant BACKUP ADMIN to BACKUP_ADMIN_ROLE;

        /* System privilege that allows reading all catalog metadata */

        grant CATALOG READ to BACKUP_ADMIN_ROLE;

        /*** Now create the user ***/

        create user BACKUP_ADMIN password Soltius2015;

        /* grant the role to this user */

        grant BACKUP_ADMIN_ROLE to BACKUP_ADMIN;

        /* and exempt the user from the password lifetime rules */

        alter user BACKUP_ADMIN disable password lifetime;

        SNAG-0114.jpg

        Thanks & Regards,

        Hendra

        (0) 
        1. Duncan Speidel Post author

          Hi Hendra,

          The script is coded to use a key called BACKUP_ADMIN.  However, the hdbuserstore list command shows a key named BACKUPADMIN.  I think if you remove the underscore it will work. 

          As ndbadm you can use hdbsql to test the key.  In hdbsql use the following to test your certificate:

          \c -i 00 -n <hostname> -U <keyname>. 

          An example would be:

          \c -i 00 -n hanab1 -U DUNCAN

          I name my user store key DUNCAN.  If everything works the next line will show

          Connected to NDB@hanab1:30015.

          Best regards,

          Duncan

          (0) 
          1. Hendra Prakasa

            Dear Duncan,

            yes, after I changed the key, the script worked, and got stuck on ‘insufficient previledge’

            I made a new SCHEMA named : ‘BACKUPLOG’ what should i do to get priledge this schema ?

            I also tried to change to configuration to ‘SBODEMOAU’ but still got error priviledge.

            the Z_SCRIPT will automaticaly created right if the database name correct ?

            SNAG-0116.jpg

            SNAG-0119.jpg

            SNAG-0117.jpg

            SNAG-0118.jpg

            (0) 
          2. Hendra Prakasa

            Hi Duncan,

            Now, I’ve create the table manually (is it OK to create direct table on SAP HANA ? like in SBODemoUS ? because on SQL version we prohibited to create table directly on SQL)

            and it show success, but still some little error

            ‘Not Authorized SQLState’ I don’t know what command that did not running,

            but when I checked the backup folder, the backup already created.

            SNAG-0125.jpg

            SNAG-0124.jpg
            (0) 
            1. Duncan Speidel Post author

              Hi Hendra,

              Which user are you using to execute the backup?  Does that user have access to the tables that you created?  Does the trace file explicity state which authorization is missing?

              Best regards,

              Duncan

              (0) 
              1. Hendra Prakasa

                Dear Duncan,

                I’m using ‘BACKUP_ADMIN’ user,

                I’ve given object prilieges ‘BACKUPLOG’ DB for logging the table.

                I’ve also granted Roles ‘BACKUP_ADMIN_ROLE’

                is there any more previlege should I give ?

                the error only 1 previldege, , I check it success insert log into table ‘Z_BACKUP_STATISTICS’, ‘Z_SCRIPT_BACKUP_RUNS’,’Z_SCRIPT_CONFIG_CUSTOMIZE’

                which trace file should I look up to check this ? can u tell me the path ?

                SNAG-0145.jpg

                SNAG-0146.jpg

                SNAG-0147.jpg

                (0) 
  9. Hendra Prakasa

    Hi Duncan,

    Btw, how to make schedule, like I want to automatic backup every 3 hours,

    I make 3 cron jobs but only 1 can run…

    for example : I want to backup every 8 AM, 12:00, 15:00

    SNAG-0148.jpg

    Nevermind, I found out the code 😀

    0 6-20/3 * * * /hana/data/script/backup.sh -q –retention=14 –config-file=/hana/data/script/backup_config_template.cfg

    (0) 
  10. Hendra Prakasa

    I don’t know what I’ve done wrong, but now everytime I do backup, the COUNT_<number>

    doesnt icrement, it always replace COUNT_0..

    but it works before…. with retention 14

    SNAG-0156.jpg

    (0) 
      1. Hendra Prakasa

        Dear Duncan,

        No, this is not what I expected,

        it supposed to everyday I take backup every 3 hours (9AM, 12, 3 PM, etc) &

        the count must be running everyday, so it must like this :

        backup_NDB_COUNT_0_databackup_0_1  –> Wed, 9 AM

        backup_NDB_COUNT_1_databackup_0_1  –> Wed, 12 PM

        backup_NDB_COUNT_2_databackup_0_1  –> Wed, 3 PM

        backup_NDB_COUNT_3_databackup_0_1  –> Wed, 6 PM

        Yesterday, before I clean up backup catalog & log files it runs fine, but after that, it messed up like this, everyday only take 1 backup ?

        SNAG-0158.jpg

        SNAG-0159.jpg

        (0) 
  11. Sudhir Nayak

    Hi Duncan,

    I am running this script and it’s working perfect on my current Version sp09 on single instance DB. It has been running for 6 month now.

    Now we are moving to sp10 and multi tenant approach. I can see the comment above that you are reviewing the multi tenant SCRIPT. Did you got chance to modify the script for MULTI-TENANT. Appreciate your quick reply.

    (0) 
    1. Duncan Speidel Post author

      Hi Sudhir,

      This blog posting was created for SAP Business One partner’s who are running SAP Business One powered by HANA.  At this point in time SPS 10 is not certified for Business One, nor is HANA multi-tenant.  If you are interested in multi-tenant  please use the Cloud Control Center, the CCC can create multi-tenants in you HANA DB that can be consumed by your customers.

      Best regards,

      Duncan

      (0) 
        1. Duncan Speidel Post author

          Hi Sudhir,

          The script in question comes from note 1651055 – Scheduling SAP HANA Database Backups in Linux (S-ID required to access the note).  Attached to the note you will find both the script and a pdf.  The pdf provides instructions.  I am not the note author, nor am I the script author.  I am SAP Business One Solution Architect.  This blog post was created for B1 Partners to provide a clear path to taking a backup of their customer’s SAP HANA system.  If you do not find the answer to your topic I would suggest posting a question to SAP HANA and In-Memory Computing

          Best regards,

          Duncan

          (0) 
  12. Javed Khan

    Hi Experts,

    While creating a user store key the below command was used.

    /usr/sap/hdbclient/hdbuserstore SET <KEY> <ENVIRONMENT> <USER> <PASSWORD>


    “usph1vm2179:~>hdbuserstore set DUNCAN usph1vm2179:30015 SYSTEM fakePassword”


    Where


    “<ENVIRONMENT> defines the SAP HANA Database system in the form <hostname>:<port> where <port> is the SQL port of the indexserver process, i.e. 3<instance>15, <instance> being the two-digit instance number of the SAP HANA Database “


    But while defining port 3<instance>15, can you please let me know what is 3 and 15 indicates, is it compulsory to use 3 and 15 or can we assign any other port number as well.


    Thanks in advance

    Javed

    (0) 
    1. Duncan Speidel Post author

      Hi Javed,

      The ports defined are the ports used by HANA, yes they are compulsory.  If you use ports other than the ones used by HANA the resulting user store will not be usable.

      Best regards,

      Duncan

      (0) 
      1. Javed Khan

        Thanks Duncan for your reply..

        The ports of SAP HANA platform are reserved for indexserver from 30015 to 39915, in which 00 to 99 is instance no.

        It is fine that they are compulsory but still I didn’t understand the specific use of 3 and 15 in that ..???

        Thanks and Regards,

        Javed

        (0) 
  13. Jim Spath

    Good blog; sorry for my tardy response. I am a bit concerned with this line:

    system($mailCmd);

    And, for the equivalent shell calls to mail/mailx.

    Generally you would want to capture the exit status of a system command to determine whether it did as expected. Cron is bad at that kind of error notification anyway (we use an enterprise scheduler so script failures get escalated).

    Having experience with email failure modes, other areas to consider:

    • What happens when the recipient has an out-of-office message on?  Sometimes those fill up root or admin email boxes.
    • What happens when the recipient email address goes away, such as leaving their company or a new domain is created without forwarders?
    • What happens if the SMTP forwarder address embedded somewhere is no longer valid?

    However, I learned what I was searching for:

    #! /bin/bash

    🙂

    Jim

    (0) 
    1. Duncan Speidel Post author

      Hi Jim,

      I’m glad  you found the blog informative.

      The system($mailCmd) is used here as an example of a way to communicate with person, or persons, responsible for the system.  There are many different ways to do this, I choose this one.


      If you add that functionality to the script you will need to perform periodic clean-up tasks.  You can use mail, or mailx to cleanup the inbox. 

      I would suggest using a shared email address.  Create an address with a name like backupService@yourDomain.com.  The created user will never leave the company.  The other option would be a distribution list instead of an email address.

      We can do our best to plan for everything but sometimes something like SMTP forwarder address embedded somewhere is no longer valid happens, and we have to find the error and correct.

      I hope I have addressed your concerns.  This is written for the Business One partner who work with very small customers.  The goal is to make it as simple as possible while still addressing there concerns.  The B1 customer no longer has to use these scripts.  They can now schedule the HANA backup using RSP (details available from Central page of Backup/Recovery topic for SAP Business One, version for SAP HANA).  If there is anything else you feel should be added, please let me know.

      Best regards,

      Duncan

      (0) 
      1. Jim Spath

        Duncan:

          Thank you for the reply.  Yes, best practices include using group email addresses.  We have recently found issues with distribution lists and Office 365, though that’s a bit off topic here.

          I’m sharing my experiences from years (ok, decades) in the trenches, trying to help others avoid pitfalls I have found.  My comments about error trapping are more general than specific to one product, and I hope you don’t mind me hijacking this thread a tad.

          Here’s an example of the “looks like it works” email dilemma I just tested on a Linux machine:

        = =

        $ echo “hello in there” | mailx -s sap01 james.spath@[].com

        $ echo $?

        0

        = =

        That command worked, according to the exit code.  However, no one will get this message, due to buried rules/configuration:

        = =

        # mailq

        -Queue ID- –Size– —-Arrival Time—- -Sender/Recipient——-

        4A694202C9      479 Thu Aug 25 09:59:59  []@[]

        (connect to x.y.z[999.999.999.999]:25: Connection refused)

                                                 james.spath@[].com

        — 0 Kbytes in 1 Request.

        = =

        Jim

        (0) 
        1. Duncan Speidel Post author

          Jim,

          Thank you for getting back to me.  It is always helpful when I receiver feedback that can be used to further enable B1 partners. 

          The further down the rabbit hole you go, the more interesting Linux becomes.  I’ve done a lot with it but everyday I learn something more.

          My standing recommendations to all B1 partners is to test everything heavily before going live.  It is possible to trigger failure of the above and from that determine remediation steps to keep the customer happy.

          Best regards,

          Duncan

          (0) 
          1. Jim Spath

            We call that a “successful failure” when an alert is generated during testing of error states.  Not much good if the failure goes unnoticed!

            🙂

            (0) 
  14. Alfonso Duro

    Hi Duncan,

    When executing the ./backup.sh –config-file=backup_config_template.cfg.

    I get the following error :

    hanab1:/usr/sap/S00/home/scripts ./backup.sh –config-file=backup_config_template.cfg
    : command not foundplate.cfg: line 15:
    : command not foundplate.cfg: line 27:
    : command not foundplate.cfg: line 57:
    : command not foundplate.cfg: line 68:
    : command not foundplate.cfg: line 83:
    “)syntax error: invalid arithmetic operator (error token is ” touch: cannot touch `/usr/sap/S00\r\r/HDB00\r\r/192.168.1.150\r/trace\r/script_log_backup_Thu.txt\r’: No such file or directory

    : No such file or directoryg: line 1318: /usr/sap/

    Can you help me? I don´t know how to solve the problem.

    Thank you so much.

    Regards,

    Alfonso

     

    (0) 
    1. Alfonso Duro

      Sorry Ducan,

      I just read the solution in the troubleshooting.

      Sorry!!!.

      I think I create bad the user store key. Because I can´t access the path

      /usr/sap/hdbclient/hdbuserstore, the console shows the message “hdbuserstore: Not a directory”, 

      and when executing the ./backup.sh –config-file=backup_config_template.cfg.

      I get the following error :

      * -10104: Invalid value for KEY (MAC)

      * -10104: Invalid value for KEY (MAC)

      * -10104: Invalid value for KEY (MAC)

      * -10104: Invalid value for KEY (MAC)

      …..

      then What is the path? and the command looks like:

      “set MAC  192.168.1.150:30015 SYSTEM fakePassword mypassword”, is ti correct?

       

      and  What is the command for verify if it exists?

      I try “hdbuserstore list” and the console shows “command not found”.

      Thank you so much.

      Regards,

      Alfonso

       

       

      (0) 

Leave a Reply