Skip to content
Permalink
Browse files

Updated the run-script module to report the parsed result level.

This fixes #2656
  • Loading branch information...
kenkendk committed Sep 1, 2017
1 parent 80d533b commit d6aa87e00390bff74c9e87119fe33869fdf823be
@@ -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
@@ -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
@@ -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
{
@@ -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;
@@ -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 ###############################################################################
@@ -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
@@ -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.



###############################################################################

1 comment on commit d6aa87e

@duplicatibot

This comment has been minimized.

Copy link

commented on d6aa87e Oct 8, 2017

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.
You can’t perform that action at this time.