Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-01-2006, 08:09 PM   #1
Registered: Sep 2003
Location: Manchester UK
Posts: 264

Rep: Reputation: 30
Using TAR to backup /

Hi all,
I probably can't see the wood for the trees at the moment and I'm sure I've missed something, but I am trying to backup my / (i.e. everything) using TAR to an external HDD within a script.

I can get TAR to copy, but I can't seem to get the syntax correct when I am telling it to exclude certain dirs.

If I don't exclude the dir that the external HDD is mounted at, it will end up backing up my backup drive too.

tar -zcvpf /media/DWORKIN/ubuntu_backup-`date '+%d-%B-%Y'`.tar.gz
--exclude=/media --exclude=/proc .
Where DWORKIN is the external HDD.

Any attempt to exclude a directory fails, as when I watch the files go by (verbose output) it starts backing up /media/DWORKIN too.

It also doesn't work as --exclude=media. I've read the man page and "tar --help" but all it says it that
--exclude=PATTERN .............exclude files, given as a PATTERN
What it doesn't do is explain what the pattern of PATTERN is!

Also, googling didn't help in this instance.

Many thanks in advance,

Last edited by morrolan; 01-01-2006 at 08:10 PM.
Old 01-01-2006, 09:03 PM   #2
Registered: Apr 2002
Location: The next brick house on the right.
Distribution: Kubuntu 18.04, Bodhi 5.0
Posts: 691

Rep: Reputation: 45
What you have right now for your exclude phrase is:
--exclude=/media --exclude=/proc
I'm thinking that the file name pattern should be:
--exclude=/media/* --exclude=/proc/*
While it's true that a directory is sort of a file, the actual files that the PATTERN looks for is files within a directory. I think that by adding something to indicate files, all in this case, within a directory that are to be excluded, you should have better luck.
Old 01-01-2006, 10:42 PM   #3
LQ Newbie
Registered: Jan 2003
Posts: 1

Rep: Reputation: 0
Strange - works for me using tar 1.15.1 (simple test example):

$ cd /tmp/testdir
$ ls
dir1 dir2 dir3
$ tar -zcvpf dir3/dirs.tar.gz --exclude=dir2 --exclude=dir3 .

Are you sure that your /media/DWORKIN is not symlinked from somewhere else under / ?


Old 01-02-2006, 01:09 AM   #4
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
Not to change the subject, but dar works great for that kind of thing. The settings seem very user-friendly and I've been using it successfully for a while now. Anyway, tar should work fine, but dar seems to be a better system for major system-wide backups like that.
Old 01-02-2006, 04:08 AM   #5
LQ Newbie
Registered: Jul 2004
Location: Australia
Distribution: Kubuntu 5.10
Posts: 3

Rep: Reputation: 0
I have been using ESR backup quite sucessfully for backup of 4 computers to a remote HDD. It is very easy to setup and my be what your looking for. Works for one or many computers!

Last edited by grishnak; 01-02-2006 at 04:14 AM.
Old 01-02-2006, 04:14 AM   #6
Registered: Jan 2003
Posts: 56

Rep: Reputation: 15
My advice is don't bother with tar.

Use rsync if you're simply mirroring a drive, and dar as your solution if you want to back up compressed image files (BTW, this backs up files individually within a volume, so one disk error means ONE problem file, not a stack of them). I do both regularly (rsync every couple of days, dar monthly), and once I got the setup debugged, I haven't had problems.

For details, go to my article:

In fact, my backup methods as described will even automatically back up the /boot partition. Not an issue for most people, but if you have had occasion to make changes, you'll appreciate this. I say methods because it'll walk you through both rsync to a drive mirror and dar to a stack of DVD-Rs.
Old 01-02-2006, 05:02 AM   #7
LQ Newbie
Registered: Jul 2004
Location: Berlin, Germany
Distribution: Fedora Core, RedHat, Debian
Posts: 1

Rep: Reputation: 0
You need to write '--exclude=./media/*' '--exclude=./proc/*'
because tar backs up ".", so the pathes it sees are


and so on.

I would also recommend to exclude

/dev/pts/* (pseudo terminal devices),
/dev/shm/* (shared-memory based RAM disk)
/sys/* (sysfs, a bit like /proc).

Old 01-03-2006, 03:44 PM   #8
Registered: Jan 2002
Location: Anchorage, AK
Distribution: Gentoo, Ubuntu and Slackware
Posts: 38

Rep: Reputation: 15
You could also create a file somewhere on your machine called "backup.excludes", which contains "/proc", "/dev", or whatever you want to exclude, and then use the flag "--exclude-from /somedir/backup.excludes". I've been successful with that syntax, even though, like you, I've never had any luck using "--exclude".
Old 01-04-2006, 06:03 AM   #9
Registered: Sep 2003
Location: Manchester UK
Posts: 264

Original Poster
Rep: Reputation: 30
I've resolved it now, it turns out I was missing the "/" to tell it to backup the root directory - I placed a / after the filename and before the excludes and it worked fine.

Many Thanks all - I will be looking into RSYNC now, but the backup was a matter of urgency and I didn't have time to look into another program in the timeframe, hence why I used 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

Similar Threads
Thread Thread Starter Forum Replies Last Post
backup: tar with the -L option help Paxmaster Linux - Software 1 11-18-2005 08:06 PM
Tar backup TheRealDeal Linux - General 7 02-08-2005 04:25 PM
Using tar for backup. TheRealDeal Linux - General 2 08-11-2004 12:46 AM
tar as backup imsajjadali Red Hat 4 02-07-2004 04:46 PM
tar: How do I backup everything !! grantm Linux - Newbie 3 07-30-2003 03:41 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:05 PM.

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