Вы находитесь на странице: 1из 44

SAP Business One Application: How do I use

the cron to schedule a backup


Posted by Duncan Speidel Jul 24, 2013

Introduction on page 2
Script Prerequisites on page 2
Script Configuration on page 3
Script Configuration for version 4 on page
5
Setting Configuration file for backup.sh
on page 6
Changes to backup.sh for version 4 on
page 6
Executing a backup on page 7
Verify the backup on page 7
Backup log file cleanup on page 8
GetLastBackup.sh: on page 8
LogCleanUp.pl: on page 9
How to schedule the jobs on page 11
How do I confirm it worked? on page 12

Generated by Jive on 2016-08-01Z


1

SAP Business One Application: How do I use the cron to schedule a backup

Troubleshooting on page 13
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

Generated by Jive on 2016-08-01Z


2

SAP Business One Application: How do I use the cron to schedule a backup

- <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 users password in SAP HANA Database
It looks like:

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

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

Generated by Jive on 2016-08-01Z


3

SAP Business One Application: How do I use the cron to schedule a backup

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.

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.

Generated by Jive on 2016-08-01Z


4

SAP Business One Application: How do I use the cron to schedule a backup

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

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.

Generated by Jive on 2016-08-01Z


5

SAP Business One Application: How do I use the cron to schedule a backup

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.

Generated by Jive on 2016-08-01Z


6

SAP Business One Application: How do I use the cron to schedule a backup

After making these changes you can execute the script using backup.sh --configfile=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.

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.

Generated by Jive on 2016-08-01Z


7

SAP Business One Application: How do I use the cron to schedule a backup

The backup is verified using backup.sh -ld.

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.

*|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:

Here is the code for GetLastBackup.sh


#!/bin/sh

Generated by Jive on 2016-08-01Z


8

SAP Business One Application: How do I use the cron to schedule a backup

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:

Generated by Jive on 2016-08-01Z


9

SAP Business One Application: How do I use the cron to schedule a backup

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.

Generated by Jive on 2016-08-01Z


10

SAP Business One Application: How do I use the cron to schedule a backup

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:

*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.

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.

Generated by Jive on 2016-08-01Z


11

SAP Business One Application: How do I use the cron to schedule a backup

*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.

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

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.

Generated by Jive on 2016-08-01Z


12

SAP Business One Application: How do I use the cron to schedule a backup

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.
18242 Views Tags: sap_business_one, sap_hana

Duncan Speidel in response to Javed Khan on page 13


May 12, 2016 4:18 PM
It needs to communicate with index server which is listening on port 30015.
Javed Khan in response to Duncan Speidel on page 14
May 12, 2016 4:06 PM
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 ..???

Generated by Jive on 2016-08-01Z


13

SAP Business One Application: How do I use the cron to schedule a backup

Thanks and Regards,


Javed
Duncan Speidel in response to Javed Khan on page 14
May 12, 2016 3:41 PM
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
Javed Khan
May 12, 2016 8:57 AM
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

Duncan Speidel in response to Sudhir Nayak on page 15


Dec 9, 2015 3:37 PM
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

Generated by Jive on 2016-08-01Z


14

SAP Business One Application: How do I use the cron to schedule a backup

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
Sudhir Nayak in response to Duncan Speidel on page 15
Dec 8, 2015 11:24 PM
HI, But I am not looking info for Busines One, just for in premises HANA installation.
Do have script which is meant for HANA sps10 ?
Duncan Speidel in response to Sudhir Nayak on page 15
Dec 7, 2015 2:59 PM
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
Sudhir Nayak
Dec 5, 2015 12:30 AM
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.
Hendra Prakasa in response to Duncan Speidel on page 16
Sep 25, 2015 5:08 AM
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
backup_NDB_COUNT_1_databackup_0_1
backup_NDB_COUNT_2_databackup_0_1
backup_NDB_COUNT_3_databackup_0_1

--> Wed, 9 AM
--> Wed, 12 PM
--> Wed, 3 PM
--> Wed, 6 PM

Generated by Jive on 2016-08-01Z


15

SAP Business One Application: How do I use the cron to schedule a backup

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 ?

Duncan Speidel in response to Hendra Prakasa on page 17


Sep 24, 2015 3:23 PM
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
Duncan Speidel in response to Hendra Prakasa on page 17
Sep 24, 2015 3:20 PM
Are you getting the expected backups?
Duncan Speidel in response to Hendra Prakasa on page 17

Generated by Jive on 2016-08-01Z


16

SAP Business One Application: How do I use the cron to schedule a backup

Sep 24, 2015 3:18 PM


Please become ndbadm using su - ndbadm before you execute the script. It is not intended to run as root
user.
Duncan Speidel in response to Hendra Prakasa on page 17
Sep 24, 2015 3:14 PM
Which user are you using to execute the script? Does that user have access to all schemas?
Hendra Prakasa
Sep 23, 2015 9:09 AM
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

Hendra Prakasa
Sep 23, 2015 9:05 AM
When I want to delete the catalog, why is this error ?

