ant sync task deletes the directory mentioned to preserve - ant

I want to preserve the ".git" directory with all of it's content while executing synk ant task, but it deletes the content of .git directory.
<sync todir="${local.git.dir}" includeEmptyDirs="true">
<fileset dir="${img.dir}"/>
<preserveintarget>
<include name=".git"/>
</preserveintarget>
</sync>
Why according to this syntax, synk deletes the content of the .git directory?
This synk task should copy the file f1 (dir="${img.dir}") into the directory dir1 (todir="${local.git.dir}"); dir1 contains the directory .git.
Synk task doesn't delete the content of the .git directory only if I mention to put the file f1 into the directory dir1/target. In this case I will have this structure:
dir1 contains the directories: .git and target
the file f1 is copied into the target directory (which I don't want)
I want dir1 to contain .git and f1.

I found the problem. I didn't specified to preserve the files in the .git.
By appending /** to .git I resolved the problem: <include name=".git/**"/> instead of <include name=".git"/>

Related

Tar does not exclude

I use
tar hczf t.tar.gz * --exclude="./test1"
where test1 is the name of a directory to exclude files from being tarred.
Unfortunately, tar still includes those directories. How can I have tar exclude directories?
The * that specifics "all files in the current directory" should be the last item on your cmd-line
tar --exclude="./test1" hczf t.tar.gz *
#--------------------------^-> tarFileName
#------------------------->f (for file)
This illustrates why the --excl... can't go inbetween hczf t.tar.gz.
The f option expects a filename right after it. So we have moved --excl... to the first option.
IHTH

ant tar, exclude content of a folder but include the folder itself

What's the right include/exclude pattern to exclude content of a folder but include the folder itself ?
for example,
I want to exclude all classes and all the package structure in WEB-INF/classes, but keep the folder itself.
Assuming the following directory str.:
..\ tarring \ xyz \ folder-A;
..\ tarring \ xyz \ folder-B;
...
..\ tarring \ xyz \ folder-X;
<tar basedir="..\tarring\xyz" destfile="..\tarring\xyz.tar">
<exclude name="folder-X/**/*"/>
</tar>
folder-X: the folder which is to be included in the tar file, but without its contents
xyz.tar will contain all the contents within the ..\ tarring \ xyz folder, along with an empty folder-X.
<exclude name="folder-X/**/*"/> : includes ONLY folder-X and not inner files or sub-directories
<exclude name="folder-X/**/*.*"/> : includes folder-X along with all sub-directories under it. However, excludes ALL files within folder-X and its sub-directories.
<exclude name="folder-X/*.*"/> : includes folder-X and any sub-directories within folder-X, along with all their contents BUT excludes all FILES directly under folder-X

tar --excludes option to exclude only the directory at current working directory, not subdirectories

I want to tar/zip a directory ./ (current working directory) and exclude files in the directory ./vendor, I happened to also have a subdirectory named vendor at ./public/web/vendor, but I want to keep that. I've tried:
tar cfz /private/var/folders/temp/mage6BRQWJ.tar.gz --exclude=vendor/* ./
tar cfz /private/var/folders/temp/mage6BRQWJ.tar.gz --exclude=./vendor/* ./
tar cfz /private/var/folders/temp/mage6BRQWJ.tar.gz --exclude="vendor/*" ./
But these both exclude the subdirectory.
I want to use relative path because I want to exclude all .svn (e.g. example) files from all directories, too.
Is there a way, using relative path , to exclude files in the ./vendor directory but not ./public/web/vendor ?
All you need is the --anchored tag:
GNU tar:
tar cfz mage6BRQWJ.tar.gz --anchored --exclude=vendor *
bsdtar:
bsdtar -czf mage6BRQWJ-1.tar.gz --exclude=^vendor *
That works.

copy and unzip files to remote machine - ant

I need to copy the zip files from local machine and paste in remote machine and unzip those files in remote machine.
I know the first part can be done using the scp (copy zip files from local and paste in remote machine) but how to do the second part using ant?
Thanks in advance
You could use the sshexec task to call the command line unzip command on the remote machine (assuming the remote machine has unzip installed).
<!-- local directory containing the files to copy -->
<property name="archives" location="C:\path\to\zipfiles" />
<property name="archives.destination" value="/home/testuser/archives" />
<property name="unzip.destination" value="/home/testuser/unpacked" />
<fileset id="zipfiles.to.copy" dir="${archives}" includes="*.zip" />
<!-- copy the archives to the remote server -->
<scp todir="${user}:${password}#host.example.com:${archives.destination}">
<fileset refid="zipfiles.to.copy" />
</scp>
<!-- Build the command line for unzip - the idea here is to turn the local
paths into the corresponding paths on the remote, i.e. to turn
C:\path\to\zipfiles\file1.zip;C:\path\to\zipfiles\file2.zip... into
/home/testuser/archives/file1.zip /home/testuser/archives/file2.zip
For this to work there must be no spaces in any of the zipfile names.
-->
<pathconvert dirsep="/" pathsep=" " property="unzip.files" refid="zipfiles.to.copy">
<map from="${archives}" to="${archives.destination}" />
</pathconvert>
<!-- execute the command. Use the "-d" option to unzip so it will work
whatever the "current" directory on the remote side -->
<sshexec host="host.example.com" username="${user}" password="${password}"
command="/bin/sh -c '
for zipfile in ${unzip.files}; do
/usr/bin/unzip -d ${unzip.destination} $$zipfile ; done '" />
The unzip command can take a number of other options, see its man page for full details. For example the -j option will ignore any directory hierarchy inside the zip files and put all the extracted files directly in the target directory. And -o will force overwrite existing files in the target directory without prompting.

Need to create a folder in remote server usint ant

using ant scp i can able to copy a file from local system(windows) to server(linux).so what i need is i want to create a folder by the system date at specified directory in linux system using ant and copy the file to the folder which created..
this is my ant script:
<sshexec host="hostname:22" username="****" trust="true"
password="fcubs"
command="mkdir $/home/desktop/<folder to be creted here>"/>
<scp todir="username#hostname:/home/desktop" password="*****" trust="true">
<fileset dir="D:\kkk"/>
</scp>
pls help me
thanks in advance
you can use such linux command which creates directory:
export ATD=`date '+%h-%d-%Y_%H:%M:%S'` && cd /path/to/specified/dir && mkdir $ATD && cd $ATD
it will create dir (for example) "Nov-14-2012_17:41:02" in the dir /path/to/specified/dir and will cd to it.
after executing this command you can simply copy your file to the directory.

Resources