Making Tar of directory and tar file is going to be placed

Quick question,

is it possible to make a Tar of completely directory and placing the tar file in it (will this cause even the tar file to tarred ?)

sample:

/opt/freeware/bin/tar -cvf -  /oracle | gzip > /oracle/backup.tgz

will the tar file backup.tgz also include backup.tgz ?

i tried searching for answer but did not find a reasonable answer.

Try:

tar --exclude backup.tar.gz -acf backup.tar.gz *

hth

Thanks SEA, so it is important to exclude the file, which means that Tar backup will include the newly backuped tar file into tar

so, let try it this way,
put the file in a directory called /nobackup

tar --exclude /oracle/backup/ -cvf -  /oracle | gzip > /oracle/backup.tgz

am i right ?

Table 1. Required Flags
Required Flags Description
-c Creates a new archive and writes the files specified by one or more File parameters to the beginning of the archive.
-f Archive Uses the Archive variable as the archive to be read or written. When this flag is not specified, the tar command uses a system-dependent default file name of the form /dev/rmt0. If the Archive variable specified is - (minus sign), the tar command writes to standard output or reads from standard input. If you write to standard output, the -c flag must be used.
-v Lists the name of each file as it is processed. With the -t flag, -v gives more information about the tape entries, including file sizes, times of last modification, User Number (UID), Group Number (GID), and permissions.

what does -a in tar parameter stand for ?
thanks

Yes, that is possible - it is just not worth the hassle.

Without taking precautions: yes, it will, although in an incomplete and unusable form.

Note that this here is the AIX-forum and hence i suppose you use AIX as your OS. The AIX tar (as opposed to the GNU tar) does NOT know the suggested "--exclude" option , because it is not required by POSIX. This means the suggested solution will not not work in AIX as long as you are not willing to install a lot of (GNU-)software.

You can achieve the same using some find -statement to produce a list of file names in the directory minus the one with the name of the tar-file itself and feed that into tar. But, frankly: wouldn't be writing the tar-file elsewhere and finally moving it be a lot easier? In principle it is possible to walk from Europe to China on your hands, but: an airplane will get you there as well and it will be less tedious.

If you think about backing up your database that way, be warned: tar follows the ustar-standard and this limits the single input file to 8G of size. Therefore tar is a poor tool for database backups. (btw: cpio does the same). For the backup of Oracle databases consider using the Oracle-framework called RMAN and some backup tool. You need it anyway because you need to constantly shovel the archive logs off the machine when the DB is running.

I hope this helps.

bakunin

I think that /oracle is not a database but an ORACLE_HOME hopefully :slight_smile:

Nevertheless you might want to consider using pax if you don't have GNU tar

cd /oracle
pax -w -f backup.tar -s',backup.tar,,' .
cd -

Will shall change directory to /oracle and create archive of current directory (.) using the pax substitute to exclude the backup.tar file itself. After it is done we shall return to previous working directory (-).

You will be able to extract the tar file using tar or pax on any operating system, but limits Bakunin mentioned still apply.

Hope that helps
Regards
Peasant.

If you use pax archive format when using the pax utility, the file size limits from the tar and cpio archive formats are removed. So with:

cd /oracle
pax -w -x pax -f backup.pax -s',backup.pax,,' .
cd -

files of any size can be archived as long as there is enough space in the filesystem where the archive is being written to hold the entire archive.

This might even work without the -x pax option; the standards don't specify which archive format is used when creating an archive when the -x option is not specified on the command line.