Hendra Prakasa in response to Duncan Speidel on page 36


Sep 23, 2015 8:06 AM
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
Hendra Prakasa in response to Duncan Speidel on page 18

Generated by Jive on 2016-08-01Z


17

SAP Business One Application: How do I use the cron to schedule a backup

Sep 23, 2015 4:45 AM


Thanks Duncan,
But I'm still curious about this one error msg when doing backup.
* 258: insufficient privilege: Not authorized SQLSTATE: HY000
Duncan Speidel in response to Hendra Prakasa on page 18
Sep 22, 2015 4:06 PM
Glad you got it working.
Hendra Prakasa
Sep 22, 2015 8:16 AM
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

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

Hendra Prakasa in response to Duncan Speidel on page 21


Sep 22, 2015 8:12 AM
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 ?

Generated by Jive on 2016-08-01Z


18

SAP Business One Application: How do I use the cron to schedule a backup

Generated by Jive on 2016-08-01Z


19

SAP Business One Application: How do I use the cron to schedule a backup

Generated by Jive on 2016-08-01Z


20

SAP Business One Application: How do I use the cron to schedule a backup

Duncan Speidel in response to Hendra Prakasa on page 22


Sep 18, 2015 5:28 PM
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
Hendra Prakasa in response to Duncan Speidel on page 31
Sep 18, 2015 11:13 AM
Hi Duncan,

Generated by Jive on 2016-08-01Z


21

SAP Business One Application: How do I use the cron to schedule a backup

I tried GetLastBackup script, and get command not found,


I've change both file with dos2unix
I've put them the same folder with backup.sh

Hendra Prakasa in response to Duncan Speidel on page 27


Sep 18, 2015 10:09 AM
Hi Duncan,

Generated by Jive on 2016-08-01Z


22

SAP Business One Application: How do I use the cron to schedule a backup

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.

Hendra Prakasa in response to Duncan Speidel on page 27


Sep 18, 2015 8:53 AM

Generated by Jive on 2016-08-01Z


23

SAP Business One Application: How do I use the cron to schedule a backup

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 ?

Generated by Jive on 2016-08-01Z


24

SAP Business One Application: How do I use the cron to schedule a backup

Generated by Jive on 2016-08-01Z


25

SAP Business One Application: How do I use the cron to schedule a backup

Generated by Jive on 2016-08-01Z


26

SAP Business One Application: How do I use the cron to schedule a backup

Duncan Speidel in response to Hendra Prakasa on page 28


Sep 17, 2015 3:48 PM
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

Generated by Jive on 2016-08-01Z


27

SAP Business One Application: How do I use the cron to schedule a backup

I name my user store key DUNCAN. If everything works the next line will show
Connected to NDB@hanab1:30015.
Best regards,
Duncan
Hendra Prakasa in response to Duncan Speidel on page 29
Sep 17, 2015 9:39 AM
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

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 ***/

Generated by Jive on 2016-08-01Z


28

SAP Business One Application: How do I use the cron to schedule a backup

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;

Thanks & Regards,


Hendra

Duncan Speidel in response to Hendra Prakasa on page 29


Sep 16, 2015 2:52 PM
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

Generated by Jive on 2016-08-01Z


29

SAP Business One Application: How do I use the cron to schedule a backup

Hendra Prakasa
Sep 16, 2015 11:29 AM
Hi Duncan,
I've downlaoded version 4 backup HANA, but I got this error when running backup.sh
pls help

Agustin Marcos Cividanes


Aug 19, 2015 11:26 AM
Thanks for this document.
Kind regards
Agustn Marcos Cividanes
Kevin Joyner in response to Duncan Speidel on page 30
Jul 6, 2015 10:38 PM
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.
Duncan Speidel in response to Kevin Joyner on page 31
Jul 6, 2015 8:56 PM
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,

Generated by Jive on 2016-08-01Z


30

SAP Business One Application: How do I use the cron to schedule a backup

Duncan
Kevin Joyner
Jul 6, 2015 7:18 PM
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
Duncan Speidel in response to Luis Enrique Flores Gonzalez on page 31
Jul 1, 2015 2:42 PM
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
Luis Enrique Flores Gonzalez in response to Duncan Speidel on page 32
Jun 30, 2015 11:38 PM
Hello Duncan

Generated by Jive on 2016-08-01Z


31

SAP Business One Application: How do I use the cron to schedule a backup

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 message

Duncan Speidel in response to Luis Enrique Flores Gonzalez on page 32


Jun 30, 2015 9:00 PM
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
Luis Enrique Flores Gonzalez
Jun 30, 2015 8:55 PM
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?

Generated by Jive on 2016-08-01Z


32

SAP Business One Application: How do I use the cron to schedule a backup

regards
Duncan Speidel in response to Luis Enrique Flores Gonzalez on page 33
Jun 30, 2015 8:40 PM
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
Luis Enrique Flores Gonzalez
Jun 30, 2015 8:30 PM
Hello such good day

I am running tests and I have a doubt, this support is schema, that is if I have more than one database as
would apply the code.

