-1

I'm trying to log the output of the command:

innobackupex --incremental $INC1_BACKUP_FOLDER --incremental-basedir=$BASEDIR_FULL $SLAVE_INFO > $PATH_TO_LOG/log_inc1.txt 2>&1;

however it does not write to file rather prints on STDOUT.

This works and logs to file:

innobackupex $DB_USER_INFO $FULL_BACKUP_FOLDER $SLAVE_INFO > $PATH_TO_LOG/log_full.txt 2>&1;

however this does not log to file:

innobackupex --incremental $INC1_BACKUP_FOLDER --incremental-basedir=$BASEDIR_FULL $SLAVE_INFO > $PATH_TO_LOG/log_inc1.txt 2>&1;

the other solution I tried is:

open (INC1_RESULT,">$PATH_TO_LOG/log_inc1.txt");
my $incr1_backup_result = `innobackupex --incremental $INC1_BACKUP_FOLDER --incremental-basedir=$BASEDIR_FULL $SLAVE_INFO`;
print INC1_RESULT $incr1_backup_result;
close INC1_RESULT;

which did not work either because it will only write to the file after the command completes execution. I need to tail the log when the command is running.

ks_1010
  • 15
  • 1
  • 6
  • 2
    Are you sure it's not writing on STDERR instead? – Cfreak Dec 06 '12 at 19:49
  • Added shell & environment tags – psema4 Dec 06 '12 at 20:00
  • Added 2>&1 missing command. @Cfreak i'm not really sure. How do I find that out ? Sorry if it is a really basic question but kinda new to this. – ks_1010 Dec 06 '12 at 20:08
  • the problem i m facing is that this works perfectly `innobackupex $DB_USER_INFO $FULL_BACKUP_FOLDER $SLAVE_INFO > $PATH_TO_LOG/log_full.txt 2>&1`; however this does not, innobackupex --incremental $INC1_BACKUP_FOLDER --incremental-basedir=$BASEDIR_FULL $SLAVE_INFO > $PATH_TO_LOG/log_inc1.txt 2>&1; Googling for this did not help. – ks_1010 Dec 06 '12 at 20:35
  • You need to redirect both to the file. See @psema4's answer – Cfreak Dec 06 '12 at 21:46
  • Tried this too http://stackoverflow.com/a/758622/1397501, it still does not write to file. – ks_1010 Dec 07 '12 at 03:09

2 Answers2

2

Assuming bash in a *nix environment, try redirecting both stdout and stderr to the text file (note the ampersand):

innobackupex --incremental $INC1_BACKUP_FOLDER --incremental-basedir=$BASEDIR_FULL $SLAVE_INFO &> $PATH_TO_LOG/log_inc1.txt

More info in the Introduction to BASH Programming HOWTO. If you're in a different environment, check it's documentation on stream redirection.

--

According to the documentation:

Note that the STDERR of innobackupex is not written in any file. You will have to redirect it to a file, e.g., innobackupex OPTIONS 2> backupout.log.

Which redirects stderr to a file. OP notes (in comment below) that redirecting both stderr and stdout is not working as expected.

psema4
  • 3,007
  • 1
  • 17
  • 22
  • I tried your solution it still prints it to the output instead of printing to the file. – ks_1010 Dec 06 '12 at 22:01
  • I've been down this road before, it can get pretty frustrating I know. What's your environment look like? Are you using Bash on Linux? – psema4 Dec 06 '12 at 22:35
  • Just added a line I noticed in the documentation - can you try using 2> log_inc1.txt and see if it writes the file? – psema4 Dec 06 '12 at 22:47
  • Tried using 2> log_inc1.txt but still nothing in the log file. – ks_1010 Dec 06 '12 at 23:11
0

There, it should now do both i.e. print out to STDOUT and write to Log-

innobackupex --incremental $INC1_BACKUP_FOLDER --incremental-basedir=$BASEDIR_FULL $SLAVE_INFO | tee -a $PATH_TO_LOG/log_inc1.txt

Or just write to log

innobackupex --incremental $INC1_BACKUP_FOLDER --incremental-basedir=$BASEDIR_FULL $SLAVE_INFO >> $PATH_TO_LOG/log_inc1.txt
Anjan Biswas
  • 7,746
  • 5
  • 47
  • 77