Dynamic exclusion list in lsyncd

Our cloud platform is powered by opennebula. So we have two instances of the frontend in “cold swap”. We use lsyncd daemon trying to keep instances in datastores synced, but there are some points: we don’t want to sync VM’s images that have an extension .bak cause of the other script moves all the .bak to other storage on schedule. The sync script logic looks like find all the .bak in /var/lib/one/datastores/ then create exclude.lst and then start lsyncd. Seems OK until we take a look at the datastores:

oneadmin@nola:~/cluster$ dir /var/lib/one/datastores/1/

…and so on.

We solved it with this monstrous function:

function create_exclude {
oneimage list -x |
xmlstarlet sel -t -m “IMAGE_POOL/IMAGE” -v “ID” -o “;” -v “NAME” -o “;” -v “SOURCE” -o “:” |
sed s/:/’\n’/g |
awk -F";" ‘/.bak;/var/lib/ {print $3}’ |
cut -d / -f8 > /var/lib/one/cluster/exclude.lst

The result is the list which contains VM IDs with .bak images inside so we can exclude the whole VM folder from syncing. That’s not kinda what we wanted, as the original image stays not synced. But it could be solved by restart the lsyncd script at the moment when other script moves all the .bak to other storage.

Now we get to the topic of the question.

It works until a new .bak will created. No way to add new string in exclude.lst “on the go” but to stop lsync and restart script which re-creates exclude.lst. But there is also no possibility to check the moment of creation a new .bak except another script that will monitor it in some period.

I believe that less complicated solution exists. It depends on opennebula of course, particularly in the way of the /datastores/ folder stores VMs.