greetings
mohammed homsi in response to mohammed homsi on page 34
Feb 23, 2015 8:54 AM
Thank you Duncan ,
but i need the

confirm it worked script ...


also
Best Regards,
Mohammad Homsi
Duncan Speidel in response to mohammed homsi on page 34
Feb 22, 2015 8:10 PM
Hi Mohammad Homsi,
I have updated the blog with the source code.

Generated by Jive on 2016-08-01Z


33

SAP Business One Application: How do I use the cron to schedule a backup

Best regards,
Duncan
mohammed homsi
Feb 22, 2015 4:43 PM
Dear Duncan,
Where i can find the script :

GetLastBackup.sh
and

LogCleanUp.pl

Best Regards,
Mohammad Homsi
Innovation Center in response to Duncan Speidel on page 34
Feb 12, 2015 3:08 AM
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
Duncan Speidel in response to Innovation Center on page 35
Feb 11, 2015 8:11 PM
Hi VJ,

Generated by Jive on 2016-08-01Z


34

SAP Business One Application: How do I use the cron to schedule a backup

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
Innovation Center
Feb 5, 2015 12:09 PM
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 MultiTenant Database Environment?
Thanks and Regards,
Vj
Adria Caireta in response to Duncan Speidel on page 35
Apr 10, 2014 5:14 PM
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
Duncan Speidel in response to Duncan Speidel on page 36
Apr 10, 2014 2:45 PM
Hi Adria,

Generated by Jive on 2016-08-01Z


35

SAP Business One Application: How do I use the cron to schedule a backup

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
Adria Caireta in response to Duncan Speidel on page 36
Apr 10, 2014 11:24 AM
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
Duncan Speidel in response to Adria Caireta on page 37
Apr 9, 2014 7:23 PM
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

Generated by Jive on 2016-08-01Z


36

SAP Business One Application: How do I use the cron to schedule a backup

#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

Adria Caireta
Apr 9, 2014 5:53 PM
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
Grzegorz Niecka
Mar 14, 2014 11:07 AM
For email notifications use posftix service (built-in Linux) and email (example gmail) account:
https://rtcamp.com/tutorials/linux/ubuntu-postfix-gmail-smtp/
then in backup.sh script add this line:
echo ${THE_DATE} ${THE_TIME} $4 | mail -s "HANA backup" your@email.com
Duncan Speidel in response to Grzegorz Niecka on page 38

Generated by Jive on 2016-08-01Z


37

SAP Business One Application: How do I use the cron to schedule a backup

Feb 27, 2014 7:38 PM


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
Grzegorz Niecka in response to Duncan Speidel on page 38
Feb 27, 2014 12:51 PM
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
Duncan Speidel in response to Grzegorz Niecka on page 39
Feb 20, 2014 4:30 PM
Hi Grzegorz,

Generated by Jive on 2016-08-01Z


38

SAP Business One Application: How do I use the cron to schedule a backup

Please visit Regular System Administration Tasks for SAP Business One Analytics and SAP Business One
Powered by HANA to see how to export a schema. It also shows how to import it with a different name. If you
leave rename schema "SBODEMOGB" to "<NewName>" off the import the schema is imported with the same
name. This is available as of HANA revision 61.
Best regards,
Duncan
Grzegorz Niecka
Feb 20, 2014 2:41 PM
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 ?
Adria Caireta in response to Duncan Speidel on page 39
Feb 17, 2014 9:17 AM
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
Duncan Speidel in response to Adria Caireta on page 41
Feb 14, 2014 5:45 PM
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.

Generated by Jive on 2016-08-01Z


39

SAP Business One Application: How do I use the cron to schedule a backup

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.

Generated by Jive on 2016-08-01Z


40

SAP Business One Application: How do I use the cron to schedule a backup

Click finish. You can script housekeeping but it is not as effective as this.
Best regards,
Duncan
Adria Caireta
Feb 14, 2014 10:09 AM
Hi Duncan,
First thanks for this document.

Generated by Jive on 2016-08-01Z


41

SAP Business One Application: How do I use the cron to schedule a backup

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
Duncan Speidel in response to Srikar Vankadaru on page 42
Dec 6, 2013 2:06 PM
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
Srikar Vankadaru
Dec 6, 2013 7:19 AM
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

Generated by Jive on 2016-08-01Z


42

SAP Business One Application: How do I use the cron to schedule a backup

6. A succinct email subject line with enough info to ignore mail or dive deeper
Thanks
Sri
Duncan Speidel in response to Srinivas Kakarla on page 43
Nov 27, 2013 8:32 PM
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
Srinivas Kakarla in response to Duncan Speidel on page 43
Nov 27, 2013 2:13 PM
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.
Duncan Speidel in response to Srinivas Kakarla on page 44
Nov 5, 2013 1:17 PM
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

Generated by Jive on 2016-08-01Z


43

SAP Business One Application: How do I use the cron to schedule a backup

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

Srinivas Kakarla
Nov 5, 2013 10:34 AM
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.

Generated by Jive on 2016-08-01Z


44

Вам также может понравиться