Skip to content

Commit

Permalink
updated - scheduled backup and task fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Robomikel committed Aug 3, 2022
1 parent 3ff1bf0 commit 90ac55d
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 59 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ Install miscreated server ```./ssm install misserver```
- ```./ssm restore <serverFolder>``` - Lists zip folder backups of server files in backups folder and overwrites serverfiles with backup files.
- ```./ssm install-monitor <serverFolder>``` - Creates Scheduled Task to monitor server
- ```./ssm install-restart <serverFolder>``` - create scheduled task to restart server daily.
- ```./ssm install-backup <serverFolder>``` - create scheduled task to backup server daily.
- ```./ssm install-mod <serverFolder>``` - Install Sourcemod or Oxide for specified servers
- ```./ssm update-mods <serverFolder>``` - updates mods and plugins for server
- ```./ssm install-ws <serverFolder>``` - Workshop Install
Expand Down
61 changes: 61 additions & 0 deletions functions/check_backupfolder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,64 @@ Function New-BackupFolder {
Get-warnmessage "backupfnfailed"
}
}
Function New-BackupJobBG {
Write-log "Function: $($MyInvocation.Mycommand)"
If ($env:UserName -and $env:COMPUTERNAME) {
$UserName = "$env:COMPUTERNAME\$env:UserName"
Write-Host "Run Task Whether user is logged on or not" -F Cyan -NoNewline
Write-Host "Input Daily Backup Time. i.e. 3am: " -F Cyan -NoNewline
$restartTime = Read-Host
If ($restartTime) {
Write-Host "Username: $env:COMPUTERNAME\$env:UserName"
$SecurePassword = Read-Host "Password:" -AsSecureString
If ($UserName -and $SecurePassword) {
If ((Test-Path "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe")) {
$posh = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $SecurePassword
$Password = $Credentials.GetNetworkCredential().Password
$Action = New-ScheduledTaskAction -Execute "$posh" -Argument "$currentdir\ssm.ps1 backup $serverfiles" -WorkingDirectory "$currentdir"
#$Trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).Date -RepetitionInterval (New-TimeSpan -Minutes $restartTime)
$Trigger = New-ScheduledTaskTrigger -Daily -At $restartTime
$Settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit '00:00:00'
$Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings
Get-Infomessage "Creating Task" 'start'
Register-ScheduledTask -TaskName "$serverfiles $command" -InputObject $Task -User "$UserName" -Password "$Password" -ea SilentlyContinue | Out-File -Append -Encoding Default $ssmlog
If ($?) {
clear-hostline 1
Get-Infomessage "Creating Task" 'done'
}
Else {
clear-hostline 1
Get-Infomessage "Creating Task" $false
}
}
}
}
}
}
Function New-BackupJob {
Write-log "Function: $($MyInvocation.Mycommand)"
Write-Host "Run Task only when user is logged on" -F Cyan -NoNewline
Write-Host "Input Daily Backup Time. i.e. 3am: " -F Cyan -NoNewline
$restartTime = Read-Host
If ($restartTime) {
If ((Test-Path "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe")) {
$posh = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$Action = New-ScheduledTaskAction -Execute "$posh" -Argument "$currentdir\ssm.ps1 backup $serverfiles" -WorkingDirectory "$currentdir"
#$Trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).Date -RepetitionInterval (New-TimeSpan -Hours $restartTime)
$Trigger = New-ScheduledTaskTrigger -Daily -At $restartTime
$Settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit '00:00:00'
$Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings
Get-Infomessage "Creating Task" 'start'
Register-ScheduledTask -TaskName "$serverfiles $command" -InputObject $Task | Out-File -Append -Encoding Default $ssmlog
If ($?) {
clear-hostline 1
Get-Infomessage "Creating Task" 'done'
}
Else {
clear-hostline 1
Get-Infomessage "Creating Task" $false
}
}
}
}
71 changes: 40 additions & 31 deletions functions/command_autorestart.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,32 @@ Function New-RestartJobBG {
If ($env:UserName -and $env:COMPUTERNAME) {
$UserName = "$env:COMPUTERNAME\$env:UserName"
Write-Host "Run Task Whether user is logged on or not" -F Cyan -NoNewline
Write-Host "Input AutoRestart Time. ie 3am: " -F Cyan -NoNewline
Write-Host "Input AutoRestart Time. i.e. 3am: " -F Cyan -NoNewline
$restartTime = Read-Host
If ($restartTime) {
Write-Host "Username: $env:COMPUTERNAME\$env:UserName"
$SecurePassword = $password = Read-Host "Password:" -AsSecureString
If ($UserName -and $SecurePassword) {
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $SecurePassword
$Password = $Credentials.GetNetworkCredential().Password
$Action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "$currentdir\ssm.ps1 restart $serverfiles" -WorkingDirectory "$currentdir"
#$Trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).Date -RepetitionInterval (New-TimeSpan -Minutes $restartTime)
$Trigger = New-ScheduledTaskTrigger -Daily -At $restartTime
$Settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit '00:00:00'
$Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings
Get-Infomessage "Creating Task" 'start'
Register-ScheduledTask -TaskName "$serverfiles $command" -InputObject $Task -User "$UserName" -Password "$Password" -ea SilentlyContinue | Out-File -Append -Encoding Default $ssmlog
If ($?){
clear-hostline 1
Get-Infomessage "Creating Task" 'done'
} Else{
clear-hostline 1
Get-Infomessage "Creating Task" $false
$SecurePassword = Read-Host "Password:" -AsSecureString
# C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
If ((Test-Path "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe")) {
$posh = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
If ($UserName -and $SecurePassword) {
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $SecurePassword
$Password = $Credentials.GetNetworkCredential().Password
$Action = New-ScheduledTaskAction -Execute "$posh" -Argument "$currentdir\ssm.ps1 restart $serverfiles" -WorkingDirectory "$currentdir"
#$Trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).Date -RepetitionInterval (New-TimeSpan -Minutes $restartTime)
$Trigger = New-ScheduledTaskTrigger -Daily -At $restartTime
$Settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit '00:00:00'
$Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings
Get-Infomessage "Creating Task" 'start'
Register-ScheduledTask -TaskName "$serverfiles $command" -InputObject $Task -User "$UserName" -Password "$Password" -ea SilentlyContinue | Out-File -Append -Encoding Default $ssmlog
If ($?) {
clear-hostline 1
Get-Infomessage "Creating Task" 'done'
}
Else {
clear-hostline 1
Get-Infomessage "Creating Task" $false
}
}
}
}
Expand All @@ -43,19 +48,23 @@ Function New-RestartJob {
Write-Host "Input AutoRestart Time. ie 3am: " -F Cyan -NoNewline
$restartTime = Read-Host
If ($restartTime) {
$Action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "$currentdir\ssm.ps1 restart $serverfiles" -WorkingDirectory "$currentdir"
#$Trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).Date -RepetitionInterval (New-TimeSpan -Hours $restartTime)
$Trigger = New-ScheduledTaskTrigger -Daily -At $restartTime
$Settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit '00:00:00'
$Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings
Get-Infomessage "Creating Task" 'start'
Register-ScheduledTask -TaskName "$serverfiles $command" -InputObject $Task | Out-File -Append -Encoding Default $ssmlog
If ($?){
clear-hostline 1
Get-Infomessage "Creating Task" 'done'
} Else{
clear-hostline 1
Get-Infomessage "Creating Task" $false
If ((Test-Path "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe")) {
$posh = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$Action = New-ScheduledTaskAction -Execute "$posh" -Argument "$currentdir\ssm.ps1 restart $serverfiles" -WorkingDirectory "$currentdir"
#$Trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).Date -RepetitionInterval (New-TimeSpan -Hours $restartTime)
$Trigger = New-ScheduledTaskTrigger -Daily -At $restartTime
$Settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit '00:00:00'
$Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings
Get-Infomessage "Creating Task" 'start'
Register-ScheduledTask -TaskName "$serverfiles $command" -InputObject $Task | Out-File -Append -Encoding Default $ssmlog
If ($?) {
clear-hostline 1
Get-Infomessage "Creating Task" 'done'
}
Else {
clear-hostline 1
Get-Infomessage "Creating Task" $false
}
}
}
}
1 change: 1 addition & 0 deletions functions/core_commands.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Function Select-Steamer {
'install-mod' { Read-Param; Get-FolderNames; Get-createdvaribles; Get-CheckForVars; Get-SevenZipCheck; Get-Modinstall; Test-VariablesNull; Get-ClearVariables; Break }
'install-ws' { Read-Param; Get-FolderNames; Get-createdvaribles; Get-CheckForVars; Install-SteamWS; Test-VariablesNull; Get-ClearVariables; Break }
'install-Restart' { Read-Param; Get-FolderNames; Get-createdvaribles; Get-CheckForVars; Set-RestartJob; Test-VariablesNull; Get-ClearVariables; Break }
'install-backup' { Read-Param; Get-FolderNames; Get-createdvaribles; Get-CheckForVars; Set-BackupJob; Test-VariablesNull; Get-ClearVariables; Break }
'query' { Read-Param; Get-NodeJSCheck; Get-FolderNames; Get-createdvaribles; Get-CheckForVars; Get-GamedigServerv2; Test-VariablesNull; Get-ClearVariables; Break }
'mcrcon' { Read-Param; Get-FolderNames; Get-createdvaribles ; Get-CheckForVars; Get-MCRconCheck; set-connectMCRcon; Test-VariablesNull; Get-ClearVariables; Break }
'discord' { Read-Param; Get-FolderNames; Get-createdvaribles; Get-CheckForVars; New-DiscordAlert; Test-VariablesNull; Get-ClearVariables; Break }
Expand Down
19 changes: 19 additions & 0 deletions functions/core_questions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,25 @@ Function Set-RestartJob {
New-RestartJob
}
}
Function Set-BackupJob {
Write-log "Function: $($MyInvocation.Mycommand)"
$title = 'Create Backup Task Job'
$question = 'Run Task Whether user is logged on or not?'
$choices = New-Object Collections.ObjectModel.Collection[Management.Automation.Host.ChoiceDescription]
$choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&Yes'))
$choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&No'))
$decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
If ($decision -eq 0) {
Write-Host 'Entered Y'
Get-ChecktaskUnreg
New-BackupJobBG
}
Else {
Write-Host 'Entered N'
Get-ChecktaskUnreg
New-BackupJob
}
}
Function New-AppDataSave {
Write-log "Function: $($MyInvocation.Mycommand)"
$title = 'Game has Saves located in AppData'
Expand Down
61 changes: 34 additions & 27 deletions functions/install_monitor.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@
Function New-MontiorJob {
Write-log "Function: $($MyInvocation.Mycommand)"
Write-Host "Run Task only when user is logged on"
$Action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "`"If (!(Get-Process '$process')) {$currentdir\ssm.ps1 monitor $serverfiles }`"" -WorkingDirectory "$currentdir"
$Trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).Date -RepetitionInterval (New-TimeSpan -Minutes 5)
$Settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit '00:00:00'
$Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings
Get-Infomessage "Creating Task" 'start'
Register-ScheduledTask -TaskName "$serverfiles $command" -InputObject $Task | Out-File -Append -Encoding Default $ssmlog
If ($?){
clear-hostline 1
Get-Infomessage "Creating Task" 'done'
} Else{
clear-hostline 1
Get-Infomessage "Creating Task" $false
If ((Test-Path "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe")) {
$posh = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$Action = New-ScheduledTaskAction -Execute "$posh" -Argument "`"If (!(Get-Process '$process')) {$currentdir\ssm.ps1 monitor $serverfiles }`"" -WorkingDirectory "$currentdir"
$Trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).Date -RepetitionInterval (New-TimeSpan -Minutes 5)
$Settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit '00:00:00'
$Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings
Get-Infomessage "Creating Task" 'start'
Register-ScheduledTask -TaskName "$serverfiles $command" -InputObject $Task | Out-File -Append -Encoding Default $ssmlog
If ($?) {
clear-hostline 1
Get-Infomessage "Creating Task" 'done'
}
Else {
clear-hostline 1
Get-Infomessage "Creating Task" $false
}
}
}
Function New-MontiorJobBG {
Expand All @@ -30,23 +34,26 @@ Function New-MontiorJobBG {
$UserName = "$env:COMPUTERNAME\$env:UserName"
Write-Host "Run Task Whether user is logged on or not"
Write-Host "Username: $env:COMPUTERNAME\$env:UserName"
$SecurePassword = Read-Host "Password " -AsSecureString
$SecurePassword = Read-Host "Password: " -AsSecureString
If ($UserName -and $SecurePassword) {
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $SecurePassword
$Action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "`"If (!(Get-Process '$process')) {$currentdir\ssm.ps1 monitor $serverfiles }`"" -WorkingDirectory "$currentdir"
$Trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).Date -RepetitionInterval (New-TimeSpan -Minutes 5)
$Settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit '00:00:00'
$Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings
Get-Infomessage "Creating Task" 'start'
Register-ScheduledTask -TaskName "$serverfiles $command" -InputObject $Task -User "$UserName" -Password "$($Credentials.GetNetworkCredential().Password)" | Out-File -Append -Encoding Default $ssmlog
If ($?){
clear-hostline 1
Get-Infomessage "Creating Task" 'done'
} Else{
clear-hostline 1
Get-Infomessage "Creating Task" $false
If ((Test-Path "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe")) {
$posh = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $SecurePassword
$Action = New-ScheduledTaskAction -Execute "$posh" -Argument "`"If (!(Get-Process '$process')) {$currentdir\ssm.ps1 monitor $serverfiles }`"" -WorkingDirectory "$currentdir"
$Trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).Date -RepetitionInterval (New-TimeSpan -Minutes 5)
$Settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit '00:00:00'
$Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings
Get-Infomessage "Creating Task" 'start'
Register-ScheduledTask -TaskName "$serverfiles $command" -InputObject $Task -User "$UserName" -Password "$($Credentials.GetNetworkCredential().Password)" | Out-File -Append -Encoding Default $ssmlog
If ($?) {
clear-hostline 1
Get-Infomessage "Creating Task" 'done'
}
Else {
clear-hostline 1
Get-Infomessage "Creating Task" $false
}
}

}
}
}
2 changes: 1 addition & 1 deletion ssm.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
#
param(
[ValidateSet('install', 'update', 'force-update', 'validate', 'start', 'stop', 'restart', 'monitor', 'backup', 'restore', 'install-monitor', 'install-mod', 'install-ws', 'install-restart', 'query', 'mcrcon', 'discord', 'details', 'install-vcredist', 'stats', 'menu', 'exit', 'ssm', 'update-mods','start-pode')]
[ValidateSet('install', 'update', 'force-update', 'validate', 'start', 'stop', 'restart', 'monitor', 'backup', 'restore', 'install-monitor', 'install-mod', 'install-ws', 'install-restart', 'install-backup', 'query', 'mcrcon', 'discord', 'details', 'install-vcredist', 'stats', 'menu', 'exit', 'ssm', 'update-mods','start-pode')]
[Parameter(ParameterSetName = "steamer", Position = 0)]
[string]$command,
[Parameter(ParameterSetName = "steamer", Position = 1)]
Expand Down

0 comments on commit 90ac55d

Please sign in to comment.