Solved

Problem logging tar errors

Posted on 2016-10-20
11
35 Views
Last Modified: 2016-10-21
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:

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

Open in new window


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?
0
Comment
Question by:Daniele Brunengo
  • 6
  • 4
11 Comments
 
LVL 20

Expert Comment

by:carlmd
ID: 41851784
Have you tried removing the split command and see if that works?

tar -cvpj /home/Archive/  2>> /tmp/log/dom.log
0
 
LVL 11

Expert Comment

by:andreas
ID: 41851786
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
0
 

Author Comment

by:Daniele Brunengo
ID: 41852545
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.
0
 

Author Comment

by:Daniele Brunengo
ID: 41852551
Ok, getting rid of the split command moves the output to the log file, but:

bzip2: I won't write compressed data to a terminal.
bzip2: For help, type: `bzip2 --help'.

Open in new window


It looks like tar is trying to output everything to the log file, including the compressed data.
0
 
LVL 20

Expert Comment

by:carlmd
ID: 41852605
Try a subshell. Any difference?

(tar -cvpj /home/Archive)  2>> /tmp/log/dom.log
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:Daniele Brunengo
ID: 41852681
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.
0
 

Author Comment

by:Daniele Brunengo
ID: 41852716
This works:
tar cfvpj /tmp/gio/gio.tar /home/Archivio/ 2>> /tmp/log/gio.log

Open in new window


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.
0
 
LVL 20

Accepted Solution

by:
carlmd earned 500 total points
ID: 41852721
One of these two should work.

(tar cvpj /home/Archive/ | split -d -b 10240m - /tmp/dom/dom.tar) 2>&1 >>/tmp/log/dom.log

or

(tar cvpj /home/Archive/ 2>&1 >>/tmp/log/dom.log) | split -d -b 10240m - /tmp/dom/dom.tar
0
 

Author Comment

by:Daniele Brunengo
ID: 41852736
This one seems to work too:

tar cfvpj - /home/Archive/ 2>> /tmp/log/dom.log | split -d -b 40MB - /tmp/dom/dom.tar

Open in new window


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.
0
 
LVL 20

Expert Comment

by:carlmd
ID: 41852740
Yes. You just have to do the error redirect before the pipe or use a subshell.
0
 

Author Comment

by:Daniele Brunengo
ID: 41852748
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.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now