Showing posts with label TAR. Show all posts
Showing posts with label TAR. Show all posts

Exclude a Sub-directory in Tar Command

To backup the directory /home/ to file /backups/home.tgz, and exclude /home/apachelog/ :


# cd /home
# tar czvf /backups/home.tgz –exclude apachelog/ *


(double ‘-’)
It may take a while, make it background:

# tar czf /backups/home.tgz –exclude apachelog/ * &

 if you have to exclude more than one dir.........then create a file called file.txt

and enlist the dirs with the path.
for ex.


#mkdir test
#mkdir test/test1
#mkdir test/test2
#mkdir test/test3


Now Suppose you want to exclude  test1 & test2 dirs..then
#vi file
test/test1
test/test2


save & exit
Now use tar as ...


# tar cvf xyz.tar.gz -X file test


where -X file is the listed dir from file and test is the tar destination to be created after excluding dirs .


have a nice taring........

Exclude Certain Files When Creating A Tarball Using Tar Command




How can I keep out certain files when creating a tarball? For example:
/home/me/file1
/home/me/dir1
/home/me/dir2
/home/me/abc
/home/me/xyz
How do I execute zyz and abc file while using a tar command?

The GNU version of the tar archiving utility has --exclude and -X options. So to exclude abc and xyz file you need to type the command as follows:
$ tar -zcvf /tmp/mybackup.tar.gz --exclude='abc' --exclude='xyz' /home/me
If you have more than 2 files use -X option to specify multiple file names. It reads list of exclude file names from a text file. For example create a file called exclude.txt:
$ vi exclude.txtAppend file names:
abc
xyz
*.bak

Save and close the file. This lists the file patterns that need to be excluded. Now type the command:
$ tar -zcvf /tmp/mybackup.tar.gz -X exclude.txt /home/me
Where,
  • -X file.txt :exclude files matching patterns listed in FILE file.txt