From 9b08891a1f633f194adc4cbadc512d343f6f46de Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 18 Sep 2006 20:56:21 +0000 Subject: [PATCH] kes Add -c option to pg_dump so that it initializes tables when restored. kes Fix FirstWritten time on Volume to be obtained from SD so that it is the actual time the volume was first written. kes Minor Makefile changes. kes Handle EBUSY during read(). Improve how EBUSY is handled in write(). git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3481 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/cats/make_catalog_backup.in | 4 ++-- bacula/src/dird/catreq.c | 12 ++++++++--- bacula/src/stored/Makefile.in | 14 ++++++------ bacula/src/stored/askdir.c | 5 +++-- bacula/src/stored/block.c | 30 +++++++++++++------------- bacula/src/stored/dev.h | 3 ++- bacula/src/version.h | 4 ++-- bacula/technotes-1.39 | 6 ++++++ 8 files changed, 46 insertions(+), 32 deletions(-) diff --git a/bacula/src/cats/make_catalog_backup.in b/bacula/src/cats/make_catalog_backup.in index 6c20a8ebd6..8bc30a582b 100755 --- a/bacula/src/cats/make_catalog_backup.in +++ b/bacula/src/cats/make_catalog_backup.in @@ -26,10 +26,10 @@ else else if test xpostgresql = x@DB_NAME@ ; then if test $# -gt 2; then - PGPASSWORD=$3 + PGPASSWORD=$3 export PGPASSWORD fi - exec @SQL_BINDIR@/pg_dump -U $2 $1 >$1.sql + exec @SQL_BINDIR@/pg_dump -c -U $2 $1 >$1.sql else echo ".dump" | @SQL_BINDIR@/sqlite3 $1.db >$1.sql fi diff --git a/bacula/src/dird/catreq.c b/bacula/src/dird/catreq.c index 3dd8a58212..e4dcdd4e5d 100644 --- a/bacula/src/dird/catreq.c +++ b/bacula/src/dird/catreq.c @@ -44,7 +44,7 @@ static char Update_media[] = "CatReq Job=%127s UpdateMedia VolName=%s" " VolJobs=%u VolFiles=%u VolBlocks=%u VolBytes=%" lld " VolMounts=%u" " VolErrors=%u VolWrites=%u MaxVolBytes=%" lld " EndTime=%d VolStatus=%10s" " Slot=%d relabel=%d InChanger=%d VolReadTime=%" lld " VolWriteTime=%" lld - " VolParts=%u\n"; + " VolFirstWritten=%" lld " VolParts=%u\n"; static char Create_job_media[] = "CatReq Job=%127s CreateJobMedia " " FirstIndex=%u LastIndex=%u StartFile=%u EndFile=%u " @@ -96,6 +96,7 @@ void catalog_request(JCR *jcr, BSOCK *bs) POOLMEM *omsg; POOL_DBR pr; uint32_t Stripe; + utime_t VolFirstWritten; memset(&mr, 0, sizeof(mr)); memset(&sdmr, 0, sizeof(sdmr)); @@ -197,7 +198,8 @@ void catalog_request(JCR *jcr, BSOCK *bs) &sdmr.VolJobs, &sdmr.VolFiles, &sdmr.VolBlocks, &sdmr.VolBytes, &sdmr.VolMounts, &sdmr.VolErrors, &sdmr.VolWrites, &sdmr.MaxVolBytes, &sdmr.LastWritten, &sdmr.VolStatus, &sdmr.Slot, &label, &sdmr.InChanger, - &sdmr.VolReadTime, &sdmr.VolWriteTime, &sdmr.VolParts) == 18) { + &sdmr.VolReadTime, &sdmr.VolWriteTime, &VolFirstWritten, + &sdmr.VolParts) == 19) { db_lock(jcr->db); Dmsg3(400, "Update media %s oldStat=%s newStat=%s\n", sdmr.VolumeName, @@ -214,7 +216,11 @@ void catalog_request(JCR *jcr, BSOCK *bs) } /* Set first written time if this is first job */ if (mr.FirstWritten == 0) { - mr.FirstWritten = jcr->start_time; /* use Job start time as first write */ + if (VolFirstWritten == 0) { + mr.FirstWritten = jcr->start_time; /* use Job start time as first write */ + } else { + mr.FirstWritten = VolFirstWritten; + } mr.set_first_written = true; } /* If we just labeled the tape set time */ diff --git a/bacula/src/stored/Makefile.in b/bacula/src/stored/Makefile.in index 58d42651df..1ce5c46d80 100644 --- a/bacula/src/stored/Makefile.in +++ b/bacula/src/stored/Makefile.in @@ -101,7 +101,7 @@ static-bacula-sd: $(SDOBJS) ../lib/libbac.a strip $@ btape.o: btape.c - echo "Compiling $<" + @echo "Compiling $<" $(NO_ECHO)$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) \ -I$(basedir) $(OPENSSL_INC) $(DINCLUDE) $(CFLAGS) $< @@ -110,27 +110,27 @@ btape: $(TAPEOBJS) ../lib/libbac.a ../cats/libsql.a -lsql $(DLIB) -lbac -lm $(LIBS) $(GETTEXT_LIBS) $(OPENSSL_LIBS) bls.o: bls.c - echo "Compiling $<" + @echo "Compiling $<" $(NO_ECHO)$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) $(PYTHON_INC) -I$(srcdir) \ -I$(basedir) $(OPENSSL_INC) $(DINCLUDE) $(CFLAGS) $< bls: ../findlib/libfind.a $(BLSOBJS) ../lib/libbac.a - echo "Compiling $<" + @echo "Compiling $<" $(NO_ECHO)$(CXX) $(TTOOL_LDFLAGS) $(LDFLAGS) -L../lib -L../findlib -o $@ $(BLSOBJS) $(DLIB) -lfind \ -lbac -lm $(LIBS) $(GETTEXT_LIBS) $(OPENSSL_LIBS) bextract.o: bextract.c - echo "Compiling $<" + @echo "Compiling $<" $(NO_ECHO)$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) $(PYTHON_INC) -I$(srcdir) \ -I$(basedir) $(OPENSSL_INC) $(DINCLUDE) $(CFLAGS) $< bextract: ../findlib/libfind.a $(BEXTOBJS) ../lib/libbac.a - echo "Compiling $<" + @echo "Compiling $<" $(NO_ECHO)$(CXX) $(TTOOL_LDFLAGS) $(LDFLAGS) -L../lib -L../findlib -o $@ $(BEXTOBJS) $(DLIB) $(FDLIBS) \ -lfind -lbac -lm $(PYTHON_LIBS) $(LIBS) $(GETTEXT_LIBS) $(OPENSSL_LIBS) bscan.o: bscan.c - echo "Compiling $<" + @echo "Compiling $<" $(NO_ECHO)$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) $(PYTHON_INC) -I$(srcdir) \ -I$(basedir) $(OPENSSL_INC) $(DINCLUDE) $(CFLAGS) $< @@ -139,7 +139,7 @@ bscan: ../findlib/libfind.a $(SCNOBJS) ../cats/libsql.a -lsql $(DB_LIBS) $(FDLIBS) -lfind -lbac -lm $(LIBS) $(GETTEXT_LIBS) $(OPENSSL_LIBS) bcopy.o: bcopy.c - echo "Compiling $<" + @echo "Compiling $<" $(NO_ECHO)$(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) \ -I$(basedir) $(OPENSSL_INC) $(DINCLUDE) $(CFLAGS) $< diff --git a/bacula/src/stored/askdir.c b/bacula/src/stored/askdir.c index 0a549aafae..4b4fb0f126 100644 --- a/bacula/src/stored/askdir.c +++ b/bacula/src/stored/askdir.c @@ -31,7 +31,7 @@ static char Update_media[] = "CatReq Job=%s UpdateMedia VolName=%s" " VolJobs=%u VolFiles=%u VolBlocks=%u VolBytes=%s VolMounts=%u" " VolErrors=%u VolWrites=%u MaxVolBytes=%s EndTime=%d VolStatus=%s" " Slot=%d relabel=%d InChanger=%d VolReadTime=%s VolWriteTime=%s" - " VolParts=%u\n"; + " VolFirstWritten=%s VolParts=%u\n"; static char Create_job_media[] = "CatReq Job=%s CreateJobMedia" " FirstIndex=%u LastIndex=%u StartFile=%u EndFile=%u" " StartBlock=%u EndBlock=%u Copy=%d Strip=%d\n"; @@ -282,7 +282,7 @@ bool dir_update_volume_info(DCR *dcr, bool label) BSOCK *dir = jcr->dir_bsock; DEVICE *dev = dcr->dev; time_t LastWritten = time(NULL); - char ed1[50], ed2[50], ed3[50], ed4[50]; + char ed1[50], ed2[50], ed3[50], ed4[50], ed5[50]; VOLUME_CAT_INFO *vol = &dev->VolCatInfo; int InChanger; POOL_MEM VolumeName; @@ -320,6 +320,7 @@ bool dir_update_volume_info(DCR *dcr, bool label) InChanger, /* bool in structure */ edit_uint64(vol->VolReadTime, ed3), edit_uint64(vol->VolWriteTime, ed4), + edit_uint64(vol->VolFirstWritten, ed5), vol->VolCatParts); Dmsg1(100, ">dird: %s", dir->msg); diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index 2b62215673..89410716a7 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -513,15 +513,16 @@ bool write_block_to_dev(DCR *dcr) * I/O errors, or from the OS telling us it is busy. */ int retry = 0; + errno = 0; do { + if ((retry > 0 && errno == EBUSY) || retry > 10) { + bmicrosleep(0, 50000); /* pause a bit if busy or lots of errors */ + } if (dev->is_tape()) { stat = tape_write(dev->fd, block->buf, (size_t)wlen); } else { stat = write(dev->fd, block->buf, (size_t)wlen); } - if (retry > 10) { - bmicrosleep(0, 100000); /* pause a bit if lots of errors */ - } } while (stat == -1 && (errno == EBUSY || errno == EIO) && retry++ < 30); #ifdef DEBUG_BLOCK_ZEROING @@ -544,6 +545,7 @@ bool write_block_to_dev(DCR *dcr) dev->dev_errno = ENOSPC; /* out of space */ } if (dev->dev_errno != ENOSPC) { + dev->VolCatInfo.VolCatErrors++; Jmsg4(jcr, M_ERROR, 0, _("Write error at %u:%u on device %s. ERR=%s.\n"), dev->file, dev->block_num, dev->print_name(), be.strerror()); } @@ -907,7 +909,7 @@ bool read_block_from_dev(DCR *dcr, bool check_block_numbers) return false; } looping = 0; - Dmsg1(200, "Full read() in read_block_from_device() len=%d\n", + Dmsg1(200, "Full read in read_block_from_device() len=%d\n", block->buf_len); reread: if (looping > 1) { @@ -948,25 +950,20 @@ reread: } retry = 0; + errno = 0; do { -// uint32_t *bp = (uint32_t *)block->buf; -// Pmsg3(000, "Read %p %u at %llu\n", block->buf, block->buf_len, lseek(dev->fd, 0, SEEK_CUR)); - + if ((retry > 0 && errno == EBUSY) || retry > 10) { + bmicrosleep(0, 50000); /* pause a bit if busy or lots of errors */ + } if (dev->is_tape()) { stat = tape_read(dev->fd, block->buf, (size_t)block->buf_len); } else { stat = read(dev->fd, block->buf, (size_t)block->buf_len); } - -// Pmsg8(000, "stat=%d Csum=%u blen=%u bnum=%u %c%c%c%c\n",stat, bp[0],bp[1],bp[2], -// block->buf[12],block->buf[13],block->buf[14],block->buf[15]); - - if (retry == 1) { - dev->VolCatInfo.VolCatErrors++; - } - } while (stat == -1 && (errno == EINTR || errno == EIO) && retry++ < 11); + } while (stat == -1 && (errno == EBUSY || errno == EINTR || errno == EIO) && retry++ < 30); if (stat < 0) { berrno be; + dev->VolCatInfo.VolCatErrors++; dev->clrerror(-1); Dmsg1(200, "Read device got: ERR=%s\n", be.strerror()); block->read_len = 0; @@ -1070,6 +1067,9 @@ reread: dev->VolCatInfo.VolCatBytes += block->block_len; dev->VolCatInfo.VolCatBlocks++; + if (dev->VolCatInfo.VolFirstWritten == 0) { + dev->VolCatInfo.VolFirstWritten = time(NULL); /* Set first written time */ + } dev->EndBlock = dev->block_num; dev->EndFile = dev->file; dev->block_num++; diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index 0408fc5206..94292171e6 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -163,13 +163,14 @@ struct VOLUME_CAT_INFO { uint32_t EndBlock; /* Last block number */ int32_t LabelType; /* Bacula/ANSI/IBM */ int32_t Slot; /* >0=Slot loaded, 0=nothing, -1=unknown */ - bool InChanger; /* Set if vol in current magazine */ + utime_t VolFirstWritten; /* Time of first write */ uint32_t VolCatMaxJobs; /* Maximum Jobs to write to volume */ uint32_t VolCatMaxFiles; /* Maximum files to write to volume */ uint64_t VolCatMaxBytes; /* Max bytes to write to volume */ uint64_t VolCatCapacityBytes; /* capacity estimate */ uint64_t VolReadTime; /* time spent reading */ uint64_t VolWriteTime; /* time spent writing this Volume */ + bool InChanger; /* Set if vol in current magazine */ char VolCatStatus[20]; /* Volume status */ char VolCatName[MAX_NAME_LENGTH]; /* Desired volume to mount */ }; diff --git a/bacula/src/version.h b/bacula/src/version.h index 8146603819..9e11c1eecd 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,8 +4,8 @@ #undef VERSION #define VERSION "1.39.23" -#define BDATE "16 September 2006" -#define LSMDATE "16Sep06" +#define BDATE "18 September 2006" +#define LSMDATE "18Sep06" #define BYEAR "2006" /* year for copyright messages in progs */ /* Debug flags */ diff --git a/bacula/technotes-1.39 b/bacula/technotes-1.39 index ae47b580b7..25364a31f8 100644 --- a/bacula/technotes-1.39 +++ b/bacula/technotes-1.39 @@ -2,6 +2,12 @@ General: 18Sep06 +kes Add -c option to pg_dump so that it initializes tables when + restored. +kes Fix FirstWritten time on Volume to be obtained from SD so that + it is the actual time the volume was first written. +kes Minor Makefile changes. +kes Handle EBUSY during read(). Improve how EBUSY is handled in write(). ebl Add yes keyword to prune/purge command 16Sep06 kes Correct a test in block.c that prevented restore of a DVD from -- 2.39.5