<?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>Le Vosgien du Net &#187; scripting</title>
	<atom:link href="http://levosgien.net/tag/scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://levosgien.net</link>
	<description>Parce que la vérité n'est pas toujours bonne à dire</description>
	<lastBuildDate>Thu, 11 Feb 2010 18:39:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Switch between versions of Firebird SQL Server</title>
		<link>http://levosgien.net/2009/12/01/switch-between-versions-of-firebird-sql-server/</link>
		<comments>http://levosgien.net/2009/12/01/switch-between-versions-of-firebird-sql-server/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 15:19:31 +0000</pubDate>
		<dc:creator>Pierre</dc:creator>
				<category><![CDATA[Geekitude]]></category>
		<category><![CDATA[Non classé]]></category>
		<category><![CDATA[firebird]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://levosgien.net/?p=172</guid>
		<description><![CDATA[	I wrote a little batch script to switch between versions of Firebird SQL Server nearly automatically.

The only one requirement is that all versions must be installed in C:\Program Files\Firebird\&#60;Version&#62; where  is Major.Minor version number of the Firebird Server you want to use.
	Eg : C:\Program Files\Firebird\1.5, C:\Program Files\Firebird\2.0, C:\Program Files\Firebird\2.1 ...
	Just copy the script in [...]]]></description>
			<content:encoded><![CDATA[	<p>I wrote a little batch script to switch between versions of <a href="http://www.firebirdsql.org">Firebird SQL Server</a> nearly automatically.<br />
<span id="more-172"></span><br />
The only one requirement is that all versions must be installed in <code>C:\Program Files\Firebird\&lt;Version&gt;</code> where <Version> is <code>Major.Minor</code> version number of the Firebird Server you want to use.</p>
	<p>Eg : <code>C:\Program Files\Firebird\1.5</code>, <code>C:\Program Files\Firebird\2.0</code>, <code>C:\Program Files\Firebird\2.1</code> ...</p>
	<p>Just copy the script in C:\Program Files\Firebird and start switching between versions of Firebird :</p>
	<p>C:\Program Files\Firebird\> switch 1.5<br />
C:\Program Files\Firebird\> switch 2.0<br />
...</p>
	<p>The code :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">@</span><span style="color: #7a0874; font-weight: bold;">echo</span> off
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #ff0000;">&quot;%OLD_PATH%&quot;</span> == <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>
  <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">OLD_PATH</span>=<span style="color: #000000; font-weight: bold;">%</span>PATH<span style="color: #000000; font-weight: bold;">%</span>
<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
setlocal
&nbsp;
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">FB_KEY</span>=HKLM\SOFTWARE\Firebird Project\Firebird Server\Instances
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">FB_VALUE</span>=DefaultInstance
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #000000; font-weight: bold;">/</span>F <span style="color: #ff0000;">&quot;skip=2 tokens=2*&quot;</span> <span style="color: #000000; font-weight: bold;">%%</span>A IN <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'reg query &quot;%FB_KEY%&quot; /v %FB_VALUE%'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>
  <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #000000; font-weight: bold;">/</span>F <span style="color: #ff0000;">&quot;delims=\ tokens=4&quot;</span> <span style="color: #000000; font-weight: bold;">%%</span>Y IN <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'echo %%B'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>
    <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">CURRENT_FB</span>=<span style="color: #000000; font-weight: bold;">%%</span>Y
  <span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">VERSION</span>=<span style="color: #000000; font-weight: bold;">%</span>1
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #ff0000;">&quot;%VERSION%&quot;</span> == <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> Syntax : <span style="color: #000000; font-weight: bold;">%</span>0 <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1.5</span> ^<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000;">2.0</span> ^<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000;">2.1</span> ^<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000;">2.5</span> ^<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000;">3.0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>Params <span style="color: #000000; font-weight: bold;">for</span> instsvc i^<span style="color: #7a0874; font-weight: bold;">&#40;</span>nstall^<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
  <span style="color: #000000; font-weight: bold;">if</span> not <span style="color: #000000; font-weight: bold;">%</span>CURRENT_FB<span style="color: #000000; font-weight: bold;">%</span> == <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>
    <span style="color: #000000; font-weight: bold;">if</span> exist <span style="color: #000000; font-weight: bold;">%</span>CURRENT_FB<span style="color: #000000; font-weight: bold;">%</span>\bin\instsvc.exe <span style="color: #7a0874; font-weight: bold;">&#40;</span>
      echo.
      <span style="color: #7a0874; font-weight: bold;">echo</span> Tip : These are the available options <span style="color: #000000; font-weight: bold;">for</span> instsvc from Firebird <span style="color: #000000; font-weight: bold;">%</span>CURRENT_FB<span style="color: #000000; font-weight: bold;">%</span>
      <span style="color: #000000; font-weight: bold;">%</span>CURRENT_FB<span style="color: #000000; font-weight: bold;">%</span>\bin\instsvc.exe
    <span style="color: #7a0874; font-weight: bold;">&#41;</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;">else</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>
  <span style="color: #000000; font-weight: bold;">if</span> not <span style="color: #ff0000;">&quot;%CURRENT_FB%&quot;</span> == <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> Unregistering Firebird <span style="color: #000000; font-weight: bold;">%</span>CURRENT_FB<span style="color: #000000; font-weight: bold;">%</span>
&nbsp;
    <span style="color: #7a0874; font-weight: bold;">pushd</span> <span style="color: #000000; font-weight: bold;">%</span>CURRENT_FB<span style="color: #000000; font-weight: bold;">%</span>\bin
    instclient r g
    instsvc stop
    instsvc r
    instreg r
    <span style="color: #7a0874; font-weight: bold;">popd</span>  
&nbsp;
    echo.
  <span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
  <span style="color: #7a0874; font-weight: bold;">echo</span> Registering Firebird <span style="color: #000000; font-weight: bold;">%</span>VERSION<span style="color: #000000; font-weight: bold;">%</span>
&nbsp;
  <span style="color: #7a0874; font-weight: bold;">pushd</span> <span style="color: #000000; font-weight: bold;">%</span>VERSION<span style="color: #000000; font-weight: bold;">%</span>\bin  
  instreg i <span style="color: #660033;">-z</span>
  instsvc i <span style="color: #000000; font-weight: bold;">%</span>2 <span style="color: #000000; font-weight: bold;">%</span>3 <span style="color: #000000; font-weight: bold;">%</span>4 <span style="color: #000000; font-weight: bold;">%</span>5 <span style="color: #000000; font-weight: bold;">%</span>6 <span style="color: #000000; font-weight: bold;">%</span>7 <span style="color: #000000; font-weight: bold;">%</span>8 <span style="color: #000000; font-weight: bold;">%</span>9
  instsvc start
  instclient i g
  <span style="color: #7a0874; font-weight: bold;">popd</span>
&nbsp;
  echo.
&nbsp;
  <span style="color: #7a0874; font-weight: bold;">echo</span> Defining System Path to search <span style="color: #000000; font-weight: bold;">in</span> Firebird <span style="color: #000000; font-weight: bold;">%</span>VERSION<span style="color: #000000; font-weight: bold;">%</span> tools and some useful environment variables
&nbsp;
  endlocal 
  <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">%</span>OLD_PATH<span style="color: #000000; font-weight: bold;">%</span>;<span style="color: #ff0000;">&quot;%CD%\%VERSION%\bin&quot;</span>
  <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">ISC_USER</span>=SYSDBA
  <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">ISC_PASSWORD</span>=masterkey
&nbsp;
  <span style="color: #7a0874; font-weight: bold;">echo</span> All Right <span style="color: #000000; font-weight: bold;">!</span>
<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

	<p>Hope this helps <img src='http://levosgien.net/wp/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>


 ]]></content:encoded>
			<wfw:commentRss>http://levosgien.net/2009/12/01/switch-between-versions-of-firebird-sql-server/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Firebird backup script</title>
		<link>http://levosgien.net/2008/09/25/firebird-backup-script/</link>
		<comments>http://levosgien.net/2008/09/25/firebird-backup-script/#comments</comments>
		<pubDate>Thu, 25 Sep 2008 09:29:59 +0000</pubDate>
		<dc:creator>Pierre</dc:creator>
				<category><![CDATA[Geekitude]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[firebird]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://levosgien.net/?p=123</guid>
		<description><![CDATA[	This is my first released backup script for Firebird RDBMS. It automagically search for all Firebird databases from a central directory, uses gfix to validate them, then backup + gzip them to a central backup directory keeping only 5 last successful backups.
	It may be used as a cron script to automate Firebird databases backup.


#!/usr/bin/env bash
#
# [...]]]></description>
			<content:encoded><![CDATA[	<p>This is my first released backup script for Firebird RDBMS. It automagically search for all Firebird databases from a central directory, uses gfix to validate them, then backup + gzip them to a central backup directory keeping only 5 last successful backups.</p>
	<p>It may be used as a cron script to automate Firebird databases backup.<br />
<span id="more-123"></span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/env bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#   Validate and Backup Firebird databases using Firebird</span>
<span style="color: #666666; font-style: italic;"># standard tools</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#   You can adjust FB_ROOT, FB_BIN, FB_DATA, Fb_BACKUP and </span>
<span style="color: #666666; font-style: italic;"># BACKUP_COUNT variables to fit your own requirements. </span>
<span style="color: #666666; font-style: italic;"># For instance, if you use an official package of Firebird for your</span>
<span style="color: #666666; font-style: italic;"># ditribution, you may have to change FB_ROOT to /usr/bin.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># The contents of this file are subject to the Initial </span>
<span style="color: #666666; font-style: italic;"># Developer's Public License Version 1.0 (the &quot;License&quot;); </span>
<span style="color: #666666; font-style: italic;"># you may not use this file except in compliance with the </span>
<span style="color: #666666; font-style: italic;"># License. You may obtain a copy of the License from</span>
<span style="color: #666666; font-style: italic;"># the Firebird Project website, at </span>
<span style="color: #666666; font-style: italic;"># http://www.firebirdsql.org/index.php?op=doc&amp;id=idpl.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Software distributed under the License is distributed </span>
<span style="color: #666666; font-style: italic;"># on an &quot;AS IS&quot; basis, WITHOUT WARRANTY OF ANY KIND, </span>
<span style="color: #666666; font-style: italic;"># either express or implied. See the License for the </span>
<span style="color: #666666; font-style: italic;"># specific language governing rights and limitations under </span>
<span style="color: #666666; font-style: italic;"># the License.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># The Original Code is licenced under IDPL</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># The Initial Developer of the Original Code is </span>
<span style="color: #666666; font-style: italic;">#   Pierre Yager (pierre@levosgien.net).</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Portions created by ______________________</span>
<span style="color: #666666; font-style: italic;"># are Copyright (C) ______ _________________.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># All Rights Reserved.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Contributor(s): _________________________.</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #007800;">FB_ROOT</span>=<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>firebird
<span style="color: #007800;">FB_BIN</span>=<span style="color: #800000;">${FB_ROOT}</span><span style="color: #000000; font-weight: bold;">/</span>bin
<span style="color: #007800;">FB_DATA</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>firebird
<span style="color: #007800;">FB_BACKUP</span>=backup
<span style="color: #007800;">BACKUP_COUNT</span>=<span style="color: #000000;">5</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># You shouldn't have to make any changes below</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">id</span> -u<span style="color: #000000; font-weight: bold;">`</span> = <span style="color: #000000;">0</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> You are not root...
  <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">67</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Loads the ISC_USER and ISC_PASSWORD environment variables</span>
<span style="color: #7a0874; font-weight: bold;">source</span> <span style="color: #800000;">${FB_ROOT}</span><span style="color: #000000; font-weight: bold;">/</span>SYSDBA.password
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> ISC_USER
<span style="color: #7a0874; font-weight: bold;">export</span> ISC_PASSWORD
&nbsp;
<span style="color: #666666; font-style: italic;">#  Returns the filename without extension, whatever the </span>
<span style="color: #666666; font-style: italic;">#+ extension is...</span>
<span style="color: #000000; font-weight: bold;">function</span> namename<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #007800;">name</span>=<span style="color: #800000;">${1##*/}</span>
  <span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #007800;">name0</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${name%.*}</span>&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${name0:-$name}</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Cleanup old backup files</span>
<span style="color: #000000; font-weight: bold;">function</span> cleanup<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #007800;">PREFIX</span>=$<span style="color: #000000;">1</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># list files by time in reverse order </span>
  <span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #007800;">FILES</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-rt</span> <span style="color: #800000;">${FB_BACKUP}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${PREFIX}</span><span style="color: #000000; font-weight: bold;">*</span>.fbk.gz<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
  <span style="color: #666666; font-style: italic;"># count the previous files list</span>
  <span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #007800;">FILES_COUNT</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-lrt</span> <span style="color: #800000;">${FB_BACKUP}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${PREFIX}</span><span style="color: #000000; font-weight: bold;">*</span>.fbk.gz <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">wc</span> -l<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$FILES_COUNT</span> <span style="color: #660033;">-gt</span> <span style="color: #007800;">$BACKUP_COUNT</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
  <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #666666; font-style: italic;"># Iterate the files list</span>
    <span style="color: #000000; font-weight: bold;">for</span> F <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$FILES</span>
    <span style="color: #000000; font-weight: bold;">do</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$FILES_COUNT</span> <span style="color: #660033;">-gt</span> <span style="color: #007800;">$BACKUP_COUNT</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
      <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #666666; font-style: italic;">#  And remove first files as soon as we have only </span>
        <span style="color: #666666; font-style: italic;">#+ BACKUP_COUNT files remaining</span>
        <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #007800;">$F</span>
        <span style="color: #007800;">FILES_COUNT</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>FILES_COUNT - <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;">else</span>
        <span style="color: #7a0874; font-weight: bold;">break</span>
      <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #000000; font-weight: bold;">done</span>
  <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Uses gfix to validates the database</span>
<span style="color: #000000; font-weight: bold;">function</span> validate<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #800000;">${FB_BIN}</span><span style="color: #000000; font-weight: bold;">/</span>gfix <span style="color: #660033;">-validate</span> <span style="color: #660033;">-full</span> $<span style="color: #000000;">1</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$?</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Uses gbak to backup the database then compress it...</span>
<span style="color: #000000; font-weight: bold;">function</span> backup<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #007800;">DIR</span>=<span style="color: #800000;">${1%/*}</span>
  <span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #007800;">DB</span>=<span style="color: #000000; font-weight: bold;">`</span>namename <span style="color: #007800;">$F</span><span style="color: #000000; font-weight: bold;">`</span>
  <span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #007800;">TS</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #ff0000;">&quot;%Y%m%d_%H%M%S&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
  <span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #007800;">BACKUP</span>=<span style="color: #800000;">${FB_BACKUP}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${DIR}</span>_<span style="color: #800000;">${DB}</span>_<span style="color: #800000;">${TS}</span>.fbk
  <span style="color: #800000;">${FB_BIN}</span><span style="color: #000000; font-weight: bold;">/</span>gbak <span style="color: #660033;">-b</span> $<span style="color: #000000;">1</span> <span style="color: #007800;">$BACKUP</span>
  <span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #007800;">$BACKUP</span>
  cleanup <span style="color: #800000;">${DIR}</span>_<span style="color: #800000;">${DB}</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">pushd</span> <span style="color: #800000;">${FB_DATA}</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-d</span> <span style="color: #800000;">${FB_BACKUP}</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #800000;">${FB_BACKUP}</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#  Avoid */*.fdb to be expanded if there are no files in the </span>
<span style="color: #666666; font-style: italic;">#+ databases repository</span>
<span style="color: #7a0874; font-weight: bold;">shopt</span> <span style="color: #660033;">-s</span> nullglob
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> F <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">*/*</span>.fdb
<span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">`</span>validate <span style="color: #007800;">$F</span><span style="color: #000000; font-weight: bold;">`</span> = <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
  <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #666666; font-style: italic;"># Only backup valid databases</span>
    backup <span style="color: #007800;">$F</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">#  Future enhancements : write a message to stderr so that</span>
    <span style="color: #666666; font-style: italic;">#+ cron can send a mail to the DBA when databases are not </span>
    <span style="color: #666666; font-style: italic;">#+ valid...</span>
  <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">popd</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null</pre></div></div>

	<p>Hope this will be useful. You can also <a href="http://levosgien.net/files/fb-backup.sh">download the script</a></p>

 ]]></content:encoded>
			<wfw:commentRss>http://levosgien.net/2008/09/25/firebird-backup-script/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
