How can I create Ant TarTask for this tar command?
tar zcvf Test.tar.gz / var / trac / test / var / svn / test
So far I have:
<target name="archive" depends="init">
<tar compression="gzip" destfile="test.tar.gz">
<tarfileset dir="/">
<include name="/var/trac/test" />
</tarfileset>
<tarfileset dir="/">
<include name="/var/trac/svn" />
</tarfileset>
</tar>
</target>
When debugging, it always says "No sources", so I am a bit confused about what to do next.
source to share
There are a few things that can go wrong here:
-
Are files or directories
/var/trac/test
and/var/svn/test
? The real onetar
will work great with both; your task is the way it's written right now, will only work with files, not folders. -
Do you (or rather the Ant process) have the appropriate permissions?
The elements -
<include>
contain patterns that are usually relative to the base dir. You specify them as absolute.
I would rewrite the above as:
<target name="archive" depends="init">
<tar compression="gzip" destfile="test.tar.gz">
<tarfileset dir="/var/trac" prefix="/var/trac">
<include name="test/**" />
<include name="svn/**" />
</tarfileset>
</tar>
</target>
prefix
allows you to explicitly specify the path from which the files in the Tar archive should begin.
/**
inside <include>
tells Ant to take all files from this folder and all its subfolders. If /var/trac/test
and /var/svn/test
are indeed files, not folders, you can omit it.
source to share