diff --git a/api/classes/lifepreserver.rst b/api/classes/lifepreserver.rst index 36bb30f..5b32fa7 100644 --- a/api/classes/lifepreserver.rst +++ b/api/classes/lifepreserver.rst @@ -178,6 +178,10 @@ Create a Schedule The "cronsnap" action is used to create snapshot schedules for Life Preserver. When creating a schedule, specify the ZFS pool to snapshot, how many snapshots to keep, and at what time the snapshots should occur. +Frequency: none, daily@XX, hourly, 30min, 10min, 5min (Specifying 'none' disables) +Keep: + + **REST Request** .. code-block:: json @@ -300,4 +304,4 @@ Run :command:`lpreserver help set` for more information about each available set "id": "fooid", "name": "response", "namespace": "sysadm" - } \ No newline at end of file + } diff --git a/src/library/sysadm-lifepreserver.cpp b/src/library/sysadm-lifepreserver.cpp index a42567f..211a3a7 100644 --- a/src/library/sysadm-lifepreserver.cpp +++ b/src/library/sysadm-lifepreserver.cpp @@ -106,6 +106,52 @@ QJsonObject LifePreserver::listSnap(QJsonObject jsin) { return retObject; } +// Schedule a new scrub routine +QJsonObject LifePreserver::scheduleScrub(QJsonObject jsin) { + QJsonObject retObject; + QString pool, frequency; + + QStringList keys = jsin.keys(); + bool ok = false; + if(! keys.contains("pool") || ! keys.contains("frequency")){ + retObject.insert("error", "Requires pool and frequency keys"); + return retObject; + } + + // Check which pool we are looking at + pool = jsin.value("pool").toString(); + frequency = jsin.value("frequency").toString(); + + // Make sure we have the pool / frequency / keep key(s) + if ( pool.isEmpty() || frequency.isEmpty() ) { + retObject.insert("error", "Empty pool or frequency keys "); + return retObject; + } + + QStringList output; + if ( frequency == "none" ) + output = General::RunCommand("lpreserver cronscrub " + pool + " stop " + frequency).split("\n"); + else + output = General::RunCommand("lpreserver cronscrub " + pool + " start " + frequency).split("\n"); + + // Check for any errors + for ( int i = 0; i < output.size(); i++) + { + if ( output.at(i).indexOf("ERROR:") != -1 ) { + retObject.insert("error", output.at(i)); + return retObject; + } + } + + // Got to the end, return the good json + QJsonObject values; + values.insert("pool", pool); + values.insert("frequency", frequency); + + return values; +} + + // Schedule a new snapshot routine QJsonObject LifePreserver::scheduleSnapshot(QJsonObject jsin) { QJsonObject retObject; @@ -129,7 +175,11 @@ QJsonObject LifePreserver::scheduleSnapshot(QJsonObject jsin) { return retObject; } - QStringList output = General::RunCommand("lpreserver cronsnap " + pool + " start " + frequency + " " + keep ).split("\n"); + QStringList output; + if ( frequency == "none" ) + output = General::RunCommand("lpreserver cronsnap " + pool + " stop " ).split("\n"); + else + output = General::RunCommand("lpreserver cronsnap " + pool + " start " + frequency + " " + keep ).split("\n"); // Check for any errors for ( int i = 0; i < output.size(); i++) diff --git a/src/library/sysadm-lifepreserver.h b/src/library/sysadm-lifepreserver.h index 940978f..9f6ffa1 100644 --- a/src/library/sysadm-lifepreserver.h +++ b/src/library/sysadm-lifepreserver.h @@ -18,6 +18,7 @@ public: static QJsonObject listCron(); static QJsonObject listSnap(QJsonObject jsin); static QJsonObject scheduleSnapshot(QJsonObject jsin); + static QJsonObject scheduleScrub(QJsonObject jsin); static QJsonObject settings(); }; diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index 2eaf477..970007e 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -149,6 +149,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmLifePreserverRequest(const Q ok = true; out->insert("listsnap", sysadm::LifePreserver::listSnap(in_args.toObject())); } + if(act=="cronscrub"){ + ok = true; + out->insert("cronscrub", sysadm::LifePreserver::scheduleScrub(in_args.toObject())); + } if(act=="cronsnap"){ ok = true; out->insert("cronsnap", sysadm::LifePreserver::scheduleSnapshot(in_args.toObject()));