diff options
author | Andreas Rogge <andreas.rogge@bareos.com> | 2022-11-07 19:13:59 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-07 19:13:59 +0300 |
commit | 87d3420ea8e36da9244a097eddf2ebd329fd75d7 (patch) | |
tree | 5d2862d3a6edf74b276079699c588af36d1737be | |
parent | cda7bdc0b540fa46a6784ce473cee143826a0a87 (diff) | |
parent | b99894b54a3c9743421afeca887c90433211b635 (diff) |
Merge pull request #1300
catalog: update fileset text in fileset record
-rw-r--r-- | CHANGELOG.md | 7 | ||||
-rw-r--r-- | core/src/cats/sql_create.cc | 30 | ||||
-rw-r--r-- | core/src/dird/job.cc | 6 | ||||
-rwxr-xr-x | systemtests/tests/bareos/testrunner-filesettext-is-updated | 68 |
4 files changed, 103 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 36268fc69..23e030056 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https: - stored: dird: added backup checkpoints that save backup metadata to the Catalog during the execution of the backup. [PR #1074] - stored: dird: add backup checkpoints that save backup metadata to the Catalog during the execution of the backup. [PR #1074] - build: run a build and test with sanitizers enabled [PR #1244] +- catalog: update fileset text in fileset record [PR #1300] ### Fixed - webui: adapt links to new URLs after website relaunch. [PR #1275] @@ -332,6 +333,7 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https: [PR #1254]: https://github.com/bareos/bareos/pull/1254 [PR #1255]: https://github.com/bareos/bareos/pull/1255 [PR #1260]: https://github.com/bareos/bareos/pull/1260 +[PR #1261]: https://github.com/bareos/bareos/pull/1261 [PR #1262]: https://github.com/bareos/bareos/pull/1262 [PR #1265]: https://github.com/bareos/bareos/pull/1265 [PR #1266]: https://github.com/bareos/bareos/pull/1266 @@ -341,6 +343,11 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https: [PR #1275]: https://github.com/bareos/bareos/pull/1275 [PR #1277]: https://github.com/bareos/bareos/pull/1277 [PR #1278]: https://github.com/bareos/bareos/pull/1278 +[PR #1279]: https://github.com/bareos/bareos/pull/1279 [PR #1284]: https://github.com/bareos/bareos/pull/1284 [PR #1285]: https://github.com/bareos/bareos/pull/1285 +[PR #1288]: https://github.com/bareos/bareos/pull/1288 +[PR #1296]: https://github.com/bareos/bareos/pull/1296 +[PR #1298]: https://github.com/bareos/bareos/pull/1298 +[PR #1300]: https://github.com/bareos/bareos/pull/1300 [unreleased]: https://github.com/bareos/bareos/tree/master diff --git a/core/src/cats/sql_create.cc b/core/src/cats/sql_create.cc index 3d26ceba9..90c836b49 100644 --- a/core/src/cats/sql_create.cc +++ b/core/src/cats/sql_create.cc @@ -704,11 +704,13 @@ bool BareosDb::CreateFilesetRecord(JobControlRecord* jcr, FileSetDbRecord* fsr) fsr->FileSetId = 0; if (QUERY_DB(jcr, cmd)) { num_rows = SqlNumRows(); + if (num_rows > 1) { - Mmsg1(errmsg, _("More than one FileSet!: %d\n"), num_rows); + Mmsg2(errmsg, _("More than one FileSet! %s: %d\n"), esc_fs, num_rows); Jmsg(jcr, M_ERROR, 0, "%s", errmsg); } if (num_rows >= 1) { + // fileset record found if ((row = SqlFetchRow()) == NULL) { Mmsg1(errmsg, _("error fetching FileSet row: ERR=%s\n"), sql_strerror()); @@ -722,8 +724,30 @@ bool BareosDb::CreateFilesetRecord(JobControlRecord* jcr, FileSetDbRecord* fsr) } else { bstrncpy(fsr->cCreateTime, row[1], sizeof(fsr->cCreateTime)); } + // Update existing fileset record to make sure the fileset text is + // inserted + PoolMem esc_filesettext(PM_MESSAGE); + + len = strlen(fsr->FileSetText); + esc_filesettext.check_size(len * 2 + 1); + EscapeString(jcr, esc_filesettext.c_str(), fsr->FileSetText, len); + + Mmsg(cmd, + "UPDATE FileSet SET (FileSet,MD5,CreateTime,FileSetText) " + "= ('%s','%s','%s','%s') WHERE FileSet='%s' AND MD5='%s' ", + esc_fs, esc_md5, fsr->cCreateTime, esc_filesettext.c_str(), esc_fs, + esc_md5); + if (QUERY_DB(jcr, cmd)) { + SqlFreeResult(); + return true; + } else { + Mmsg1(errmsg, _("error updating FileSet row: ERR=%s\n"), + sql_strerror()); + Jmsg(jcr, M_ERROR, 0, "%s", errmsg); + SqlFreeResult(); + return false; + } SqlFreeResult(); - return true; } SqlFreeResult(); } @@ -739,7 +763,6 @@ bool BareosDb::CreateFilesetRecord(JobControlRecord* jcr, FileSetDbRecord* fsr) len = strlen(fsr->FileSetText); esc_filesettext.check_size(len * 2 + 1); EscapeString(jcr, esc_filesettext.c_str(), fsr->FileSetText, len); - Mmsg(cmd, "INSERT INTO FileSet (FileSet,MD5,CreateTime,FileSetText) " "VALUES ('%s','%s','%s','%s')", @@ -902,7 +925,6 @@ bool BareosDb::CreateFileAttributesRecord(JobControlRecord* jcr, DbLocker _{this}; Dmsg1(dbglevel, "Fname=%s\n", ar->fname); Dmsg0(dbglevel, "put_file_into_catalog\n"); - SplitPathAndFile(jcr, ar->fname); if (!CreatePathRecord(jcr, ar)) { return false; } diff --git a/core/src/dird/job.cc b/core/src/dird/job.cc index 0b1f7f06b..a317f873a 100644 --- a/core/src/dird/job.cc +++ b/core/src/dird/job.cc @@ -1352,10 +1352,8 @@ bool GetOrCreateFilesetRecord(JobControlRecord* jcr) unsigned char digest[16]; /* MD5 digest length */ memcpy(&md5c, &jcr->impl->res.fileset->md5c, sizeof(md5c)); ALLOW_DEPRECATED(MD5_Final(digest, &md5c)); - /* - * Keep the flag (last arg) set to false otherwise old FileSets will - * get new MD5 sums and the user will get Full backups on everything - */ + /* Keep the flag (last arg) set to false otherwise old FileSets will + * get new MD5 sums and the user will get Full backups on everything */ BinToBase64(fsr.MD5, sizeof(fsr.MD5), (char*)digest, sizeof(digest), false); bstrncpy(jcr->impl->res.fileset->MD5, fsr.MD5, sizeof(jcr->impl->res.fileset->MD5)); diff --git a/systemtests/tests/bareos/testrunner-filesettext-is-updated b/systemtests/tests/bareos/testrunner-filesettext-is-updated new file mode 100755 index 000000000..d3ec000bb --- /dev/null +++ b/systemtests/tests/bareos/testrunner-filesettext-is-updated @@ -0,0 +1,68 @@ +#!/bin/bash +set -e +set -o pipefail +set -u + +# Delete fileset text from database and check that it is readded +# when estimate call uses the fileset +TestName="$(basename "$(pwd)")" +export TestName + + +#shellcheck source=../environment.in +. ./environment + +#shellcheck source=../scripts/functions +. "${rscripts}"/functions + +start_test + +run_log=$tmp/run.out +filesetwithtext=$tmp/fileset-with-filesettext +filesetwithouttext=$tmp/fileset-without-filesettext +JobName=backup-bareos-fd + +rm -f $run_log $filesetwithtext $filesetwithouttext + + +cat <<END_OF_DATA >"$tmp/bconcmds" +@$out /dev/null +messages +@$out $run_log +@# first do an estimate to be sure the fileset db entry exists +estimate listing job=$JobName + +@# remove filesettext from db entry +sqlquery +update fileset set filesettext=''; + +@$out $filesetwithouttext +@# display fileset entry (without filesettext) +sqlquery +select * from fileset; + +@# call estimate to update the fileset db entry and readd the filesettext +estimate listing job=$JobName + +@#verify the fileset text is added again +@$out $filesetwithtext +sqlquery +select * from fileset; +END_OF_DATA + +run_bconsole + +run_bconsole + +# check that the fileset has not the fileset text after it was deleted +expect_grep "| 1 | SelfTest | FileSet {" \ + "$filesetwithtext" \ + "The expected fileset text was not found." + +# check that the fileset has the fileset was added by the estimate call +expect_grep "| 1 | SelfTest | |" \ + "$filesetwithouttext" \ + "The expected fileset without text was not found." + + +end_test |