LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-28-2013, 09:36 PM   #1
tommytomato
Member
 
Registered: Nov 2003
Location: Narrogin Western Australia
Distribution: GUI Ubuntu 14.0.4 - Server Ubuntu 14.04.5 LTS
Posts: 963

Rep: Reputation: 32
Question Backup Script


Hi all

It's been some years since I've created a back script

I've had to redo my home server to Ubuntu 12.04

Script I'm running is giving me a message
Code:
# ./www_backup.sh
tar: Removing leading `/' from member names
I'm simply at a lost here to what it means or how to fix

Back up seems to be in the folder I told it to go to.
any tips of help would be great

here's my script, written by some one else

Code:
TIME=`date +"%b-%d-%y"`            # This Command will add date in Backup File Name.
FILENAME="www_backup-$TIME.tar.gz" # Here i define Backup file name format.
SRCDIR="/var/www"                  # Location of Important Data Directory (Source of backup).
DESDIR="/root/.www_backup"         # Destination of backup file. 
tar -cpzf $DESDIR/$FILENAME $SRCDIR
cheers TT
 
Old 12-28-2013, 10:22 PM   #2
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,339

Rep: Reputation: Disabled
That's not an error message. tar's just telling you it doesn't store the leading "/" character in path names, which makes it (slightly) easier to restore a backup to an alternate location.
 
Old 12-28-2013, 10:38 PM   #3
tommytomato
Member
 
Registered: Nov 2003
Location: Narrogin Western Australia
Distribution: GUI Ubuntu 14.0.4 - Server Ubuntu 14.04.5 LTS
Posts: 963

Original Poster
Rep: Reputation: 32
Thank you for the meaning of it

I replace this line with
Code:
tar -cpzf $DESDIR/$FILENAME $SRCDIR
To

Code:
tar -cpPf $DESDIR/$FILENAME $SRCDIR
p = Preserving Files and Directory Permissions

Don't know if that's correct, but I get no errors when running the script from the command line

cheers TT
 
Old 12-28-2013, 10:52 PM   #4
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,339

Rep: Reputation: Disabled
Did you remove the "z" on purpose? Your backups are bound to take up a lot more space without compression.

The capital "P" option will indeed disable the function that usually strips leading slashes, hence removing the message. As for the message (which is not an error message), it will only appear if the $SRCDIR variable starts with a slash. This command would not produce any output at all:
Code:
bob@server:~# tar -czpf mybackup.tgz *
bob@server:~#
...while the following command backs up the same files using an absolute path (starting with a "/"), which triggers the tar function in question:
Code:
bob@server:~# tar -czpf mybackup.tgz /home/bob/*
tar: Removing leading `/' from member names
bob@server:~#
...and finally, with the "P" parameter all is silent again, but the archive will contain absolute paths with can't be restored to an alternate location without a workaround:
Code:
bob@server:~# tar -czpPf mybackup.tgz /home/bob/*
bob@server:~#
If you're running this script as a cron job and are getting tired of receiving mails from cron every time the job is run, adding "2> /dev/null" to the crontab entry is probably a better idea. A backup script should do its own error checking anyway.
 
Old 12-28-2013, 11:00 PM   #5
tommytomato
Member
 
Registered: Nov 2003
Location: Narrogin Western Australia
Distribution: GUI Ubuntu 14.0.4 - Server Ubuntu 14.04.5 LTS
Posts: 963

Original Poster
Rep: Reputation: 32
No I didn't must of been a type O

So your saying like so

Code:
10 * * * * /root/.www_backup/www_backup.sh 2> /dev/null
TT
 
Old 12-28-2013, 11:23 PM   #6
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,339

Rep: Reputation: Disabled
Yes, that should work. All messages to stderr will be sent to /dev/null, which means you'll get no notification e-mails about the removal of leading slashes.

You'll also get no e-mails should the tar command fail completely for some reason, so you may want to add some basic error checking to "www_backup.sh". Putting this right after the tar command doesn't really qualify as error handling, but it beats having nothing at all:
Code:
if [ ! "$?" == "0" ]; then echo %0: error: tar command failed ; fi
If the exit code from tar is not 0, a message gets sent to stdout which will trigger an e-mail notification from cron.

Last edited by Ser Olmy; 12-28-2013 at 11:24 PM.
 
Old 12-28-2013, 11:31 PM   #7
tommytomato
Member
 
Registered: Nov 2003
Location: Narrogin Western Australia
Distribution: GUI Ubuntu 14.0.4 - Server Ubuntu 14.04.5 LTS
Posts: 963

Original Poster
Rep: Reputation: 32
I did try that and still got the error message

Code:
Removing leading `/' from member names
So I tried this, NO error message now

Code:
tar -Pczf $DESDIR/$FILENAME $SRCDIR
I'm quiet new to these scripts, So I'm un sure if that's the correct format

Crontab is

Code:
02 13 * * 1,6 /root/www_backup.sh
will run at 01:01:00 at every Monday and Saturday

TT
 
Old 12-29-2013, 12:03 AM   #8
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,339

Rep: Reputation: Disabled
Adding "2> /dev/null" to the crontab line certainly gets rid of any notification e-mails sent due to messages sent to stderr. Are you using the crontab command to edit the crontab file?

There are a number of other ways to get rid of the message. Off the top of my head:
  • You could suppress the message from tar directly in the backup file by adding "2> /dev/null" to the end of the line:
    Code:
    tar -czpF $DESDIR/$FILENAME $SRCDIR 2>/dev/null
  • You could selectively filter the "Removing leading" message by running tar in a subshell:
    Code:
    ( tar -czpF $DESDIR/$FILENAME $SRCDIR 2>&1 ) | grep -v "Removing leading"
  • You could make tar cd into the source directory before the command is run, and use "." to back up everything:
    Code:
    tar -czpf $DESDIR/$FILENAME -C $SRCDIR .
Just use whatever method works for you, even the "-P" option, but do Google for the security implications of using "-P". Also, you won't be able to restore files to an alternate location without chroot'ing to that directory first.
 
Old 12-29-2013, 12:33 AM   #9
tommytomato
Member
 
Registered: Nov 2003
Location: Narrogin Western Australia
Distribution: GUI Ubuntu 14.0.4 - Server Ubuntu 14.04.5 LTS
Posts: 963

Original Poster
Rep: Reputation: 32
This one seems to work OK, thank you

Code:
tar -cpzf $DESDIR/$FILENAME $SRCDIR 2>/dev/null
TT
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What happens with backup-manager.org (very useful backup script)? Murz Linux - Software 3 07-27-2010 06:46 AM
Newbie trying to write a simple backup script to backup a single folder Nd for school stryker759a Linux - Newbie 2 09-16-2009 08:52 AM
Need help with script to organise files into folders as part of DVD backup script jasybee2000 Linux - Newbie 5 06-15-2009 07:29 PM
Backup Script shane25119 Linux - General 9 02-22-2009 09:51 PM
how to create backup MYSQL Script to backup my database for every 1hour RMLinux Linux - Newbie 3 11-20-2008 10:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration