Daniele Brunengo
asked on
Problem logging tar errors
Hello, so I've written a script in Centos cron to create daily backups of certain folders, using tar.
My problem is, I can't seem to have tar write errors to a log file.
This is the relevant command sequence:
I have tried renaming the Archive directory and running the script, the errors appear on the terminal but they don't get written to the log file. I only ever get the echoed strings in the log file.
I thought the 2>> would reroute all errors to the log file?
My problem is, I can't seem to have tar write errors to a log file.
This is the relevant command sequence:
echo "*** Backup data DOM" > /tmp/log/dom.log
tar -cvpj /home/Archive/ | split -d -b 10240m - /tmp/dom/dom.tar 2>> /tmp/log/dom.log
echo "*** Backup completed" >> /tmp/log/dom.log
I have tried renaming the Archive directory and running the script, the errors appear on the terminal but they don't get written to the log file. I only ever get the echoed strings in the log file.
I thought the 2>> would reroute all errors to the log file?
try
tar -cvpj /home/Archive/ | split -d -b 10240m - /tmp/dom/dom.tar 2>&1 >>/tmp/log/dom.log
assuming you are using bash as your script interpreter.
use
#!/bin/bash
at the 1st line of the script to enforce bash
tar -cvpj /home/Archive/ | split -d -b 10240m - /tmp/dom/dom.tar 2>&1 >>/tmp/log/dom.log
assuming you are using bash as your script interpreter.
use
#!/bin/bash
at the 1st line of the script to enforce bash
ASKER
Yes I use bash, I posted only the part of the script giving me trouble. andreas' version still gives the same result.
I will try to eliminate the split, see how it goes.
I will try to eliminate the split, see how it goes.
ASKER
Ok, getting rid of the split command moves the output to the log file, but:
It looks like tar is trying to output everything to the log file, including the compressed data.
bzip2: I won't write compressed data to a terminal.
bzip2: For help, type: `bzip2 --help'.
It looks like tar is trying to output everything to the log file, including the compressed data.
Try a subshell. Any difference?
(tar -cvpj /home/Archive) 2>> /tmp/log/dom.log
(tar -cvpj /home/Archive) 2>> /tmp/log/dom.log
ASKER
Looks like the biggest problem was the "-" sign in front of the options, forgot tar doesn't need it...
Now it works with tar, still have to try adding the split command back.
Now it works with tar, still have to try adding the split command back.
ASKER
This works:
If i factor split into it, there is no output to the log file, just to the terminal. I think tar outputs to the terminal and split outputs its null output to the log file.
tar cfvpj /tmp/gio/gio.tar /home/Archivio/ 2>> /tmp/log/gio.log
If i factor split into it, there is no output to the log file, just to the terminal. I think tar outputs to the terminal and split outputs its null output to the log file.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This one seems to work too:
It outputs errors to the log and creates the splitted archive. Have to test it a little bit more though.
It's similar to your second suggestion.
tar cfvpj - /home/Archive/ 2>> /tmp/log/dom.log | split -d -b 40MB - /tmp/dom/dom.tar
It outputs errors to the log and creates the splitted archive. Have to test it a little bit more though.
It's similar to your second suggestion.
Yes. You just have to do the error redirect before the pipe or use a subshell.
ASKER
Great. I'll test it a little bit more but it looks fine now. The script is quite bigger, mounts a nas folder, creates a daily backup (different folder per day of the week) and a daily log, then looks for errors in the logs with grep and mails them if any, then unmounts the nas folder.
tar -cvpj /home/Archive/ 2>> /tmp/log/dom.log