LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 02-18-2010, 04:18 PM   #1
worm5252
Member
 
Registered: Oct 2004
Location: Atlanta
Distribution: Debian Lenny 64-bit, Open Solaris, and CentOS
Posts: 559

Rep: Reputation: 57
Question BASH - tar --exclude not working


Hey guys, I wrote this script up a while back to do a full backup of my HOME directory. However there are certain sub-directories and hidden files I do not want to include in the back up. for example I do not want to include my virtual machines I use in vmware as I have a separate backup to get those.

Here is my Script
Code:
#!/bin/bash
#
# This script is designed to backup a users home directory
#

# Set script global variables
SRCDIR="/home/`whoami`"
ARCHIVE="`hostname`-`whoami`-`date +%F`.`date +%H%M`.tar.bz2"
#BACKUP="files/"
STORE="/mnt/nfs/File_Store/Backups"
EXCLUDE="$ARCHIVE,.vm,.vm/*,Music,Music/*,tmp,tmp/*,Downloads,Downloads/,.adobe,.adobe/*,.azureus,.azureus/*,.cache,.cache/*,.dmrc,.dmrc/*,.dvdrip,.dvdrip/*,.dvdcss,.dvdcss/*,.DCOPserver_Sarah__0,.dvdriprc,.ICEauthority,.macromedia,.macromedia/*,.mcop,.mcop/*,.mcoprc,.mplayer,.mplayer/*,.qt,.qt/*,.recently-used,.recently-used.xbel,.themes,.thumbnails,.VirtualBox,.VirtualBox/*,.themes/*,.thumbnails/*,.vlc,.vlc/*,.w3m,.w3m/*,.Xauthority,.xchat2,.xchat2/*,.xfe,.xfe/*,.xscreensaver,.xsession-errors"

# Change to users home directory and backup files
cd $SRCDIR
tar cpjP --file=$ARCHIVE $SRCDIR --exclude={$EXCLUDE}
mv $ARCHIVE $STORE

# Delete old backups and save the last 3 backups
touch backuplist.lst

ls -r1 $STORE/$(hostname)* | sed '1,4d' >>backuplist.lst

cat backuplist.lst | while read line ; do
        rm $line
done

rm backuplist.lst
The problem is when the tar command is executed, it is not excluding the specified files and folders. I don't understand why. Can someone explain to me why it is not excluding the listed files and folders?
 
Old 02-18-2010, 04:29 PM   #2
mattca
Member
 
Registered: Jan 2009
Distribution: slackware + ratpoison
Posts: 253

Rep: Reputation: 41
Not really familiar with the --exclude option, but some I found some info via google that may be helpful.

Try putting the --exclude option at the beginning of the command.
http://ubuntuforums.org/showthread.php?t=147501

Also check these links out, they may be helpful:
http://sunsite.ualberta.ca/Documenta...r_6.html#SEC97
http://sunsite.ualberta.ca/Documenta...r_6.html#SEC98
 
Old 02-18-2010, 06:04 PM   #3
worm5252
Member
 
Registered: Oct 2004
Location: Atlanta
Distribution: Debian Lenny 64-bit, Open Solaris, and CentOS
Posts: 559

Original Poster
Rep: Reputation: 57
Thanks for the Reply.
Quote:
Originally Posted by mattca View Post
Try putting the --exclude option at the beginning of the command.
http://ubuntuforums.org/showthread.php?t=147501
I will look into that.

Quote:
Originally Posted by mattca View Post
I have read those before. I read em when I was trying to figure this out on my own.

Think I will tinker with this as you have helped me see a problem with my tar command. I have
Code:
tar cpjP --file=$ARCHIVE $SRCDIR --exclude={$EXCLUDE}
I need to list $SRCDIR after the --exclude statement. Like this
Code:
tar cpjP --file=$ARCHIVE --exclude={$EXCLUDE} $SRCDIR
 
Old 02-18-2010, 06:10 PM   #4
raconteur
Member
 
Registered: Dec 2007
Location: Slightly left of center
Distribution: slackware
Posts: 276
Blog Entries: 2

Rep: Reputation: 43
It appears that the exclusion parameter should be a shell globbing expression pattern. I don't think a comma-delimited list will match.

This article has more info (search for exclude).

Of particular note in that article:

"use ‘--exclude’ when files to be excluded are given as a pattern on the command line. Use ‘--exclude-from’ to introduce the name of a file which contains a list of patterns, one per line; each of these patterns can exclude zero, one, or many files"

hth

Last edited by raconteur; 02-18-2010 at 06:12 PM.
 
  


Reply

Tags
exclude, tar


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
tar exclude HELP BassKozz Linux - Newbie 1 06-03-2009 03:41 AM
tar --exclude-from=files command not working cucolin@ Linux - Server 2 04-03-2007 09:33 PM
tar exclude from not working noir911 Linux - Software 5 08-05-2006 07:05 PM
tar --exclude --exclude-from cefn Linux - Software 4 10-11-2005 07:31 PM
tar exclude-from drisay Slackware 1 12-23-2004 01:10 PM


All times are GMT -5. The time now is 11:17 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration