LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 10-18-2011, 12:11 PM   #1
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Rep: Reputation: 60
Tar using include-file and exclude file one liner?


Can someone show me an example of using tar to backup a directories and files using an include-file and exclude-file together in a one liner? So basically backup these files and exclude So for example:

Code:
cat include.mydirs

/home/testuser/Documents/paths.exchange
/home/testuser/Documents/report.pdf
/home/testuser/Documents
/home/testuser/lf5/mru_file_manager
/home/testuser/lf5
/home/testuser/brookshire
/home/testuser/
Code:
cat exclude.mydirs
/home/testuser/.*
/home/testuser/Downloads*
/home/testuser/Pictures*
Code:
tar czXf /home/testuser/exclude.mydirs backup.dirs.tgz `/bin/cat /home/testuser/include.mydirs`
or

Code:
tar -zcvf backup.dirs.tar.gz -X exclude.mydirs `/bin/cat /home/testuser/include.mydirs`
??

Last edited by metallica1973; 10-18-2011 at 03:33 PM.
 
Old 10-18-2011, 01:07 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Here we go:
Code:
tar zcf backup.dirs.tgz --files-from=include.mydirs --exclude-from=exclude.mydirs --no-recursion
Don't forget the --no-recursion option at the end.

Last edited by colucix; 10-18-2011 at 01:08 PM.
 
Old 10-18-2011, 03:18 PM   #3
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
too easy. Many thanks

Last edited by metallica1973; 10-18-2011 at 03:32 PM.
 
Old 10-18-2011, 03:32 PM   #4
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
Many thanks

one more question. when I run the tar command I get this in the beginning:

Code:
tar: Removing leading `/' from member names
and at the end when it finishes but it works fine:

Code:
tar: Exiting with failure status due to previous errors
.Just curious when I see erorrs. It appears to strip the "/" from the file when reading include.mydirs

any ideas ??
 
Old 10-18-2011, 08:04 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Try adding the -v (verbose ) flag to help see error msgs.
The default for tar is to remove leading '/', so that tarball contents are relocatable on restore.
You can prevent that
Quote:
-P, --absolute-names
don't strip leading '/'s from file names
http://linux.die.net/man/1/tar
 
Old 10-20-2011, 02:25 PM   #6
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
Awesome, Many thanks
 
  


Reply



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
how to tar file with exclude a directory elainelaw Linux - Newbie 1 03-02-2010 10:15 PM
Exclude file types in smbclient tar UltramaticOrange Linux - Networking 1 04-09-2006 04:11 PM
TAR: Unpack file, exclude a folder Smeerbalg Linux - Software 1 01-29-2006 07:59 AM
tar.gz file did not include install file |Spec-ops Linux - Newbie 12 11-17-2005 08:25 AM
tar --exclude-from=FILE GATTACA Programming 1 07-29-2005 12:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:29 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