Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dird: fix purge oldest volume #1628

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Documentation
- docs: improvements for droplet, jobdefs [PR #1581]

### Fixed
- dird: fix `purge oldest volume` [PR #1628]

[PR #1581]: https://github.com/bareos/bareos/pull/1581
[PR #1587]: https://github.com/bareos/bareos/pull/1587
[PR #1589]: https://github.com/bareos/bareos/pull/1589
Expand All @@ -33,4 +36,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[PR #1612]: https://github.com/bareos/bareos/pull/1612
[PR #1614]: https://github.com/bareos/bareos/pull/1614
[PR #1617]: https://github.com/bareos/bareos/pull/1617
[PR #1628]: https://github.com/bareos/bareos/pull/1628
[unreleased]: https://github.com/bareos/bareos/tree/master
6 changes: 2 additions & 4 deletions core/src/dird/ua_input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,12 @@ bool GetYesno(UaContext* ua, const char* prompt)
* or user enters "yes"
* false otherwise
*/
bool GetConfirmation(UaContext* ua, const char* prompt)
bool GetConfirmation(UaContext* ua, const char* prompt, bool fallback_value)
{
if (FindArg(ua, NT_("yes")) >= 0) { return true; }

if (!ua->UA_sock) { return fallback_value; }
if (ua->api || ua->batch) { return false; }

if (GetYesno(ua, prompt)) { return (ua->pint32_val == 1); }

return false;
}

Expand Down
3 changes: 2 additions & 1 deletion core/src/dird/ua_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ bool GetPint(UaContext* ua, const char* prompt);
bool GetYesno(UaContext* ua, const char* prompt);
bool IsYesno(char* val, bool* ret);
bool GetConfirmation(UaContext* ua,
const char* prompt = T_("Confirm (yes/no): "));
const char* prompt = T_("Confirm (yes/no): "),
bool fallback_value = false);
int GetEnabled(UaContext* ua, const char* val);
void ParseUaArgs(UaContext* ua);
bool IsCommentLegal(UaContext* ua, const char* name);
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/ua_purge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ bool PurgeJobsFromVolume(UaContext* ua, MediaDbRecord* mr, bool force)
} else {
ua->InfoMsg(T_("Found %d Jobs for media \"%s\" in catalog \"%s\".\n"),
lst.size(), mr->VolumeName, client->catalog->resource_name_);
if (!GetConfirmation(ua, "Purge (yes/no)? ")) {
if (!GetConfirmation(ua, "Purge (yes/no)? ", true)) {
ua->InfoMsg(T_("Purge canceled.\n"));
} else {
PurgeJobsFromCatalog(ua, jobids.c_str());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Job {
Name = "purge-oldest-job"
Type = Backup
Level = Full
Client = "bareos-fd"
FileSet = "SelfTest"
Storage = File
Messages = Standard
Pool = purgeoldest
Priority = 10
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Pool {
Name = purgeoldest
Pool Type = Backup
Recycle = yes # Bareos can automatically recycle Volumes
AutoPrune = yes # Prune expired volumes
Volume Retention = 1 year # How long should the Full Backups be kept? (#06)
Maximum Volume Bytes = 2M # Limit Volume size to something reasonable
Maximum Volumes = 12 # Limit number of Volumes in Pool
Label Format = "purgeoldest-"
Purge Oldest Volume = yes
}
66 changes: 66 additions & 0 deletions systemtests/tests/bareos-basic/testrunner-purge-oldest
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash
set -e
set -o pipefail
set -u
#
# Run multiple backups in parallel and
# then restore them.
#
TestName="$(basename "$(pwd)")"
export TestName

#shellcheck source=../environment.in
. ./environment

#shellcheck source=../scripts/functions
. "${rscripts}"/functions

start_test

backupjob="purge-oldest-job"
recycle_backuplog="$tmp/purge-oldest-backuplog.out"
recycle_restorelog="$tmp/purge-oldest-restorelog.out"
recyle_restoredirectory="$tmp/purge-oldest-restore"

rm -f $recycle_backuplog
rm -f $recycle_restorelog

cat <<END_OF_DATA >"$tmp/bconcmds"
@$out $recycle_backuplog
run job=$backupjob level=Full yes
wait
@sleep 2
run job=$backupjob level=Full yes
wait
@sleep 2
messages
quit
END_OF_DATA

run_bconsole

backup_with_recycled_volume=$(awk '/Job queued./{i++}i==2 {print; exit;}' "$recycle_backuplog" | sed -n -e 's/^.*JobId=//p')
volume_tobe_recycled=$(grep "Labeled new Volume" $recycle_backuplog | sed -n -e 's/^.*Labeled new Volume "//p' | sed -n -e 's/" on device .*//p')

cat <<END_OF_DATA >"$tmp/bconcmds"
@$out $recycle_restorelog
restore jobid=$backup_with_recycled_volume client=bareos-fd fileset=SelfTest where=$recyle_restoredirectory select all done yes
wait
messages
quit
END_OF_DATA

run_bconsole

expect_grep "Recycled volume \"$volume_tobe_recycled\"" \
"$recycle_backuplog" \
"Volume was not recycled!"

expect_grep "New volume \"$volume_tobe_recycled\" mounted on device \"FileStorage\"" \
"$recycle_backuplog" \
"Recycled volume was not reused!"

check_two_logs "$recycle_backuplog" "$recycle_restorelog"
check_restore_diff "${BackupDirectory}" "$recyle_restoredirectory"

end_test