Le 06/05/2011 18:05, no-re...@cfengine.com a écrit :
> Forum: Cfengine Help Subject: Re: Running a command just once. 
> Author: jeromebaum Link to topic:
> https://cfengine.com/forum/read.php?3,21797,21800#msg-21800
> 
> Was just working on a config today. Part of it was "create a database
> w/ its tables, add some stored procedures, import a development
> snapshot dump" but only if this wasn't already done (obviously). How
> do you do that in a convergent fashion?
> 
> So:
> 
> 
> 1. Create database 2. Import schema 3. Import stored procedures 4.
> Import a dump
> 
> 
> All of these only if necessary. I can see handling #1 -- just check
> if the database exists. #2 dito, #3 would be a bit more hard but I
> guess dito. #4 is the troublesome thing. How do I know if "the dump
> has been imported" in a clean fashion? Check if there is "some data"
> in the DB? What if it was partially applied? etc.
> 
> I think using a flag file sounds fine. Yes, if it's deleted then
> re-running the script should bring it back to an expected state, not
> break it. But yes, the flag file sounds good to prevent starting a
> long-running script, or something.
> 
> What's your take? Is cfengine the wrong tool to import the dump?
> This, btw, is for provisioning a devel workstation.

I have come across this requirement before - in my case restoring data
from backups if the database "seems" empty. An approach discussed at
FOSDEM was to test the "freshness" of your data.

The simple case is the initial one: if the database is completely empty
then load dump. However, lots of software initializes it's database on
first run if it's empty... not a very reliable test (no more than the
flag file in fact).

The harder case is how to tell whether you should restore your dump, or
keep the data in the database. The "freshness" approach is based on
measuring some indicator in the dump and in the database, ie the highest
value of a "last modified" field in some table, or the max value of an
auto-increment ID. If the dump is "fresher" than the database, then
restore. If not, consider you're already in the desired state.

This is a bit of a twist on defining the desired state - Cfengine
usually encourages defining "desired-state == A", but here we want
"desired-state >= A".

Jonathan

-- 
--------------------------------------------------------------
Jonathan Clarke - jonat...@phillipoux.net
--------------------------------------------------------------
Ldap Synchronization Connector (LSC) - http://lsc-project.org
--------------------------------------------------------------
_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to