added shutdown after backup feature
This commit is contained in:
parent
65dd48b54a
commit
9b940563b1
BIN
snapcontrol.exe
BIN
snapcontrol.exe
Binary file not shown.
@ -83,6 +83,9 @@ LimitIO =
|
|||||||
; should drive/media be ejected after backup ? (yes/no)
|
; should drive/media be ejected after backup ? (yes/no)
|
||||||
EjectMedia = yes
|
EjectMedia = yes
|
||||||
|
|
||||||
|
; should we ask for a shutdown after backup ? (yes/no)
|
||||||
|
AskForShutdown = yes
|
||||||
|
|
||||||
|
|
||||||
[LOGGING]
|
[LOGGING]
|
||||||
LogFile = backup.log
|
LogFile = backup.log
|
||||||
|
@ -29,7 +29,7 @@ EnableGraphicalConsole(0)
|
|||||||
|
|
||||||
Dim filelist$(0)
|
Dim filelist$(0)
|
||||||
|
|
||||||
Global VERSION$="V1.03"
|
Global VERSION$="V1.04"
|
||||||
Global installme = 0
|
Global installme = 0
|
||||||
Global updatesched = 0
|
Global updatesched = 0
|
||||||
Global dryrun = 0
|
Global dryrun = 0
|
||||||
@ -38,6 +38,8 @@ Global jobname$ = "snapcontrol"
|
|||||||
Global month$ = FormatDate("%mm", Date())
|
Global month$ = FormatDate("%mm", Date())
|
||||||
Global day$ = FormatDate("%dd", Date())
|
Global day$ = FormatDate("%dd", Date())
|
||||||
Global DriveSnapshotVersionOk = 0
|
Global DriveSnapshotVersionOk = 0
|
||||||
|
Global DoShutdown = 0
|
||||||
|
Global Shutdowncommand$ = "shutdown /s /f"
|
||||||
|
|
||||||
; valid versions for Drive Snapshot we support ...
|
; valid versions for Drive Snapshot we support ...
|
||||||
NewList DriveSnapshotVersion$()
|
NewList DriveSnapshotVersion$()
|
||||||
@ -99,20 +101,21 @@ Global BinPath$ = ReadPreferenceString("BinPath","c:\tools")
|
|||||||
PreferenceGroup("backup")
|
PreferenceGroup("backup")
|
||||||
Global TargetPath$ = ReadPreferenceString("TargetPath","\\server\share")
|
Global TargetPath$ = ReadPreferenceString("TargetPath","\\server\share")
|
||||||
Global FtpBackup$ = ReadPreferenceString("FtpBackup","no")
|
Global FtpBackup$ = ReadPreferenceString("FtpBackup","no")
|
||||||
Global FtpServer$ = ReadPreferenceString("FtpServer","none")
|
Global FtpServer$ = LCase(ReadPreferenceString("FtpServer","none"))
|
||||||
Global TargetUser$ = ReadPreferenceString("TargetUser","guest")
|
Global TargetUser$ = ReadPreferenceString("TargetUser","guest")
|
||||||
Global TargetPassword$ = ReadPreferenceString("TargetPassword","guest")
|
Global TargetPassword$ = ReadPreferenceString("TargetPassword","guest")
|
||||||
Global BackupschedMode$ = ReadPreferenceString("BackupschedMode","LOGIN")
|
Global BackupschedMode$ = LCase(ReadPreferenceString("BackupschedMode","login"))
|
||||||
Global BackupStart$ = ReadPreferenceString("BackupStart","0005:00")
|
Global BackupStart$ = ReadPreferenceString("BackupStart","0005:00")
|
||||||
Global Disks2Dump$ = ReadPreferenceString("Disks2Dump","HD1:*")
|
Global Disks2Dump$ = ReadPreferenceString("Disks2Dump","HD1:*")
|
||||||
Global ExcludeList$ = ReadPreferenceString("ExcludeList","")
|
Global ExcludeList$ = ReadPreferenceString("ExcludeList","")
|
||||||
Global DumpSize$ = ReadPreferenceString("DumpSize","4095")
|
Global DumpSize$ = ReadPreferenceString("DumpSize","4095")
|
||||||
Global Verify$ = ReadPreferenceString("Verify","yes")
|
Global Verify$ = LCase(ReadPreferenceString("Verify","yes"))
|
||||||
Global BurnTrash$ = ReadPreferenceString("BurnTrash","no")
|
Global BurnTrash$ = LCase(ReadPreferenceString("BurnTrash","no"))
|
||||||
Global Encrypt$ = ReadPreferenceString("Encrypt","no")
|
Global Encrypt$ = LCase(ReadPreferenceString("Encrypt","no"))
|
||||||
Global EncryptPW$ = ReadPreferenceString("EncryptPW","")
|
Global EncryptPW$ = ReadPreferenceString("EncryptPW","")
|
||||||
Global LimitIO$ = ReadPreferenceString("LimitIO","")
|
Global LimitIO$ = ReadPreferenceString("LimitIO","")
|
||||||
Global EjectMedia$ = ReadPreferenceString("EjectMedia","yes")
|
Global EjectMedia$ = LCase(ReadPreferenceString("EjectMedia","yes"))
|
||||||
|
Global AskForShutdown$ = LCase(ReadPreferenceString("AskForShutdown","no"))
|
||||||
|
|
||||||
PreferenceGroup("logging")
|
PreferenceGroup("logging")
|
||||||
Global LogFile$ = ReadPreferenceString("LogFile","backup.log")
|
Global LogFile$ = ReadPreferenceString("LogFile","backup.log")
|
||||||
@ -123,7 +126,7 @@ LogFile$ = InstallTo$ + "\" + LogFile$
|
|||||||
HistLog$ = InstallTo$ + "\" + HistLog$
|
HistLog$ = InstallTo$ + "\" + HistLog$
|
||||||
|
|
||||||
PreferenceGroup("mail")
|
PreferenceGroup("mail")
|
||||||
Global MailReport$ = ReadPreferenceString("MailReport","no")
|
Global MailReport$ = LCase(ReadPreferenceString("MailReport","no"))
|
||||||
Global MailTo$ = ReadPreferenceString("MailTo","")
|
Global MailTo$ = ReadPreferenceString("MailTo","")
|
||||||
Global MailServer$ = ReadPreferenceString("MailServer","")
|
Global MailServer$ = ReadPreferenceString("MailServer","")
|
||||||
Global MailPort = Val(ReadPreferenceString("MailPort",""))
|
Global MailPort = Val(ReadPreferenceString("MailPort",""))
|
||||||
@ -239,7 +242,7 @@ Procedure EndProg(err)
|
|||||||
LogMe("return=" + err)
|
LogMe("return=" + err)
|
||||||
|
|
||||||
; send a report via mail ?
|
; send a report via mail ?
|
||||||
If ( LCase(MailReport$) = "yes" )
|
If ( MailReport$ = "yes" )
|
||||||
LogMe("INFO: sending mail to: " + MailTo$)
|
LogMe("INFO: sending mail to: " + MailTo$)
|
||||||
If ( LogSend(s$, Logfile$) )
|
If ( LogSend(s$, Logfile$) )
|
||||||
LogMe("INFO: mail sent")
|
LogMe("INFO: mail sent")
|
||||||
@ -324,16 +327,16 @@ If ( updatesched = 1 )
|
|||||||
jobcmd$ = ProgramFilename()
|
jobcmd$ = ProgramFilename()
|
||||||
|
|
||||||
; check jobtype ...
|
; check jobtype ...
|
||||||
If ( LCase(BackupschedMode$) <> "login" And LCase(BackupschedMode$) <> "time" )
|
If ( BackupschedMode$ <> "login" And BackupschedMode$ <> "time" )
|
||||||
PrintN("WARNING: unknown BackupschedMode [ " + BackupschedMode$ + " ] ---> IGNORING. Type will be set to LOGIN.")
|
PrintN("WARNING: unknown BackupschedMode [ " + BackupschedMode$ + " ] ---> IGNORING. Type will be set to LOGIN.")
|
||||||
BackupschedMode$ = "LOGIN"
|
BackupschedMode$ = "LOGIN"
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
; update the job ...
|
; update the job ...
|
||||||
PrintN ("Updating windows jobscheduler ...")
|
PrintN ("Updating windows jobscheduler ...")
|
||||||
If ( LCase(BackupschedMode$) = "time" )
|
If ( BackupschedMode$ = "time" )
|
||||||
dummy = system("schtasks /create /F /RL HIGHEST /SC daily /ST " + BackupStart$ + " /TN " + jobname$ + " /TR " + jobcmd$)
|
dummy = system("schtasks /create /F /RL HIGHEST /SC daily /ST " + BackupStart$ + " /TN " + jobname$ + " /TR " + jobcmd$)
|
||||||
ElseIf ( LCase(BackupschedMode$) = "login" )
|
ElseIf ( BackupschedMode$ = "login" )
|
||||||
dummy = system("schtasks /create /F /RL HIGHEST /SC onlogon /DELAY " + BackupStart$ + " /TN " + jobname$ + " /TR " + jobcmd$)
|
dummy = system("schtasks /create /F /RL HIGHEST /SC onlogon /DELAY " + BackupStart$ + " /TN " + jobname$ + " /TR " + jobcmd$)
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
@ -348,15 +351,14 @@ If ( updatesched = 1 )
|
|||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
|
|
||||||
;
|
|
||||||
; ASK the user for permission to start ...
|
|
||||||
;
|
|
||||||
|
|
||||||
; FTP backup requested ?
|
; FTP backup requested ?
|
||||||
If ( FtpBackup$ = "yes" )
|
If ( FtpBackup$ = "yes" )
|
||||||
TargetPath$ = "ftp://" + TargetUser$ + "@" + FtpServer$ + TargetPath$
|
TargetPath$ = "ftp://" + TargetUser$ + "@" + FtpServer$ + TargetPath$
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
|
;
|
||||||
|
; ASK the user for permission to start ...
|
||||||
|
;
|
||||||
Result = MessageRequester("SnapControl",
|
Result = MessageRequester("SnapControl",
|
||||||
"Start BACKUP now?" + Chr(13) +
|
"Start BACKUP now?" + Chr(13) +
|
||||||
"Targetpath => " + TargetPath$,
|
"Targetpath => " + TargetPath$,
|
||||||
@ -370,6 +372,17 @@ If Result = #PB_MessageRequester_No
|
|||||||
End 0
|
End 0
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
|
;
|
||||||
|
; ASK the user for a shutdown ...
|
||||||
|
;
|
||||||
|
Result$ = InputRequester("SnapControl",
|
||||||
|
"SHUTDOWN system after backup?" + Chr(13) +
|
||||||
|
" (type 'yes' or 'no')", "no")
|
||||||
|
|
||||||
|
If LCase(Result$) = "yes"
|
||||||
|
DoShutdown = 1
|
||||||
|
EndIf
|
||||||
|
|
||||||
|
|
||||||
; cleanup: delete old Logfile, remove old drive letter...
|
; cleanup: delete old Logfile, remove old drive letter...
|
||||||
dummy = DeleteFile(LogFile$, #PB_FileSystem_Force)
|
dummy = DeleteFile(LogFile$, #PB_FileSystem_Force)
|
||||||
@ -396,7 +409,7 @@ EndIf
|
|||||||
;
|
;
|
||||||
|
|
||||||
; encryption enabled ?
|
; encryption enabled ?
|
||||||
If ( LCase(Encrypt$) = "yes" )
|
If ( Encrypt$ = "yes" )
|
||||||
params$ = "-PW=" + EncryptPW$ + " "
|
params$ = "-PW=" + EncryptPW$ + " "
|
||||||
If ( EncryptPW$ = "" )
|
If ( EncryptPW$ = "" )
|
||||||
LogMe("WARNING: ENCRYPTED backup requested but PASSWORD is not set in infile !")
|
LogMe("WARNING: ENCRYPTED backup requested but PASSWORD is not set in infile !")
|
||||||
@ -406,7 +419,7 @@ If ( LCase(Encrypt$) = "yes" )
|
|||||||
EndIf
|
EndIf
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
If ( LCase(Encrypt$) = "dynamic" )
|
If ( Encrypt$ = "dynamic" )
|
||||||
If ( EncryptPW$ = "" )
|
If ( EncryptPW$ = "" )
|
||||||
EncryptPW$ = mkpass(20)
|
EncryptPW$ = mkpass(20)
|
||||||
LogMe("WARNING: ENCRYPTED backup requested and DYNAMIC password was requested !")
|
LogMe("WARNING: ENCRYPTED backup requested and DYNAMIC password was requested !")
|
||||||
@ -427,12 +440,12 @@ If ( LimitIO$ <> "" )
|
|||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
; verify the backup ?
|
; verify the backup ?
|
||||||
If ( LCase(Verify$) = "yes" )
|
If ( Verify$ = "yes" )
|
||||||
params$ + "-T "
|
params$ + "-T "
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
; burn all the trash in the recyclebin ?
|
; burn all the trash in the recyclebin ?
|
||||||
If ( LCase(BurnTrash$) = "yes" )
|
If ( BurnTrash$ = "yes" )
|
||||||
params$ + "-R "
|
params$ + "-R "
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
@ -532,6 +545,13 @@ LogMe(" LogFile: [ " + LogFile$ + " ]")
|
|||||||
|
|
||||||
If ( dryrun = 0 )
|
If ( dryrun = 0 )
|
||||||
e = system(SnapshotBin$ + " --Logfile:" + LogFile$ + " " + params$ + " " + DumpFile$ + " " + HashFile$)
|
e = system(SnapshotBin$ + " --Logfile:" + LogFile$ + " " + params$ + " " + DumpFile$ + " " + HashFile$)
|
||||||
|
|
||||||
|
If DoShutdown = 1
|
||||||
|
LogMe("INFO: shutdown was requested ...")
|
||||||
|
LogMe("INFO: executing [ " + ShutdownCommand$ + " ]")
|
||||||
|
e = system(ShutdownCommand$)
|
||||||
|
EndIf
|
||||||
|
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
; end with return code...
|
; end with return code...
|
||||||
@ -539,8 +559,8 @@ EndProg(e)
|
|||||||
|
|
||||||
; IDE Options = PureBasic 5.73 LTS (Windows - x64)
|
; IDE Options = PureBasic 5.73 LTS (Windows - x64)
|
||||||
; ExecutableFormat = Console
|
; ExecutableFormat = Console
|
||||||
; CursorPosition = 526
|
; CursorPosition = 384
|
||||||
; FirstLine = 500
|
; FirstLine = 351
|
||||||
; Folding = --
|
; Folding = --
|
||||||
; EnableXP
|
; EnableXP
|
||||||
; Executable = snapcontrol.exe
|
; Executable = snapcontrol.exe
|
||||||
|
Loading…
Reference in New Issue
Block a user