Automatically backing up the TM1 data directory

Ideas and tips for enhancing your TM1 application
Post Reply
User avatar
Martin Ryan
Site Admin
Posts: 1952
Joined: Sat May 10, 2008 9:08 am
OLAP Product: TM1
Version: 10.1
Excel Version: 2010
Location: Wellington, New Zealand
Contact:

Automatically backing up the TM1 data directory

Post by Martin Ryan » Tue Feb 05, 2013 12:27 am

Backups have come up a few times but I've noticed we haven't put anything in this useful code forum about it. Here's how I've rolled mine...

1) I installed 7zip on the server that runs the backups.

2) I wrote the main bit of code in a batch file called "backupSlave.bat"

Code: Select all

:: Call this file with two arguments - the source folder (first argument) and the destination folder (second argument)
:: e.g. backupSlave.bat C:\TM1\MyServer\Data G:\Backups\MyServer
:: This file will create a timestamped folder within the destination folder, copy the source into the destination
:: run a zip then delete the copied folder.

::@echo off

:: Retrieve the two parameters which will be the directory to be backed up 
:: and the directory to back it up into respectively
set "srcFolder=%~1"
set "destnFolder=%~2"

if "%srcFolder%"=="" (
  set errorMsg=no srcFolder provided
  goto :exitwitherror
) else (
  echo srcFolder set to %srcFolder%
)
if "%destnFolder%"=="" (
  set errorMsg=no destnFolder provided
  goto :exitwitherror
) else (
  echo destnFolder set to %destnFolder%
)

set hh=%time:~-11,2%
set /a hh=%hh%+100
set hh=%hh:~1%
Set dateseed=%date:~10,4%%date:~7,2%%date:~4,2%-%hh%%time:~3,2%

set targetDir=%destnFolder%\%dateseed%

mkdir %targetDir%

:: copy the data.  /C switch tells it to carry out even if there are sharing violations (common with tm1s.log)
xcopy "%srcFolder%" "%targetDir%" /e /C

:: zip it up
"C:\Program Files\7-Zip\7z.exe" a -tzip ""%targetDir%".zip" "%targetDir%" -r

:: Remove the unzipped directory
RD /S /Q "%targetDir%"

:: Avoid error handler
goto :exitwithouterror

:exitwitherror
echo An error occurred - %errorMsg%

:exitwithouterror
3) I wrote separate batch files for each instance I'm backing up (but this could be skipped and folded directly into step 4).

Code: Select all

:: Calls the slave to backup the source folder (first argument) to the destination folder (second argument)
:: the slave will create a timestamped folder within the destination folder

E:\TM1\scripts\backupSlave.bat \\server\e$\TM1\MyServer G:\Backups\MyServer
4) I have a standalone instance called "backups" that does nothing but run a chored TI process that calls the batch file created in step 3 with this in the prolog
ExecuteCommand('E:\TM1\scripts\backupMaster.bat', 0);

Not sure if that's the best way, but it's been working for me for about a year now and has saved my bacon at least a dozen times.
Please do not send technical questions via private message or email. Post them in the forum where you'll probably get a faster reply, and everyone can benefit from the answers.
Jodi Ryan Family Lawyer

TM1KS
Posts: 14
Joined: Tue Apr 09, 2013 6:35 am
OLAP Product: TM1
Version: 10.1
Excel Version: 2007

Re: Automatically backing up the TM1 data directory

Post by TM1KS » Thu Apr 25, 2013 11:41 am

Hi Alan,
Thanks for the script.
I tried using it with only difference of the line where it uses 7zip to compress. Instead I used the code for WinRar.

Code: Select all

:: zip it up & remove the unzipped directory
"C:\Program Files (x86)\WinRAR\Rar.exe" m -r ""%targetDir%".RAR" "%targetDir%"
however, I don't see anything in the backup folder.
The process completes successfully.
I even tried changing the logging to DEBUG, but it does not show any error messages.
What could possibly be wrong?

upali
Posts: 38
Joined: Thu Oct 11, 2012 6:15 am
OLAP Product: TM1
Version: 10.2.2.4
Excel Version: 2010
Location: Melbourne, Australia

Re: Automatically backing up the TM1 data directory

Post by upali » Mon Apr 29, 2013 7:09 am

Thanks for the code mate... I use this simple DOS command to clear old backup files, which runs through the Scheduler.

Code: Select all

@echo *** Started - %date% - %time% ***@echo on

forfiles /P "D:\TM1Database\App_backup" /S /M *.zip /D -90 /C "cmd /c del @path"

:EXIT
@echo *** Completed - %date% - %time% ***

User avatar
Martin Ryan
Site Admin
Posts: 1952
Joined: Sat May 10, 2008 9:08 am
OLAP Product: TM1
Version: 10.1
Excel Version: 2010
Location: Wellington, New Zealand
Contact:

Re: Automatically backing up the TM1 data directory

Post by Martin Ryan » Wed May 01, 2013 11:32 pm

upali,
That's useful, thanks for the addition.

TM1KS,

I haven't used WinRar before. 7zip is freeware and often used. It's a reliable tool.

If you want to stick with WinRar, you'll just have to use trial and error. Type things out in the command line till you find out what works, then insert that into the batch file.

BTW, while Alan is our most prolific poster, he's not our only poster. ;)
Please do not send technical questions via private message or email. Post them in the forum where you'll probably get a faster reply, and everyone can benefit from the answers.
Jodi Ryan Family Lawyer

Craig Trevor
Posts: 7
Joined: Tue Jul 28, 2009 4:43 am
OLAP Product: TM1
Version: 10.1.1
Excel Version: Excel 20010
Location: Brisbane, Australia

Re: Automatically backing up the TM1 data directory

Post by Craig Trevor » Tue Jun 18, 2013 11:12 pm

I use 7-zip as well. I the following code in the Epilog of a scheduled process:

Code: Select all

sExec = 'C:\Program Files\7-Zip\7z.exe';
sBackupDirectory = 'E:\TM1\TM1 Archive\';
sDataDirectory = 'E:\TM1\Server\Data\';

sFileName = 'Data.' | TIMST( NOW(), '\Y\m\d.\h\i', 1) | '.zip';
sArgs = ' a -tzip ';
sCommand = sExec | sArgs | '"' | sBackupDirectory | sFileName | '" "' | sDataDirectory |  '"';
EXECUTECOMMAND(sCommand,0);
This has worked flawlessly for more than 2 years now.

Just update the sBackupDirectory to your Archive location, and sDataDirectory to your TM1 data directory.

Kyro
Community Contributor
Posts: 123
Joined: Tue Nov 03, 2009 7:46 pm
OLAP Product: IBM Cognos TM1 all the way!
Version: You name it.
Excel Version: 2003 -2007 -2010
Location: Sydney, Australia
Contact:

Re: Automatically backing up the TM1 data directory

Post by Kyro » Tue Jul 02, 2013 2:36 am

Thats the same code as on our blog - posted pretty much two years ago. :lol:
http://blog.tm1tutorials.com/2011/10/04 ... 1-backups/

Post Reply