As already mentioned in my previous blog post Autosave of SAP instances’ work folder sometimes it is really necessary to keep content of work folder. For SAP systems running on Unix (AIX, HP-UX, Oracle-Solaris, Linux) I already have found a workaround. But how about Windows? Well, after some testing I can share my experiences with you. Count with the same Pros and Cons as previously:
- SAP saves work folder automatically while startup
- No 3rd party tool involved
- Date and time of saving is part of filename
- File system may overflow
- You have to manually delete unnecessary archives later on
- Some delay while startup procedure
Are you curious? Let’s check the steps.
First of all, please note, that it’s Windows, therefore some more manual steps will be necessary. Why exactly? Because regional setting, in this case datum and time format may be different on operating system level depending on your region.
Okay, and what now? Tell me more, I can’t wait. Let the show begin!
- Check in <drive>:\usr\sap\<SID>\D<VEBMGS><NR>\work\sapstart.log what profile is responsible for starting up SAP.
Example: Startup Profile: “\\<sapglobalhost>\sapmnt\<SID>\SYS\profile\START_D<VEBMGS><NR>_<hostname>”
- Find a suitable Start_Program_<NR> line entry for this profile where <NR> is a unique, two-digit number in this profile.
- Increase the highest available Start_Program_<NR> by one.
- highest available Start_Program_<NR> entry is: Start_Program_04 = <command>
- next entry will start therefore with: Start_Program_05 = <command>
- Add the following line: Start_Program_<NR> = <command>
Example: Start_Program_05 = immediate cmd /c start /B $(DIR_CT_RUN)\SAPCAR -cfi $(DIR_INSTANCE)\work_”%date:.=%_%time::=%”.SAR -C $(DIR_INSTANCE)\work . -F “core*”
Note: “%date:.=%_%time::=%” depends on regional settings of Windows. Check first what echo %date% and echo %time% gives back. All characters which are not allowed in file names on Windows (for example: “/” or “:”) must be replaced by other characters or removed. You can define the character to be changed after “:” in variable with character defined after “=”. E.g.: outcome echo %time% is 10:23:52,02 with not allowed characters of filename but echo %time::=.% replaces “:” by “.” this way outcome is 10.26.58,33. Or echo %time::=% replaces “:” by blank and outcome is 103009,89 which is already a valid name for files. But this is rather for Microsoft than for SAP.
dir <drive>:\usr\sap\<SID>\D<VEBMGS><NR> | findstr /I “work”
15.10.2015 15:50 <DIR> work
15.10.2015 15:44 252.201 work_15102015_154442,47.SAR
If echo %date%_%time% has this format Mon 10/19/15_11:02:04.65 create a command script (e.g.: backup.cmd) in DIR_INSTACE folder (<drive>:\usr\sap\<SID>\D<VEBMGS><NR>) with content
set date=%date: =0%
set time=%time: =0%
SAPCAR -cfi ..\work_”%date%_%time%”.SAR -C ..\work . -F “core*”
and add this line in profile: Start_Program_<NR> = immediate $(DIR_INSTANCE)\<name>.cmd
Example: Start_Program_05 = immediate $(DIR_INSTANCE)\backup.cmd
Result: SAR looks like work_101915_105336.SAR
Adam, and what is your recommendation? Which method is the simplest?
The most common solution is to use powershell for date and time formatting. In this case you don’t have to mess with command line but powershell does it. You only have to add this line in profile: Start_Program_<NR> = immediate powershell -ExecutionPolicy bypass -command SAPCAR -cfi ..\work_$(Get-Date -format yyyyMMdd_HHmmss).SAR -C ..\work . -F “core*”
Result: SAR looks like work_20151019_105337.SAR
Explanation of profile entry and SAPCAR options:
Same is valid as in Autosave of SAP instances’ work folder
Success. Or rather almost success.
We’re already close to the end. If you want to extract the archive created according to method 1, an error appears:
SAPCAR -xvf <drive>:\usr\sap\<SID>\D<VEBMGS><NR>\work_15102015_154442,47.SAR -R <path\work_test
SAPCAR: error opening <drive>:\usr\sap\<SID>\D<VEBMGS><NR>\work_15102015_154442 (error 6). The system cannot find the file specified.
SAPCAR: 0 file(s) extracted
SAPCAR: error opening 47.SAR (error 6). The system cannot find the file specified.
SAPCAR: 0 file(s) extracted
Just run SAPCAR without arguments and you’ll find the answer. “,” is the trick.
And what’s our trick to overcome this?
- Rename the archive, remove “,” in filename and extract it by SAPCAR
- Replace “,” by “*” in SAPCAR command and it’ll work:
SAPCAR -xf <drive>:\usr\sap\<SID>\D<VEBMGS><NR>\work_15102015_154442*47.SAR -R <path>\work_test
SAPCAR: processing archive <drive>:\usr\sap\<SID>\D<VEBMGS><NR>\work_15102015_154442,47.SAR (version 2.01)
SAPCAR: 105 file(s) extracted