Skip to content

Commit

Permalink
Updated the run-script module to report the parsed result level.
Browse files Browse the repository at this point in the history
This fixes #2656
  • Loading branch information
kenkendk committed Sep 1, 2017
1 parent 80d533b commit d6aa87e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
27 changes: 20 additions & 7 deletions Duplicati/Library/Modules/Builtin/RunScript.cs
Expand Up @@ -21,7 +21,8 @@
using System.Text;
using System.Collections.Generic;
using Duplicati.Library.Utility;

using Duplicati.Library.Interface;

namespace Duplicati.Library.Modules.Builtin
{
public class RunScript : Duplicati.Library.Interface.IGenericCallbackModule
Expand Down Expand Up @@ -87,21 +88,30 @@ public void OnStart(string operationname, ref string remoteurl, ref string[] loc


if (!string.IsNullOrEmpty(m_requiredScript))
Execute(m_requiredScript, "BEFORE", m_operationName, ref m_remoteurl, ref m_localpath, m_timeout, true, m_options, null);
Execute(m_requiredScript, "BEFORE", m_operationName, ref m_remoteurl, ref m_localpath, m_timeout, true, m_options, null, null);

if (!string.IsNullOrEmpty(m_startScript))
Execute(m_startScript, "BEFORE", m_operationName, ref m_remoteurl, ref m_localpath, m_timeout, false, m_options, null);
Execute(m_startScript, "BEFORE", m_operationName, ref m_remoteurl, ref m_localpath, m_timeout, false, m_options, null, null);
}

public void OnFinish (object result)
{
if (string.IsNullOrEmpty(m_finishScript))
return;
return;


ParsedResultType level;
if (result is Exception)
level = ParsedResultType.Fatal;
else if (result != null && result is Library.Interface.IBasicResults)
level = ((IBasicResults)result).ParsedResult;
else
level = ParsedResultType.Error;

using (TempFile tmpfile = new TempFile())
{
SerializeResult(tmpfile, result);
Execute(m_finishScript, "AFTER", m_operationName, ref m_remoteurl, ref m_localpath, m_timeout, false, m_options, tmpfile);
Execute(m_finishScript, "AFTER", m_operationName, ref m_remoteurl, ref m_localpath, m_timeout, false, m_options, tmpfile, level);
}
}
#endregion
Expand Down Expand Up @@ -171,7 +181,7 @@ public static void SerializeResult(string file, object result)
}
}

private static void Execute(string scriptpath, string eventname, string operationname, ref string remoteurl, ref string[] localpath, int timeout, bool requiredScript, IDictionary<string, string> options, string datafile)
private static void Execute(string scriptpath, string eventname, string operationname, ref string remoteurl, ref string[] localpath, int timeout, bool requiredScript, IDictionary<string, string> options, string datafile, ParsedResultType? level)
{
try
{
Expand All @@ -191,7 +201,10 @@ private static void Execute(string scriptpath, string eventname, string operatio
psi.EnvironmentVariables["DUPLICATI__EVENTNAME"] = eventname;
psi.EnvironmentVariables["DUPLICATI__OPERATIONNAME"] = operationname;
psi.EnvironmentVariables["DUPLICATI__REMOTEURL"] = remoteurl;
if (localpath != null)
if (level != null)
psi.EnvironmentVariables["DUPLICATI__PARSED_RESULT"] = level.Value.ToString();

if (localpath != null)
psi.EnvironmentVariables["DUPLICATI__LOCALPATH"] = string.Join(System.IO.Path.PathSeparator.ToString(), localpath);

string stderr = null;
Expand Down
5 changes: 4 additions & 1 deletion Duplicati/Library/Modules/Builtin/run-script-example.bat
Expand Up @@ -100,6 +100,9 @@ REM is empty operations other than backup or restore. The local path can
REM contain : to separate multiple folders. This value can be changed by echoing
REM --localpath = "new value".

REM DUPLICATI__PARSED_RESULT
REM This is a value indicating how well the operation was performed.
REM It can take the values: Unknown, Success, Warning, Error, Fatal.


REM ###############################################################################
Expand Down Expand Up @@ -154,7 +157,7 @@ GOTO end

IF "%OPERATIONNAME%" == "Backup" GOTO ON_AFTER_BACKUP
REM This will be ignored
echo "Got operation "%OPERATIONNAME%", ignoring
echo "Got operation "%OPERATIONNAME%", ignoring "
GOTO end

:ON_AFTER_BACKUP
Expand Down
4 changes: 4 additions & 0 deletions Duplicati/Library/Modules/Builtin/run-script-example.sh
Expand Up @@ -100,6 +100,10 @@
# contain : to separate multiple folders. This value can be changed by echoing
# --localpath = "new value".

# DUPLICATI__PARSED_RESULT
# This is a value indicating how well the operation was performed.
# It can take the values: Unknown, Success, Warning, Error, Fatal.



###############################################################################
Expand Down

1 comment on commit d6aa87e

@duplicatibot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Duplicati. There might be relevant details there:

http://forum.duplicati.com/t/posting-duplicati-backup-events-to-slack-channel/931/6

Please sign in to comment.