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 |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
10-24-2007, 06:24 PM
|
#1
|
Member
Registered: Jan 2006
Location: France
Distribution: Debian Wheezy, Webmin + Virtualmin (remote dedi)
Posts: 214
Rep:
|
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.
|
|
|
10-24-2007, 06:57 PM
|
#2
|
Member
Registered: Dec 2002
Location: St Louis, MO
Distribution: Arch Linux
Posts: 99
Rep:
|
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
|
|
|
10-24-2007, 07:30 PM
|
#3
|
Member
Registered: Jan 2006
Distribution: Slackware Current
Posts: 272
Rep:
|
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..
|
|
|
10-25-2007, 03:11 AM
|
#4
|
Member
Registered: Jan 2006
Location: France
Distribution: Debian Wheezy, Webmin + Virtualmin (remote dedi)
Posts: 214
Original Poster
Rep:
|
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...
|
|
|
10-25-2007, 03:39 AM
|
#5
|
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
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.
|
|
|
10-25-2007, 03:57 AM
|
#6
|
Member
Registered: Oct 2006
Location: The Ether
Distribution: Ubuntu 16.04.7 LTS, Kali, MX Linux with i3WM
Posts: 299
Rep:
|
Thanks for the "-g" option hint jschiwal. A very useful tip indeed !!!!
|
|
|
11-04-2007, 06:57 AM
|
#7
|
Member
Registered: Jan 2006
Location: France
Distribution: Debian Wheezy, Webmin + Virtualmin (remote dedi)
Posts: 214
Original Poster
Rep:
|
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...
|
|
|
11-04-2007, 07:27 AM
|
#8
|
LQ Newbie
Registered: Sep 2007
Posts: 2
Rep:
|
How about
find . -print | grep -v ^\./test | xargs tar -cvf bak.tar
|
|
|
11-05-2007, 01:44 AM
|
#9
|
Member
Registered: Jan 2006
Location: France
Distribution: Debian Wheezy, Webmin + Virtualmin (remote dedi)
Posts: 214
Original Poster
Rep:
|
Quote:
Originally Posted by ptossy
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 
|
|
|
11-05-2007, 02:12 AM
|
#10
|
Senior Member
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039
Rep:
|
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.
|
|
|
11-05-2007, 02:24 AM
|
#11
|
Senior Member
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039
Rep:
|
Quote:
Originally Posted by ptossy
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.
|
|
|
All times are GMT -5. The time now is 02:04 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|