Problem with write/read to/from the tape
I am using RHEL 5.3
I want to do some backup/restore and export/import operation with the database.
I am writing a label to the tape as "BACKUP TAPE" or "EXPORT TAPE" during backup/export , so that i can check the same while doing restore/import.
I used the below code to write to the tape:
//checking the tape
if ((fd = open("/dev/st0", O_RDONLY)) >= 0) {
printf( "Tape open succeeded\n");
close(fd); }
//Rewinding the tape
if( system("mt -f /dev/st0 rewind") != 0 ) {
printf( "tape rewind failed\n");
exit(0); }
//Opening the tape in non-rewinding mode
if ((fp = fopen("/dev/nst0","w")) == NULL) {
printf( "tape open failed\n");
exit(0); }
//writing to tape
if((fprintf(fp,"BACKUP TAPE\n")<=0) || (ferror(fp)!=0))
printf("write failed\n");
fclose(fp);
To read from the tape:
I did the first 3 same operation as in writing and here the code follows
if((fgets(cmd,sizeof(cmd)-1,fp)==NULL) || (ferror(fp)!=0) ) {
printf("Reading from tape failed\n"); }
printf ("cmd is %s\n", cmd); --> prints nothing
But write is getting passed without any errors.
On the other side, read fails and cud nt read the label
Can anyone help me out where i am going wrong?
Should i go for tar/cpio to write even a string?
-Lakshmi
|