Q: Remove folder structure from archive, ignore folder while archiving and fix error I am trying to make a script to backup each of my plesk hosts to individual files, I am having two problems:


*

*I would like to remove the folder structure from archive, the tar is 3 folders deep

*I am getting this error: tar: Removing leading `/' from member names

*I need my archive to ignore folders named "catch" because I don't need them in my archive.


The code:
FILES=/var/www/vhosts/*
FNAME=""
for f in $FILES
do
FNAME=`basename $f`
tar cfv "/root/backup/ftp/$FNAME.tar" $f
done

Sample output:
tar: Removing leading `/' from member names
/var/www/vhosts/mydomain.com/
/var/www/vhosts/mydomain.com/conf
/var/www/vhosts/mydomain.com/etc/
/var/www/vhosts/mydomain.com/etc/group
/var/www/vhosts/mydomain.com/etc/termcap
/var/www/vhosts/mydomain.com/etc/passwd
/var/www/vhosts/mydomain.com/usr/


A: 
I would like to remove the folder structure from archive, the tar is 3
  folders deep

you can't. cd to the target directory or one level higher, then run tar on ./$f

I am getting this error: tar: Removing leading `/' from member names

this is rather a warning and if you follow the first suggestion you will not get it again

A: As always, in Linux a single command will do:
for i in $(find /path/to/source/dir -type f -exec echo {} \;) ; do tar -c  -f path/to/dest/directory/${i##*/}.tar -C ${i%/*} ${i##*/} ; done

Make sure that the source directory is specified through its full path name, not a relative one; the rest is obvious, I have used heavily the shell substitution capacities. 
EDIT: while I was writing my reply, an other answer stated that one cannot erase the directory structure. This is not correct, the -F option in tar does exactly that. With this command, one will find all files coming from the directory tree in /path/to/source/directory, all suitably tarred, and piled up neatly within the branchless directory /path/to/dest/directory. 
Edit: the change requested, i.e., excluding files whose names begin with catch, can be accomplished by means of the following command:
for i in $(find /path/to/source/dir -type f ! -name 'catch*' -exec echo {} \;) ; do tar -c  -f path/to/dest/directory/${i##*/}.tar -C ${i%/*} ${i##*/} ; done

If you want to avoid files ending the with catch, susbstitute catch* with *catch, I am sure you get the drift.
