Operating System - HP-UX
1843898 Members
2264 Online
110225 Solutions
New Discussion

Re: tar: how to do backup of one by one file in the tape ?

 
Deepu Chakravarty
Regular Advisor

tar: how to do backup of one by one file in the tape ?

I have to do oracle database hotbackup. I have developed a script which takes complete list of file names from database and do backup in the tape. Which should be the correct script of tar ? So that all files are backed up one by one. Following is an example of list of files :
alter tablespace SYSTEM begin backup;
!tar cvf /dev/rmt/c3t8d0BEST /sysprod/sysascp/testdata/system11.dbf
alter tablespace SYSTEM end backup;

alter tablespace SYSTEM begin backup;
!tar cvf /dev/rmt/c3t8d0BEST /sysprod/sysascp/testdata/system10.dbf
alter tablespace SYSTEM end backup;

alter tablespace SYSTEM begin backup;
!tar cvf /dev/rmt/c3t8d0BEST /sysprod/sysascp/testdata/system09.dbf
alter tablespace SYSTEM end backup;

alter tablespace SYSTEM begin backup;
!tar cvf /dev/rmt/c3t8d0BEST /sysprod/sysascp/testdata/system08.dbf
alter tablespace SYSTEM end backup;

alter tablespace SYSTEM begin backup;
!tar cvf /dev/rmt/c3t8d0BEST /sysprod/sysascp/testdata/system07.dbf
alter tablespace SYSTEM end backup;

alter tablespace SYSTEM begin backup;
!tar cvf /dev/rmt/c3t8d0BEST /sysprod/sysascp/testdata/system06.dbf
alter tablespace SYSTEM end backup;

This way all files should be backed up in the media.

Pls advise.
Thanks.
9 REPLIES 9
Joseph Loo
Honored Contributor

Re: tar: how to do backup of one by one file in the tape ?

hi,

why don't u tar everything from the directory, /sysprod/sysascp/testdata/?

SQL> !tar -cvf /dev/rmt/c3t8d0BEST /sysprod/sysascp/testdata/

or u may like this in your script:

svrmgrl << EOT
connect as sysdba;
alter tablespace SYSTEM begin backup;
tar -cvf /dev/rmt/c3t8d0BEST /sysprod/sysascp/testdata/
alter tablespace SYSTEM end backup;
quit
EOT

refer to this post for more info:

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=600832

regards
what you do not see does not mean you should not believe
Deepu Chakravarty
Regular Advisor

Re: tar: how to do backup of one by one file in the tape ?

Hi,
I just gave one example only. I have other tablespaces also which should be backed up with this (SYSTEM) tablespace. There are altogether 52 datafiles which should be backed up one by one in the tape. How the script would be then ?
Thanks....
Indira Aramandla
Honored Contributor

Re: tar: how to do backup of one by one file in the tape ?

Hi Deepu,

You could do this way.

Get the list of all the tablespace names and the datafile names from the view dba_data_files and spool them a list file.

Once you have the list file then cat the list file and

For each line read from the list file
do

# (eg: $TBS_NAME is the variable containing the tablespace name the first column in the list file and $FS_NAME is the datafile name in the second column of the list file)

#Alter tablespace start backup

sqlplus â s <connect internal
alter tablespace $TBS_NAME begin backup ;
exit
EOF3

tar -cvf /dev/rmt/c3t8d0BEST /sysprod/sysascp/testdata/$FS_NAME

# Alter tablespace end backup

sqlplus â s <connect internal
alter tablespace $TBS_NAME end backup ;
exit
EOF4
do
Never give up, Keep Trying
Bernhard Mueller
Honored Contributor

Re: tar: how to do backup of one by one file in the tape ?

Hi,

I would suggest you write the *.dbf paths into a file and use a single "fbackup -g" command.

man fbackup will certainly help

if you use "tar -c" with a "rewind" device file then after each command the tape will be rewound and your next "tar -c" will overwrite the existing tarfile on tape....

you can instead use "tar -u" to add the file to the existing tarfile on tape, or use a no-rewind device file and write several tarfiles on tape. In that case, however, it will be quite difficult to restore since you need to use mt to wind the tape to the n-th tarfile (assuming you alread know that you need the n-th tarfile) to extract it. Also performance will be quite bad in any case you are not using a single tar command.

Regards,
Bernhard

Cem Tugrul
Esteemed Contributor

Re: tar: how to do backup of one by one file in the tape ?

Hi,

Things to remember about tar:

* tar is, for the most part, platform generic (ie: a tar tape created on
a SUN machine can usually be read by an HPUX machine). However, if the
platforms are far removed from each other (ie: SunOS 4.x and HPUX
11.0), then reading the tape may be impossible.

Command Description

tar cvf /dev/rmt/0m /etc/hosts backup one file

tar cvf /dev/rmt/0m (file1) (file2) backup file1 and file2

tar tvf /dev/rmt/0m verify contents of tape

tar xvf /dev/rmt/0m restore entire tape

tar xvf /dev/rmt/0m (file) restore one file

tar tf /dev/rmt/0m | grep swp | xargs restore all files that contain
tar xvf /dev/rmt/0m the string swp

Good Luck,
Our greatest duty in this life is to help others. And please, if you can't
Roland Piette
Regular Advisor

Re: tar: how to do backup of one by one file in the tape ?

Hi,

May I add a little remark about tar and sparse file.

tar will certainly copy your datafile on tape, but when you will extract it you will maybe not have enough space to restore it.

Sparse file are often use in Database concept to limit block usage on disk.

A following code explains this concept :

#include
#include
void main()
{
int fd;
int data = 0xdeadbeef;
fd = open("/tmp/sparse", O_WRONLY|O_CREAT|O_TRUNC, 0666);
lseek(fd, 2*1024*1024, SEEK_SET);
write(fd, &data, sizeof(int));
close(fd);
exit(0);
}

$ ll /tmp/sparse
-rw-rw-rw- 1 woof users 2097156 Aug 13 14:13 /tmp/sparse

$ du /tmp/sparse
32 /tmp/sparse

$ xd /tmp/sparse
0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
0200000 dead beef
0200004

You can see a difference between spaces used for this file. In datafiles there is a lot of space wich contains no relevant information then lot of space not used. Sparse file uses only disk blocs with usable info.

Conclusion :
For this kind of file fbackup is better !

Only a little stone in this thread
Roland PIETTE
Greg OBarr
Regular Advisor

Re: tar: how to do backup of one by one file in the tape ?

This is a script that I wrote to do the same thing, but it writes the backup to disk first and compresses the tar files. You can backup the entire database in a small amount of disk space using this method. Once the script is finished, you write all the files to tape at one time with tar.

See attached file
Greg OBarr
Regular Advisor

Re: tar: how to do backup of one by one file in the tape ?

By the way, the script I sent also does a binary and trace file backup of the control files, and backs up the initSID.ora file and an include file, if you are using one. Without backing these up also, you'd have a difficult time recovering.

-greg
Jeroen Peereboom
Honored Contributor

Re: tar: how to do backup of one by one file in the tape ?

You should use the NOREWIND device /dev/rmt/c3t8d0BESTn
if writing multiple times to the same tape.
Otherwise you end up with one tar file on the tape i.s.o. many.

JP