Bacula-users

Re: [Bacula-users] Fileset generated by awk

2011-05-10 06:36:21
Subject: Re: [Bacula-users] Fileset generated by awk
From: Jérôme Blion <jerome.blion AT free DOT fr>
To: bacula-users AT lists.sourceforge DOT net
Date: Tue, 10 May 2011 12:33:02 +0200
Le 10/05/2011 11:56, Jérôme Blion a écrit :
Hello,

I have to backup machines which have been configured different ways for the same feature. In fact, I want to backup mysql binlogs on a hourly basis.
binlogs can be located at different locations:
 /home/mysql
 /usr/local/mysql/data
 /home/binlogs
Depending on the client.

If I use the following Fileset directive,

FileSet {
  Name = "Mysql Binlogs"
  Include {
    Options {
      signature = MD5
      wildfile = "*-bin.*"
    }
    Options {
      Regex = ".*"
      Exclude = yes
    }
    File = "/home/mysql"
    File = "/home/binlogs"
    File = "/usr/local/mysql/data"
  }
  Ignore Fileset Changes = yes
}

the backup log contains:

10-mai 05:17 tucana-dir JobId 117: Start Backup JobId 117, Job=Backup_aquila1_binlogs.2011-05-10_05.17.00_46
10-mai 05:17 tucana-dir JobId 117: Using Device "FileStorage"
10-mai 05:17 tucana-dir JobId 117: Sending Accurate information.
10-mai 05:17 aquila1-fd JobId 117:      Could not stat "/home/binlogs": ERR=No such file or directory
10-mai 05:17 aquila1-fd JobId 117:      Could not stat "/usr/local/mysql/data": ERR=No such file or directory
10-mai 05:17 tucana-sd JobId 117: Job write elapsed time = 00:00:03, Transfer rate = 5.502 M Bytes/second
10-mai 05:17 tucana-dir JobId 117: Bacula tucana-dir 5.0.2 (28Apr10): 10-mai-2011 05:17:06
  [...]
  Non-fatal FD errors:    2
  SD Errors:              0
  FD termination status:  OK
  SD termination status:  OK
  Termination:            Backup OK -- with warnings

I would like to tune my Fileset definition to avoid these non-fatal errors.
If I run the following command on the client, I'm sure to get the correct path to backup:

`awk '{ if($1 ~ /^log[-_]bin/ && NF==3) logfile=$3; else if($1 ~ /^datadir/) datadir=$3 } END { if (logfile != NULL) print "dirname " logfile; else print "echo " datadir }' /etc/mysql/my.cnf`

I created /tmp/binlogs.sh:

8<------
#!/bin/bash

`awk '{ if($1 ~ /^log[-_]bin/ && NF==3) logfile=$3; else if($1 ~ /^datadir/) datadir=$3 } END { if (logfile != NULL) print "dirname " logfile; else print "echo " datadir }' /etc/mysql/my.cnf`
------->8

If I set File = "\\| /tmp/binlogs.sh" the backup runs fine.
I would like to use the awk command directly in the Fileset directive.
Any time I use a backquote, the command fails and my backup does not work.

My last attempt was: File = "\\| bash -c \"`/usr/bin/awk '{ if(\$1 ~ /^log[-_]bin/ && NF==3) logfile=\$3; else if(\$1 ~ /^datadir/) datadir=\$3 } END { if (logfile != NULL) print \"dirname \" logfile; else print \"echo \" datadir }' /etc/mysql/my.cnf`\""
I tried with: File = "\\| bash -c \"\`/usr/bin/awk '/datadir/ {print \"echo \" \$3}' /etc/mysql/my.cnf\`\" " without success.

aquila1:~#  bash -c "`/usr/bin/awk '/datadir/ {print "echo " $3}' /etc/mysql/my.cnf`"
/home/mysql
aquila1:~# bash -c "`awk '{ if($1 ~ /^log[-_]bin/ && NF==3) logfile=$3; else if($1 ~ /^datadir/) datadir=$3 } END { if (logfile != NULL) print "dirname " logfile; else print "echo " datadir }' /etc/mysql/my.cnf`"
/home/mysql

10-mai 11:17 aquila1-fd JobId 149: Fatal error: Error running program: bash -c "`/usr/bin/awk '/datadir/ {print "echo " $3}' /etc/mysql/my.cnf`". stat=2: ERR=Child exited with code 2
10-mai 10:31 aquila1-fd JobId 144: Fatal error: Error running program: bash -c "`/usr/bin/awk '{ if($1 ~ /^log[-_]bin/ && NF==3) logfile=$3; else if($1 ~ /^datadir/) datadir=$3 } END { if (logfile != NULL) print "dirname " logfile; else print "echo " datadir }' /etc/mysql/my.cnf`". stat=2: ERR=Child exited with code 2

What could I try to perform what I want ?

Best regards.
Jerome Blion.

As usual, I found the solution just after sending this mail:

FileSet {
  Name = "Mysql Binlogs"
  Include {
    Options {
      signature = MD5
      wildfile = "*-bin.*"
    }
    Options {
      Regex = ".*"
      Exclude = yes
    }
    File = "\\| awk '{ if(\$1 ~ /^log[-_]bin/ && NF==3) lf=\$3; else if(\$1 ~ /^datadir/) dd=\$3 } END { if (lf != NULL) system(\"dirname \" lf); else system(\"echo \" dd) }' /etc/mysql/my.cnf"
  }
  Ignore Fileset Changes = yes
}

HTH.
Jérôme Blion.

------------------------------------------------------------------------------
Achieve unprecedented app performance and reliability
What every C/C++ and Fortran developer should know.
Learn how Intel has extended the reach of its next-generation tools
to help boost performance applications - inlcuding clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Bacula-users mailing list
Bacula-users AT lists.sourceforge DOT net
https://lists.sourceforge.net/lists/listinfo/bacula-users
<Prev in Thread] Current Thread [Next in Thread>