<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Berthou.com &#187; db2</title>
	<atom:link href="http://www.berthou.com/us/tag/db2/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.berthou.com/us</link>
	<description>A french developper blog</description>
	<lastBuildDate>Mon, 09 Aug 2010 08:55:28 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5</generator>
		<item>
		<title>DB2 &#8211; An image problem on the Open system ?</title>
		<link>http://www.berthou.com/us/2008/02/27/db2-an-image-problem-on-the-open-system/</link>
		<comments>http://www.berthou.com/us/2008/02/27/db2-an-image-problem-on-the-open-system/#comments</comments>
		<pubDate>Wed, 27 Feb 2008 19:39:06 +0000</pubDate>
		<dc:creator>rberthou</dc:creator>
				<category><![CDATA[db2]]></category>

		<guid isPermaLink="false">http://www.berthou.com/us/2008/02/27/db2-an-image-problem-on-the-open-system/</guid>
		<description><![CDATA[I have worked in the informatic for over twenty years and during all these years I have used many different data bases (relational, hierarchic, or network). So I have followed the evolution and sometimes the disparitions of these data bases. Today I am still surprised of teh small place that DB2 occupy on the open [...]]]></description>
				<content:encoded><![CDATA[<p>I have worked in the informatic for over twenty years and during all these years I have used many different data bases (relational, hierarchic, or network).<br />
So I have followed the evolution and sometimes the disparitions of these data bases.<br />
Today I am still surprised of teh small place that DB2 occupy on the open Systems, and I give you in this article my opinion on this lateness.</p>
<p><img src="/_img/DB2_famheader.gif" alt="DB2 logo" class="right"/><br />
First I would say DB2 has no problem on the Open Systems :</p>
<ul>
<li>Performances : very good </li>
<li>Price : Competitive except of course in front of OpenSource</li>
<li>Functionality  : Good security</li>
<li>Evolution : Regular version of the product</li>
</ul>
<p><span id="more-42"></span></p>
<h2 class="titre2">An image problem or something else ?</h2>
<p><b>An image problem</b> : According to me it is because of the story of DB2/IBM and his &#8220;Big system&#8221; image. It mostly stay associated with &#8220;Owner system&#8221;.<br />
Indeed, when we talk about DB2 we usually think MVS, VSE ans even AS/400, we associated it rarely to Windows (where we prefer SQL-serveur) Unix (here it is Oracle) or Linux (with of course MySQL).<br />
<img src="/_img/DB2_joinvision.png" alt="Database evolution chart" class="center"/></p>
<p><b>Linked sales</b> : When we buy an application &#8220;key in hand&#8221; it is usally delivered in standard on an limitate number of data bases (usaully SQL-Serveur and Oracle). And if we want the support of an other base it implies an additional cost.<br />
Yet I find that DB2 is very rarely supported in standard by his applications and SQL-Serveur is usually included with a Window Serveur.</p>
<p><b><br />
Less &#8220;owner&#8221; system:</b> :  Actually ( and since many years), the Big Systems are stalling and it have a direct impact on the part of markeks and the notoriety of DB2 because it is teh leader on these Systems.<br />
The companies using a &#8220;Owner System&#8221; also use &#8220;cover systems&#8221; (Unix/Linux/Windows) for littles applications, delivered with their own data base (Oracle ou SQL-Serveur). This data bases are administrated and if the administrator have no problems, it is natural to chose these data bases that we already now if we abbandon the &#8220;Mainframe&#8221;.</p>
<p><b>Sale team</b> : IBM use &#8220;partners&#8221; to commercialize his products, but often his &#8220;partners are multi-casquettes and as data bases, they mostly recommend Oracle ou SQL-Serveur by praising the merit of their team qualified in these technologies.</p>
<h2 class="titre2">The futur&#8230;</h2>
<p>I think IBM perfectly knows this problem and I hope he would be able to solve it to gove back the place DB2 merit on the &#8220;Open Systems&#8221;. Finally I invite you to test this data base if it is not already done and to verify that your application work on this base.</p>
<p class="alertLink">
<a href="http://www.mysql.fr/why-mysql/marketshare/" target="_blank">http://www.mysql.fr/why-mysql/marketshare/</a> Evolution of the markek part<br />
<a href="http://troels.arvin.dk/db/rdbms/" target="_blank">http://troels.arvin.dk/db/rdbms/</a> Comparatif fonctionnalités<br />
<a href="http://www.ibm.com/software/data/db2/" target="_blank">http://www.ibm.com/software/data/db2/</a> The official site<br />
<a href="http://www14.software.ibm.com/webapp/download/search.jsp?pn=DB2+9" target="_blank">Downloads</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.berthou.com/us/2008/02/27/db2-an-image-problem-on-the-open-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DB2 backup script on Linux</title>
		<link>http://www.berthou.com/us/2008/01/31/db2-backup-script-on-linux/</link>
		<comments>http://www.berthou.com/us/2008/01/31/db2-backup-script-on-linux/#comments</comments>
		<pubDate>Thu, 31 Jan 2008 19:00:01 +0000</pubDate>
		<dc:creator>rberthou</dc:creator>
				<category><![CDATA[db2]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.berthou.com/us/2008/01/31/db2-backup-script-on-linux/</guid>
		<description><![CDATA[DB2 Backup Script After my news about DB2 backup script under Windows, I give you in this small article a solution to do the same thing under Linux. To Backup a database this IBM/DB2 gives you a graphic interface quite simple to use &#8220;Control-Center&#8221;, but if you want you include this backup in a batch [...]]]></description>
				<content:encoded><![CDATA[<h2 class="titre2">DB2 Backup Script</h2>
<p>After my news about DB2 backup script under Windows, I give you in this small article a solution to do the same thing under Linux.</p>
<p>To Backup a database this IBM/DB2 gives you a graphic interface quite simple to use  &#8220;Control-Center&#8221;, but if you want you include this backup in a batch script you must write a backup script without GUI.</p>
<p>In this new I explain how to write a windows script procedure (.bat or .cmd) to backup your DB2 database.</p>
<p>In this sample I considered that you must close your database before backup ( It&#8217;s possible to do this in &#8220;ONLINE&#8221; mode but it&#8217;s more complexe &#8212; include log file, rollforward&#8230;&#8211;) and I use a database <b>SAMPLE</b> (it is his name) for this test .</p>
<p>the goal of this scripts is to :</p>
<ul>
<li>Quiesce database (close)</li>
<li>Backup your data</li>
<li>UnQuiesce database (open)</li>
<li>Zip backup file</li>
<li>Clean/Delete old backup rows in DB2 catalogue</li>
<li>Delete old backup files</li>
</ul>
<p><span id="more-39"></span></p>
<p class="alertWarning">
Warning ! If you want to do a backup between two differents OS you must use db2move tools (for exmple a backup/restore between Windows and Linux not work).
</p>
<h2 class="titre2">DB2 command</h2>
<p>To execute in a script a command you must initialize DB2 working context. In Windows it is made by a <b>db2cmd</b> but in linux/unix you can do this with the execution of  <b>db2profile</b>.</p>
<p>Commands :</p>
<ul>
<li> <a href="http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/core/r0008635.htm" target="_blank">QUIESCE</a></li>
<li> <a href="http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/core/r0008636.htm" target="_blank">UNQUIESCE</a>
<li>
<li> <a href="http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/core/r0001933.htm" target="_blank">BACKUP DATABASE</a> </li>
<li> PRUNE </li>
</ul>
<p>File <b>sample_backup.db2</b></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CONNECT</span> <span style="color: #993333; font-weight: bold;">TO</span> sample ;
QUIESCE <span style="color: #993333; font-weight: bold;">DATABASE</span> IMMEDIATE FORCE CONNECTIONS;
<span style="color: #993333; font-weight: bold;">CONNECT</span> RESET;
&nbsp;
BACKUP <span style="color: #993333; font-weight: bold;">DATABASE</span> sample <span style="color: #993333; font-weight: bold;">TO</span> <span style="color: #ff0000;">&quot;/db2_backup&quot;</span> <span style="color: #993333; font-weight: bold;">WITH</span> <span style="color: #cc66cc;">2</span> BUFFERS BUFFER <span style="color: #cc66cc;">1024</span> PARALLELISM <span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">WITHOUT</span> PROMPTING;
&nbsp;
<span style="color: #993333; font-weight: bold;">CONNECT</span> <span style="color: #993333; font-weight: bold;">TO</span> sample;
UNQUIESCE <span style="color: #993333; font-weight: bold;">DATABASE</span>;
<span style="color: #993333; font-weight: bold;">CONNECT</span> RESET;
&nbsp;
TERMINATE ;</pre></td></tr></table></div>

<p>Warning : If your current user can not be connected to your database to make a backup you must change this user in CONNECT with these parameters.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CONNECT</span> <span style="color: #993333; font-weight: bold;">TO</span> sample <span style="color: #993333; font-weight: bold;">USER</span> monuser <span style="color: #993333; font-weight: bold;">USING</span> monpassword;</pre></td></tr></table></div>

<p>DB2 saves in his catalogue somes informations about each backup. I advise you to clean it often with the command <a href="http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/core/r0001992.htm" target="_blank">PRUNE HISTORY</a> .</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="sql" style="font-family:monospace;">PRUNE HISTORY <span style="color: #cc66cc;">20071021</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #993333; font-weight: bold;">DELETE</span>;</pre></td></tr></table></div>

<p>This command will delete from the catalogue the informations on previous backup and will delete associated log files</p>
<h2 class="titre2">Batch script file</h2>
<p>In my opinion I&#8217;m not a Windows batch specialist and according to me the date calculation (<b>delmax</b>) of this script can be amelirated (more simple).</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># +----------------------------------------------------------+</span>
<span style="color: #666666; font-style: italic;"># +   Script de sauvegarde DB2 avec gestion de delete        +</span>
<span style="color: #666666; font-style: italic;"># +----------------------------------------------------------+</span>
<span style="color: #666666; font-style: italic;"># + Ver. + Auteur   + Remarques                              +</span>
<span style="color: #666666; font-style: italic;"># +------+----------+----------------------------------------+</span>
<span style="color: #666666; font-style: italic;"># + 1.00 + RBerthou +                                        +</span>
<span style="color: #666666; font-style: italic;"># +----------------------------------------------------------+</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># definition de l environnement de travail DB2</span>
. <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>db2inst<span style="color: #000000; font-weight: bold;">/</span>sqllib<span style="color: #000000; font-weight: bold;">/</span>db2profile
&nbsp;
<span style="color: #007800;">NBHISTO</span>=<span style="color: #000000;">12</span>
<span style="color: #007800;">MINDATE</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> <span style="color: #660033;">--date</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$NBHISTO</span> days ago&quot;</span> +<span style="color: #000000; font-weight: bold;">%</span>Y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #000000; font-weight: bold;">`</span>
REM +- Fin initialisation    -+
&nbsp;
<span style="color: #007800;">destdir</span>=<span style="color: #000000; font-weight: bold;">/</span>db2_backup
<span style="color: #007800;">db2backupdir</span>=<span style="color: #007800;">$destdir</span><span style="color: #000000; font-weight: bold;">/</span>SAMPLE.0<span style="color: #000000; font-weight: bold;">/</span>DB2<span style="color: #000000; font-weight: bold;">/</span>NODE0000<span style="color: #000000; font-weight: bold;">/</span>CATN0000
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;DB2 Backup&quot;</span>
db2 <span style="color: #660033;">-v</span> -f<span style="color: #007800;">$destdir</span><span style="color: #000000; font-weight: bold;">/</span>sample_backup.db2 -z<span style="color: #007800;">$destdir</span><span style="color: #000000; font-weight: bold;">/</span>sample_backup.log
<span style="color: #007800;">returnCode</span>=<span style="color: #007800;">$?</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$returnCode</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Erreur BACKUP DB2 : <span style="color: #007800;">$returnCode</span>&quot;</span>
   <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$returnCode</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; Suppression historique backup DB2 PIB &quot;</span>
db2 <span style="color: #660033;">-v</span> CONNECT TO SAMPLE user myuser using mypassword
db2 <span style="color: #660033;">-v</span> <span style="color: #c20cb9; font-weight: bold;">prune</span> <span style="color: #7a0874; font-weight: bold;">history</span> <span style="color: #007800;">$MINDATE</span> and delete
db2 <span style="color: #660033;">-v</span> connect reset
<span style="color: #007800;">returnCode</span>=<span style="color: #007800;">$?</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$returnCode</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Erreur BACKUP DB2 PRUNE : <span style="color: #007800;">$returnCode</span>&quot;</span>
   <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$returnCode</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Suppression physique des anciens fichiers</span>
<span style="color: #007800;">DELTA</span>=<span style="color: #000000;">50</span>
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$DELTA</span> <span style="color: #660033;">-gt</span> <span style="color: #007800;">$NBHISTO</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">do</span>
      <span style="color: #007800;">MAXDATE</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> <span style="color: #660033;">--date</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DELTA</span> days ago&quot;</span> +<span style="color: #000000; font-weight: bold;">%</span>Y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #000000; font-weight: bold;">`</span>
      <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>db2data<span style="color: #000000; font-weight: bold;">/</span>SAMPLE.0.db2inst.NODE0000.CATN0000.<span style="color: #007800;">$MAXDATE</span><span style="color: #000000; font-weight: bold;">*</span>
      <span style="color: #007800;">DELTA</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>DELTA - <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Fin BACKUP DB2 : <span style="color: #007800;">$returnCode</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$returnCode</span></pre></td></tr></table></div>

<h2 class="titre2">Remarques</h2>
<ul>
<li>I advise you, of course, to test this script in developpement environnement and mainly to try to test a restore procedure.</li>
<li>You can also make an <b>Online</b> database or tablespace backup but it&#8217;s more difficult (include log, rollforward,&#8230;) and if you are interested in that I write a new on this on the following weeks.
</ul>
<h2 class="titre2">Links</h2>
<p class="alertLink">
<a href="http://www.ibm.com/developerworks/db2/library/techarticle/0307fierros/0307fierros.html" target="_blank">Introduction to DB2 UDB Scripting on Windows</a><br />
<a href="http://www.hotline-pc.org/batchscripts.htm" target="_blank">Exemple de script batch windows</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.berthou.com/us/2008/01/31/db2-backup-script-on-linux/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Windows script for a DB2 backup</title>
		<link>http://www.berthou.com/us/2008/01/10/windows-script-for-a-db2-backup/</link>
		<comments>http://www.berthou.com/us/2008/01/10/windows-script-for-a-db2-backup/#comments</comments>
		<pubDate>Thu, 10 Jan 2008 07:53:13 +0000</pubDate>
		<dc:creator>rberthou</dc:creator>
				<category><![CDATA[db2]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.berthou.com/us/2008/01/10/windows-script-for-a-db2-backup/</guid>
		<description><![CDATA[DB2 Backup Script A database is very usefull but it&#8217;s always important to backup very often your data. To do this IBM/DB2 gives you a graphic interface quite simple to use &#8220;Control-Center&#8221;, but if you want you include this backup in a batch script you must write a backup script without GUI. In this new [...]]]></description>
				<content:encoded><![CDATA[<h2 class="titre2">DB2 Backup Script</h2>
<p>A database is very usefull but it&#8217;s always important to backup very often your data. To do this IBM/DB2 gives you a graphic interface quite simple to use  &#8220;Control-Center&#8221;, but if you want you include this backup in a batch script you must write a backup script without GUI.</p>
<p>In this new I explain how to write a windows script procedure (.bat or .cmd) to backup your DB2 database.</p>
<p>In this sample I considered that you must close your database before backup ( It&#8217;s possible to do this in &#8220;ONLINE&#8221; mode but it&#8217;s more complexe &#8212; include log file, rollforward&#8230;&#8211;) and I use a database <b>SAMPLE</b> (it is his name) for this test .</p>
<p>the goal of this scripts is to :</p>
<ul>
<li>Quiesce database (close)</li>
<li>Backup your data</li>
<li>UnQuiesce database (open)</li>
<li>Zip backup file</li>
<li>Clean/Delete old backup rows in DB2 catalogue</li>
<li>Delete old backup files</li>
</ul>
<p><span id="more-34"></span></p>
<h2 class="titre2">DB2 command</h2>
<p>To execute in a script a command you must initialize DB2 working context. In Windows it is made by a <b>db2cmd</b> but in linux/unix you can do this with the execution of  <b>db2profile</b>.</p>
<p>Commands :</p>
<ul>
<li> <a href="http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/core/r0008635.htm" target="_blank">QUIESCE</a></li>
<li> <a href="http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/core/r0008636.htm" target="_blank">UNQUIESCE</a>
<li>
<li> <a href="http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/core/r0001933.htm" target="_blank">BACKUP DATABASE</a> </li>
<li> PRUNE </li>
</ul>
<p>File <b>sample_backup.db2</b></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CONNECT</span> <span style="color: #993333; font-weight: bold;">TO</span> sample ;
QUIESCE <span style="color: #993333; font-weight: bold;">DATABASE</span> IMMEDIATE FORCE CONNECTIONS;
<span style="color: #993333; font-weight: bold;">CONNECT</span> RESET;
&nbsp;
BACKUP <span style="color: #993333; font-weight: bold;">DATABASE</span> sample <span style="color: #993333; font-weight: bold;">TO</span> <span style="color: #ff0000;">&quot;C:<span style="color: #000099; font-weight: bold;">\d</span>b2_backup&quot;</span> <span style="color: #993333; font-weight: bold;">WITH</span> <span style="color: #cc66cc;">2</span> BUFFERS BUFFER <span style="color: #cc66cc;">1024</span> PARALLELISM <span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">WITHOUT</span> PROMPTING;
&nbsp;
<span style="color: #993333; font-weight: bold;">CONNECT</span> <span style="color: #993333; font-weight: bold;">TO</span> sample;
UNQUIESCE <span style="color: #993333; font-weight: bold;">DATABASE</span>;
<span style="color: #993333; font-weight: bold;">CONNECT</span> RESET;
&nbsp;
TERMINATE ;</pre></td></tr></table></div>

<p>Warning : If your current user can not be connected to your database to make a backup you must change this user in CONNECT with these parameters.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CONNECT</span> <span style="color: #993333; font-weight: bold;">TO</span> sample <span style="color: #993333; font-weight: bold;">USER</span> monuser <span style="color: #993333; font-weight: bold;">USING</span> monpassword;</pre></td></tr></table></div>

<p>DB2 saves in his catalogue somes informations about each backup. I advise you to clean it often with the command <a href="http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/core/r0001992.htm" target="_blank">PRUNE HISTORY</a> .</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="sql" style="font-family:monospace;">PRUNE HISTORY <span style="color: #cc66cc;">20071021</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #993333; font-weight: bold;">DELETE</span>;</pre></td></tr></table></div>

<p>This command will delete from the catalogue the informations on previous backup and will delete associated log files</p>
<h2 class="titre2">Batch script file</h2>
<p>In my opinion I&#8217;m not a Windows batch specialist and according to me the date calculation (<b>delmax</b>) of this script can be amelirated (more simple).</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="winbatch" style="font-family:monospace;"><span style="color: #66cc66;">@</span>echo <span style="color: #0080FF; font-weight: bold;">off</span>
REM <span style="color: #66cc66;">+----------------------------------------------------------+</span>
REM <span style="color: #66cc66;">+</span>   DB2 Windows backup script width delete        <span style="color: #66cc66;">+</span>
REM <span style="color: #66cc66;">+----------------------------------------------------------+</span>
REM <span style="color: #66cc66;">+</span> Ver. <span style="color: #66cc66;">+</span> Autor    <span style="color: #66cc66;">+</span> Remarques                              <span style="color: #66cc66;">+</span>
REM <span style="color: #66cc66;">+------+----------+----------------------------------------+</span>
REM <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1.00</span> <span style="color: #66cc66;">+</span> RBerthou <span style="color: #66cc66;">+</span>                                        <span style="color: #66cc66;">+</span>
REM <span style="color: #66cc66;">+----------------------------------------------------------+</span>
REM <span style="color: #66cc66;">+--</span> Attention les numeriques de la forme 01 .. 0999 sont  <span style="color: #66cc66;">-+</span>
REM <span style="color: #66cc66;">+--</span>   considérés comme des nb octal donc prb de calcul    <span style="color: #66cc66;">-+</span>
REM <span style="color: #66cc66;">+--</span> d ou l ajout du <span style="color: #cc66cc;">1</span> devant certaines variables          <span style="color: #66cc66;">-+</span>
&nbsp;
REM <span style="color: #66cc66;">+-</span> Warning the date est au considéré au format français  <span style="color: #66cc66;">-+</span>
REM <span style="color: #66cc66;">+-</span> Format de la date <span style="color: #ff0000;">&quot;dd/mm/yyyy&quot;</span>                         <span style="color: #66cc66;">-+</span>
REM <span style="color: #66cc66;">+-</span>  a modifier suivant vos paramètres                     <span style="color: #66cc66;">-+</span>
<span style="color: #800080;">for</span> <span style="color: #66cc66;">/</span>f <span style="color: #ff0000;">&quot;tokens=1-4 delims=/-\ &quot;</span> <span style="color: #66cc66;">%%</span>a <span style="color: #800080;">in</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'date /t'</span><span style="color: #66cc66;">&#41;</span> do <span style="color: #66cc66;">&#40;</span>
  set mjour=<span style="color: #66cc66;">%%</span>a
  set mmois=<span style="color: #66cc66;">%%</span>b
  set mannee=<span style="color: #66cc66;">%%</span>c
<span style="color: #66cc66;">&#41;</span>
set mydate=<span style="color: #66cc66;">%</span>mannee<span style="color: #66cc66;">%%</span>mmois<span style="color: #66cc66;">%%</span>mjour<span style="color: #66cc66;">%</span>
set nbhisto=07
&nbsp;
<span style="color: #800080;">if</span> <span style="color: #66cc66;">/</span>I <span style="color: #ff0000;">&quot;%mjour%&quot;</span> GTR <span style="color: #ff0000;">&quot;%nbhisto%&quot;</span> <span style="color: #66cc66;">&#40;</span>
   set <span style="color: #66cc66;">/</span>a mjour=<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">%</span>mjour<span style="color: #66cc66;">%-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">%</span>nbhisto<span style="color: #66cc66;">%</span>
<span style="color: #66cc66;">&#41;</span> <span style="color: #800080;">else</span> <span style="color: #66cc66;">&#40;</span>
   <span style="color: #800080;">if</span> <span style="color: #66cc66;">/</span>I <span style="color: #ff0000;">&quot;%mmois%&quot;</span> == <span style="color: #ff0000;">&quot;01&quot;</span> <span style="color: #66cc66;">&#40;</span>
         set <span style="color: #66cc66;">/</span>a mannee=<span style="color: #66cc66;">%</span>mannee<span style="color: #66cc66;">%-</span><span style="color: #cc66cc;">1</span>
         set <span style="color: #66cc66;">/</span>a mmois=<span style="color: #cc66cc;">12</span>
   <span style="color: #66cc66;">&#41;</span> <span style="color: #800080;">else</span> <span style="color: #66cc66;">&#40;</span>
       set <span style="color: #66cc66;">/</span>a mmois=<span style="color: #66cc66;">%</span>mmois<span style="color: #66cc66;">%-</span><span style="color: #cc66cc;">1</span>
   <span style="color: #66cc66;">&#41;</span>
   set <span style="color: #66cc66;">/</span>a mjour=<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">%</span>mjour<span style="color: #66cc66;">%+</span><span style="color: #cc66cc;">30</span><span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">%</span>nbhisto<span style="color: #66cc66;">%</span>
<span style="color: #66cc66;">&#41;</span>
<span style="color: #800080;">if</span> <span style="color: #66cc66;">%</span>mmois<span style="color: #66cc66;">%</span> LSS <span style="color: #cc66cc;">10</span> <span style="color: #66cc66;">&#40;</span> set mmois=<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">%</span>mmois<span style="color: #66cc66;">%</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #800080;">if</span> <span style="color: #66cc66;">%</span>mjour<span style="color: #66cc66;">%</span> LSS <span style="color: #cc66cc;">10</span> <span style="color: #66cc66;">&#40;</span> set mjour=<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">%</span>mjour<span style="color: #66cc66;">%</span><span style="color: #66cc66;">&#41;</span>
set delmax=<span style="color: #66cc66;">%</span>mannee<span style="color: #66cc66;">%%</span>mmois<span style="color: #66cc66;">%%</span>mjour<span style="color: #66cc66;">%</span>
REM <span style="color: #66cc66;">+-</span> <span style="color: #800080;">End</span> init    <span style="color: #66cc66;">-+</span>
&nbsp;
set destdir=c<span style="color: #FF1010; font-weight: bold;">:/db2_backup</span>
set db2backupdir=<span style="color: #66cc66;">%</span>destdir<span style="color: #66cc66;">%/</span>SAMPLE.0<span style="color: #66cc66;">/</span>DB2<span style="color: #66cc66;">/</span>NODE0000<span style="color: #66cc66;">/</span>CATN0000
&nbsp;
echo <span style="color: #ff0000;">&quot;DB2 Backup date=%mydate%&quot;</span>
db2cmd <span style="color: #66cc66;">/</span>c <span style="color: #66cc66;">/</span>w <span style="color: #66cc66;">/</span>i db2 <span style="color: #66cc66;">-</span>v <span style="color: #66cc66;">-</span>t <span style="color: #66cc66;">-</span>f<span style="color: #66cc66;">%</span>destdir<span style="color: #66cc66;">%/</span>sample_backup.db2 <span style="color: #66cc66;">-</span>z<span style="color: #66cc66;">%</span>destdir<span style="color: #66cc66;">%/</span>sample_backup.log
&nbsp;
<span style="color: #800080;">if</span> not <span style="color: #66cc66;">%</span>errorlevel<span style="color: #66cc66;">%</span> == <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#40;</span>
  echo <span style="color: #ff0000;">&quot;ERROR: Backup Error backupDB2, RC=%errorlevel% &quot;</span>
  <span style="color: #800080;">goto</span> fin
<span style="color: #66cc66;">&#41;</span>
&nbsp;
echo <span style="color: #ff0000;">&quot;Compress DB2 Backup file&quot;</span>
del <span style="color: #66cc66;">/</span>S <span style="color: #66cc66;">%</span>destdir<span style="color: #66cc66;">%/</span>db2_zip.jar
jar.exe <span style="color: #66cc66;">-</span>cvf <span style="color: #66cc66;">%</span>destdir<span style="color: #66cc66;">%/</span>db2_zip.jar <span style="color: #66cc66;">%</span>db2backupdir<span style="color: #66cc66;">%/%</span>mydate<span style="color: #66cc66;">%</span>
&nbsp;
<span style="color: #800080;">if</span> not <span style="color: #66cc66;">%</span>errorlevel<span style="color: #66cc66;">%</span> == <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#40;</span>
  echo <span style="color: #ff0000;">&quot;ERROR: Backup Error zipDB2, RC=%errorlevel% &quot;</span>
  <span style="color: #800080;">goto</span> fin
<span style="color: #66cc66;">&#41;</span>
&nbsp;
echo <span style="color: #ff0000;">&quot;DB2 delete catalogue Backup before %delmax%&quot;</span>
db2cmd <span style="color: #66cc66;">/</span>c <span style="color: #66cc66;">/</span>w <span style="color: #66cc66;">/</span>i db2 <span style="color: #66cc66;">-</span>v CONNECT <span style="color: #800080;">TO</span> sample
db2cmd <span style="color: #66cc66;">/</span>c <span style="color: #66cc66;">/</span>w <span style="color: #66cc66;">/</span>i db2 <span style="color: #66cc66;">-</span>v prune history <span style="color: #66cc66;">%</span>delmax<span style="color: #66cc66;">%</span> and delete
db2cmd <span style="color: #66cc66;">/</span>c <span style="color: #66cc66;">/</span>w <span style="color: #66cc66;">/</span>i db2 <span style="color: #66cc66;">-</span>v CONNECT RESET
db2cmd <span style="color: #66cc66;">/</span>c <span style="color: #66cc66;">/</span>w <span style="color: #66cc66;">/</span>i db2 <span style="color: #66cc66;">-</span>v <span style="color: #0000FF;">TERMINATE</span>
<span style="color: #800080;">if</span> not <span style="color: #66cc66;">%</span>errorlevel<span style="color: #66cc66;">%</span> == <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#40;</span>
  echo <span style="color: #ff0000;">&quot;ERROR: Backup Error, deleteDB2 RC=%errorlevel% &quot;</span>
  <span style="color: #800080;">goto</span> fin
<span style="color: #66cc66;">&#41;</span>
&nbsp;
echo <span style="color: #ff0000;">&quot;DB2 delete previos backup files (before %delmax%)&quot;</span>
<span style="color: #800080;">for</span> <span style="color: #66cc66;">/</span>f <span style="color: #ff0000;">&quot;skip=%nbhisto%&quot;</span> <span style="color: #66cc66;">%%</span>i <span style="color: #800080;">in</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'dir %db2backupdir% /b /o:-n'</span><span style="color: #66cc66;">&#41;</span> do <span style="color: #66cc66;">&#40;</span>
   rmdir <span style="color: #66cc66;">/</span>Q<span style="color: #66cc66;">/</span>S <span style="color: #66cc66;">%%</span>i
   <span style="color: #800080;">if</span> not <span style="color: #66cc66;">%</span>errorlevel<span style="color: #66cc66;">%</span> == <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#40;</span>
     echo <span style="color: #ff0000;">&quot;ERROR: Backup Error, deleteHisto  RC=%errorlevel% &quot;</span>
   <span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #FF1010; font-weight: bold;">:fin</span>
<span style="color: #800080;">if</span> <span style="color: #66cc66;">%</span>errorlevel<span style="color: #66cc66;">%</span> == <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#40;</span>
   echo <span style="color: #ff0000;">&quot; DB2 backup ok date=%mydate% &quot;</span>
<span style="color: #66cc66;">&#41;</span> <span style="color: #800080;">else</span> <span style="color: #66cc66;">&#40;</span>
   echo <span style="color: #ff0000;">&quot; Error in DB2 backup date=%mydate% &quot;</span>
<span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<h2 class="titre2">Remarques</h2>
<ul>
<li>I advise you, of course, to test this script in developpement environnement and mainly to try to test a restore procedure.</li>
<li>You can also make an <b>Online</b> database or tablespace backup but it&#8217;s more difficult (include log, rollforward,&#8230;) and if you are interested in that I write a new on this on the following weeks.
</ul>
<h2 class="titre2">Links</h2>
<p class="alertLink">
<a href="http://www.ibm.com/developerworks/db2/library/techarticle/0307fierros/0307fierros.html" target="_blank">Introduction to DB2 UDB Scripting on Windows</a><br />
<a href="http://www.hotline-pc.org/batchscripts.htm" target="_blank">Exemple de script batch windows</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.berthou.com/us/2008/01/10/windows-script-for-a-db2-backup/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
