snap limit set Limit the number of snapshots.
snap list (snap ls) Dump list of image snapshots.
snap protect Prevent a snapshot from being deleted.
- snap purge Delete all snapshots.
+ snap purge Delete all unprotected snapshots.
snap remove (snap rm) Delete a snapshot.
snap rename Rename a snapshot.
snap rollback (snap revert) Rollback image to snapshot.
[--image-id <image-id>] [--no-progress]
<image-spec>
- Delete all snapshots.
+ Delete all unprotected snapshots.
Positional arguments
<image-spec> image specification
} else if (0 == snaps.size()) {
return 0;
} else {
- for (size_t i = 0; i < snaps.size(); ++i) {
- r = image.snap_is_protected(snaps[i].name.c_str(), &is_protected);
+ list<std::string> protect;
+ for (auto it = snaps.begin(); it != snaps.end();) {
+ r = image.snap_is_protected(it->name.c_str(), &is_protected);
if (r < 0) {
pc.fail();
return r;
} else if (is_protected == true) {
- pc.fail();
- std::cerr << "\r" << "rbd: snapshot '" << snaps[i].name.c_str()
- << "' is protected from removal." << std::endl;
- return -EBUSY;
+ protect.push_back(it->name.c_str());
+ snaps.erase(it);
+ } else {
+ ++it;
}
}
+
+ if (!protect.empty()) {
+ std::cout << "rbd: error removing snapshot(s) '" << protect << "', which "
+ << (1 == protect.size() ? "is" : "are")
+ << " protected - these must be unprotected with "
+ << "`rbd snap unprotect`."
+ << std::endl;
+ }
for (size_t i = 0; i < snaps.size(); ++i) {
r = image.snap_remove(snaps[i].name.c_str());
if (r < 0) {
pc.fail();
return r;
}
- pc.update_progress(i + 1, snaps.size());
+ pc.update_progress(i + 1, snaps.size() + protect.size());
+ }
+
+ if (!protect.empty()) {
+ pc.fail();
+ } else if (snaps.size() > 0) {
+ pc.finish();
}
- pc.finish();
return 0;
}
}
{"snap", "remove"}, {"snap", "rm"}, "Delete a snapshot.", "",
&get_remove_arguments, &execute_remove);
Shell::Action action_purge(
- {"snap", "purge"}, {}, "Delete all snapshots.", "",
+ {"snap", "purge"}, {}, "Delete all unprotected snapshots.", "",
&get_purge_arguments, &execute_purge);
Shell::Action action_rollback(
{"snap", "rollback"}, {"snap", "revert"}, "Rollback image to snapshot.", "",