LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 10-24-2007, 06:24 PM   #1
Sabinou
Member
 
Registered: Jan 2006
Location: France
Distribution: Debian Wheezy, Webmin + Virtualmin (remote dedi)
Posts: 214

Rep: Reputation: 30
Silly problems with "tar" in commandline...


Hello there

I am a bit ashamed to ask such a question after five years I switched to linux, but I remained globally hostile to command line mode unless I couldn't avoid it...

And here, I need to have a command line function work, and I don't manage to have a parameter understood.
I will be grateful if you help

The command is very simple, it's tar. I can log into my server's storage with ssh and then backup everything, file permissions and all, it's the best for a backup. But I don't manage to exclude a precise folder

Quote:
tar -cvf bak20071024.tar *
This one works. But I don't find how I can have a correct syntax to exclude a folder called "test"

I saw two possibilites with tar's manual :

Code:
   --exclude=PATTERN
              exclude files matching PATTERN

   -X, --exclude-from=FILE
              exclude files matching patterns listed in FILE
But here I don't want to exlude all files whose names contain "test", only the folder called like that...

Do you see how I could write that tar command line to add to my archive everything but the "test" folder ?
Thanks a lot if you can help me !

Last edited by Sabinou; 10-24-2007 at 06:27 PM.
 
Old 10-24-2007, 06:57 PM   #2
docalton
Member
 
Registered: Dec 2002
Location: St Louis, MO
Distribution: Arch Linux
Posts: 99

Rep: Reputation: 15
You are on the right track.

tar -cvf bak20071024.tar * --exclude=test

That should work. I would keep an eye on it or perhaps redirect the output to a file so you can take a look at the contents to make sure you are not missing anything important.

Hope this helps
 
Old 10-24-2007, 07:30 PM   #3
davimint
Member
 
Registered: Jan 2006
Distribution: Slackware Current
Posts: 272

Rep: Reputation: 33
Just for kicks I had to try that..
This worked fine on my home directory and excluding the BL directory

Code:
tar --exclude=BL -cvf mybackup.tar /home/david/
Hope that helps..
 
Old 10-25-2007, 03:11 AM   #4
Sabinou
Member
 
Registered: Jan 2006
Location: France
Distribution: Debian Wheezy, Webmin + Virtualmin (remote dedi)
Posts: 214

Original Poster
Rep: Reputation: 30
Thank you guys, I appreciate it

However, I just saw that the default tar option, even without exclusion, didn't fully work ?!?

After tar-ing about one third of the files and folders, the list of the archived elements is replaced with a list of the bugged elements...

The ssh-server message is :
tar: tell_a_friend.php: ne peut stat: Aucun fichier ou ré�pertoire de ce type

you could transated as :
tar: tell_a_friend.php: can't stat: no such file or folder

Do you have any idea why that problem occured ? I am puzzled...
 
Old 10-25-2007, 03:39 AM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 681Reputation: 681Reputation: 681Reputation: 681Reputation: 681Reputation: 681
You are probably backing up a live system. The file may have been removed before it could be backed up, or you tried to follow a dead link. Or you could have a correct directory (a file from the kernels point of view).

I don't know which directories you are trying to backup. Backing up the root directory without excluding /tmp, /dev, /tmp and other directories may not be the best idea.

I'm not certain, but if you use the -g <snapshot-file> option when creating an archive, it may ignore files that were altered after the start of the tar job. See section 5.2 of the info manual for examples of using snapshot files and incremental backups.

Last edited by jschiwal; 10-25-2007 at 03:40 AM.
 
Old 10-25-2007, 03:57 AM   #6
uncle-c
Member
 
Registered: Oct 2006
Location: The Ether
Distribution: Ubuntu 16.04.7 LTS, Kali, MX Linux with i3WM
Posts: 299

Rep: Reputation: 30
Thanks for the "-g" option hint jschiwal. A very useful tip indeed !!!!
 
Old 11-04-2007, 06:57 AM   #7
Sabinou
Member
 
Registered: Jan 2006
Location: France
Distribution: Debian Wheezy, Webmin + Virtualmin (remote dedi)
Posts: 214

Original Poster
Rep: Reputation: 30
And thanks too for the kind help

As for me, this is indeed to save the files from a live server (in mutualized [or should I say "shared", in english ?] hosting, so fortunately there is no filesystem to save, it's only that it's possible that cache, cookies and session files might differ from the beginning to the end of the archiving.
I'm saving everything in www/*

I made tests, and the bug only occurs when i try to exlude things from the archiving, I simply gave up on the exclusion.

However, I just only saw that tar -cvf bak.tar * does NOT save .htaccess files for me o.O
Would you guys imagine why ?

The options for the tar never spoke about ignoring or not ignoring hidden files... I am troubled...
 
Old 11-04-2007, 07:27 AM   #8
ptossy
LQ Newbie
 
Registered: Sep 2007
Posts: 2

Rep: Reputation: 0
How about
find . -print | grep -v ^\./test | xargs tar -cvf bak.tar
 
Old 11-05-2007, 01:44 AM   #9
Sabinou
Member
 
Registered: Jan 2006
Location: France
Distribution: Debian Wheezy, Webmin + Virtualmin (remote dedi)
Posts: 214

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by ptossy View Post
How about
find . -print | grep -v ^\./test | xargs tar -cvf bak.tar
That generated an archive 20 times bigger than the norm containing several du plicates of ALL files on the server, I guess that didn't work as planned
 
Old 11-05-2007, 02:12 AM   #10
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
Your problem is with the use of *

if you try:
Code:
tar cvf testing.tar ./ --exclude test
This will tar all files starting with current directory (including hidden files) excluding any files or folders called "test"

This will error on testing.tar as this is the backup file and would be created in the directory that it is backing up, however it will do everything else that you requested.
 
Old 11-05-2007, 02:24 AM   #11
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
Quote:
Originally Posted by ptossy View Post
How about
find . -print | grep -v ^\./test | xargs tar -cvf bak.tar
This causes duplicates because it is passing the directories as well as the contents of the directories.

You could use the '-type d' option to just pass directories but then you would still have subdirectories being passed (hence duplicates), the best that you could do is have it find only files '-type f', but not sure how this would handle named pipes and symbolic links.

Also, why bother? seems an extreeme measure to pass info into tar in this way.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Usage of "k size" option in "tar" ?? kcarun Solaris / OpenSolaris 4 08-20-2007 02:59 PM
how do you install programs extracted from "tar.gz", "bz2", etc? shoelessworm Ubuntu 13 04-12-2006 02:24 PM
How to "cp" or "rm" or "tar" all the files except a certain file? cqmyg5 Slackware 7 04-07-2006 02:45 PM
"&" after a command in commandline faezeh Fedora 3 05-07-2005 10:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:24 AM.

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