Tuesday, January 29, 2008

OBIEE backing up repository

When developing you sometimes need to go back in time. Developers have a natural tendency to forget checking in there work properly, SourceSafe safe systems have a tendency to crash.....
During a recent project I installed this simple script on all development machines and simple have it run every hour by a scheduler.

Stampme.cmd:

@ECHO off
SETLOCAL
IF [%1] NEQ [] goto s_start
:: Author - Simon Sheppard, July 2003
:: Tested for Windows NT, 2K, XP
:: Adapted by John Minkjan, January 2008 Ciber
ECHO STAMPME.cmd
ECHO Copy to a backup directory
ECHO and rename a file with the DATE/Time
ECHO.
ECHO SYNTAX STAMPME sh.rpd
ECHO.
:: To change the filename format just change around the last line below
GOTO :eof
:s_start
SET
_file=%~n1%
SET _pathname=%~f1%
SET _ext=%~x1%
::Get the date
:: note ISO 8601 date format would require 4 digit YYYY Year)
FOR /f "tokens=6-8
delims=/ " %%G IN ('NET TIME \\%computername%') DO (
SET _mm=%%G
SET
_dd=%%H
SET _yy=%%I
)
:: Get the time
FOR /f "tokens=1,2 delims=: "
%%G IN ('time/t') DO (
SET _hr=%%G
SET _min=%%H
)
copy "%_pathname%"
".\backup\%_file%-%_yy%-%_mm%-%_dd%@%_hr%-%_min%%_ext%"

Till Next Time

4 comments:

lukas flek said...

hi, the script does not work in my case. i can't script at dos at all so don't know where is the problem, but one is probably the separate SET on one line and sepatare _file= on the next one. but if i put these two on one line (SET _file=) is does not work either. it says "incorrect syntax - probably the copy command is not compiled correctly ...

John Minkjan said...

Which OS are you using?

regards John

lukas flek said...

hi, i've already made it work. the only problem was in line breaks. if you simply select the code on the page and paste it into notepad using clipboard, it preserves break lines at these are on the page. the code does not make sense then. so the solution is to remove these "false" break lines and the code works. but one question anyway: is it possible to change the code in order to insert two-digit mm, dd, hr and min. the current code backs up a rpd file as eg: rpd_name-2009-5-6@13-14.rpd. i would prefer: rpd_name-2009-05-06@13-14.rpd ... i use win xp

John Minkjan said...

Why don't you add an extra 0 and then use the DOS str command to select the part you want:
http://www.dostips.com/DtTipsStringManipulation.php

regards