Bacula-users

Re: [Bacula-users] Making backups with FIFOs -- in theory

2008-10-30 09:51:45
Subject: Re: [Bacula-users] Making backups with FIFOs -- in theory
From: "Shad L. Lords" <slords AT lordsfam DOT net>
To: Arno Lehmann <al AT its-lehmann DOT de>
Date: Thu, 30 Oct 2008 07:48:25 -0600
Arno Lehmann wrote:
> 30.10.2008 04:47, Dan Langille wrote:
>> SZÉKELYI Szabolcs wrote:
>>> I understand the concept, but I have problems with timing. I did a small
>>> research on how FIFOs work. Consider the following script:
>>>
>>> ==
>>> #!/bin/bash
>>>
>>> exec > /dev/null
>>>
>>> mkfifo /tmp/tmpfifo
>>>
>>> (
>>>   for n in `seq 20`; do
>>>     echo $n >/tmp/tmpfifo
>>>     sleep 1
>>>   done
>>> ) &
>>> ==
>>>
>>> Let's use this script to generate the data to be backed up, so it is run
>>> from RunBeforeJob. Creates a FIFO, writes the numbers from 1 to 20 into
>>> it, with a 1 second delay between them.
> 
> You need to be aware that your loop does the following:
> 1. open the FIFO for writing
> 2. write into it
> 3. close the FIFO
> 4. sleep
> 5. loop
> 
> The important thing is that the FIFO is opened and closed for each write.
> 
> If, on the other hand, you opened the FIFO in the surrounding code, 
> redirected your output to it (for testing, do it similarly as you do 
> with 'exec > /dev/null') and closed the FIFO once the loop is done 
> you'll see your cat reads all the numbers in one go.
> 
> That's the difference.

This was going to be my point as well.  Take your example and change it 
to this and everything behaves as you expect:

#!/bin/bash

exec > /dev/null

mkfifo /tmp/tmpfifo

(
   for n in `seq 20`; do
     echo $n
     sleep 1
   done
) >/tmp/tmpfifo &



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Bacula-users mailing list
Bacula-users AT lists.sourceforge DOT net
https://lists.sourceforge.net/lists/listinfo/bacula-users