Skip to content

Commit 384fd79

Browse files
committed
added profile feature to scheduled task creation
1 parent b6c961a commit 384fd79

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

SimpleBackup.au3

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#AutoIt3Wrapper_UseX64=y
55
#AutoIt3Wrapper_Change2CUI=y
66
#AutoIt3Wrapper_Res_Description=SimpleBackup
7-
#AutoIt3Wrapper_Res_Fileversion=1.0.0.212
7+
#AutoIt3Wrapper_Res_Fileversion=1.0.0.215
88
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
99
#AutoIt3Wrapper_Res_ProductVersion=1
1010
#AutoIt3Wrapper_Res_LegalCopyright=SimpleBackup
@@ -56,6 +56,7 @@ Global $RequiredSettings = "Setup_Password|Backup_Path|Backup_Prune|RESTIC_REPOS
5656
Global $SettingsTemplate = $RequiredSettings & "|AWS_ACCESS_KEY_ID|AWS_SECRET_ACCESS_KEY|RESTIC_READ_CONCURRENCY=4|RESTIC_PACK_SIZE=32|" & $SMTPSettings
5757
Global $ConfigFile = StringTrimRight(@ScriptName, 4) & ".dat"
5858
Global $ConfigFileFullPath = @ScriptDir & "\" & $ConfigFile
59+
Global $ActiveProfile = "Default"
5960

6061
; $RunSTDIO will determine how we execute restic, if this is not done properly we will miss console output or log output
6162
; This value changes depending on program contexts to give us the most aplicable output
@@ -87,6 +88,7 @@ For $i = 1 To $CmdLine[0]
8788
; The profile parameter and the following parameter are used to adjust the
8889
$i = $i + 1
8990
$ConfigFileFullPath = StringTrimRight($ConfigFileFullPath, 4) & "." & $CmdLine[$i] & ".dat"
91+
$ActiveProfile = $CmdLine[$i]
9092
_ConsoleWrite("Config file is now " & StringTrimLeft($ConfigFileFullPath, StringInStr($ConfigFileFullPath, "\", 0, -1)))
9193

9294
Case Else
@@ -211,7 +213,7 @@ While 1
211213

212214
; Setup tools menu
213215
$g_hTools = _GUICtrlMenu_CreateMenu()
214-
_GUICtrlMenu_InsertMenuItem($g_hTools, -1, "Create/Reset Scheduled Task", $ScheduledTaskMenuItem)
216+
_GUICtrlMenu_InsertMenuItem($g_hTools, -1, "Create/Reset Scheduled Task (Profile: " & $ActiveProfile & ")", $ScheduledTaskMenuItem)
215217
_GUICtrlMenu_InsertMenuItem($g_hTools, -1, "Open Restic Browser", $BrowserMenuItem)
216218
_GUICtrlMenu_InsertMenuItem($g_hTools, -1, "Add Missing Configuration Options From Template", $TemplateMenuItem)
217219

@@ -313,6 +315,9 @@ While 1
313315

314316
_ConsoleWrite("$ConfigFileFullPath=" & $ConfigFileFullPath, 3)
315317

318+
$ActiveProfile = StringTrimRight(StringTrimLeft($ConfigFileFullPath, StringInStr($ConfigFileFullPath, "\", 0, -1) + StringLen($Title) + 1), 4)
319+
_ConsoleWrite("$ActiveProfile=" & $ActiveProfile, 3)
320+
316321
; Delete the GUI and restart
317322
GUIDelete($SettingsForm)
318323
ContinueLoop 2
@@ -329,7 +334,7 @@ While 1
329334
$EnvPath = EnvGet("Path")
330335
If Not StringInStr($EnvPath, $TempDir) Then
331336
EnvSet("Path", $TempDir & ";" & $EnvPath)
332-
_ConsoleWrite("EnvSet: "&@error)
337+
_ConsoleWrite("EnvSet: "&@error, 3)
333338
EndIf
334339

335340
; Verify the hash of the restic-browser.exe
@@ -344,13 +349,22 @@ While 1
344349
$ResticBrowserPid = Run($ResticBrowserFullPath)
345350

346351
Case $ScheduledTaskMenuItem
347-
$Run = "SCHTASKS /CREATE /SC DAILY /TN " & $Title & " /TR ""'" & @ScriptFullPath & "' backup"" /ST 22:00 /RL Highest /NP /F /RU System"
352+
If $ActiveProfile <> "Default" Then
353+
$ProfileSwitch = " profile " & $ActiveProfile
354+
$TaskName = "." & $ActiveProfile
355+
Else
356+
$ProfileSwitch = ""
357+
$TaskName = ""
358+
EndIf
359+
360+
$Run = "SCHTASKS /CREATE /SC DAILY /TN " & $Title & $TaskName & " /TR ""'" & @ScriptFullPath & "' backup" & $ProfileSwitch & """ /ST 22:00 /RL Highest /NP /F /RU System"
348361
_ConsoleWrite($Run)
349362
$Return = _RunWait($Run, @ScriptDir, @SW_SHOW, $STDERR_MERGED, True)
350363
If StringInStr($Return, "SUCCESS: ") Then
351364
MsgBox(0, $TitleVersion, "Scheduled task created. Please review and test the task.")
352365
Else
353366
MsgBox($MB_ICONERROR, $TitleVersion, "Error creating scheduled task.")
367+
If @Compiled Then MsgBox($MB_ICONERROR, $TitleVersion, "Are you running without admin?")
354368
EndIf
355369

356370

0 commit comments

Comments
 (0)