Академический Документы
Профессиональный Документы
Культура Документы
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
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
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.
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
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.
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.
SAP Business One Application: How do I use the cron to schedule a backup
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
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.
SAP Business One Application: How do I use the cron to schedule a backup
This shows that the backup was successful and I can ignore the generated errors.
*|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:
SAP Business One Application: How do I use the cron to schedule a backup
LogCleanUp.pl:
SAP Business One Application: How do I use the cron to schedule a backup
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.
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
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
SAP Business One Application: How do I use the cron to schedule a backup
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
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
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 ?
SAP Business One Application: How do I use the cron to schedule a backup
Hendra Prakasa
Sep 23, 2015 9:05 AM
When I want to delete the catalog, why is this error ?
SAP Business One Application: How do I use the cron to schedule a backup
SAP Business One Application: How do I use the cron to schedule a backup
SAP Business One Application: How do I use the cron to schedule a backup
SAP Business One Application: How do I use the cron to schedule a backup
SAP Business One Application: How do I use the cron to schedule a backup
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.
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 ?
SAP Business One Application: How do I use the cron to schedule a backup
SAP Business One Application: How do I use the cron to schedule a backup
SAP Business One Application: How do I use the cron to schedule a backup
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 ***/
SAP Business One Application: How do I use the cron to schedule a backup
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
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
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
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?
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
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,
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,
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
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
SAP Business One Application: How do I use the cron to schedule a backup
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.
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.
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.
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
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
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.