ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Distribution: Debian Lenny 64-bit, Open Solaris, and CentOS
Posts: 559
Rep:
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?
"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"
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.