kmwoley / restic-windows-backup

Powershell scripts to run Restic backups on Windows
MIT License
326 stars 66 forks source link

unable to setup task #40

Open si458 opened 3 years ago

si458 commented 3 years ago

Hi All, im not able to create the scheduledtask via the install.ps1, i just keep getting an error?

Register-ScheduledTask : The parameter is incorrect.
At C:\restic\install.ps1:52 char:9
+         Register-ScheduledTask $backup_task_name -Action $task_action
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (PS_ScheduledTask:Root/Mi
   dTask], CimException
    + FullyQualifiedErrorId : HRESULT 0x80070057,Register-ScheduledTask

any suggestions?

kmwoley commented 3 years ago

Can you share your configuration? It would help to know what parameters are being passed to the command to debug.

si458 commented 3 years ago

its just the standard setup with the items set in secret.ps1 like user/pass server etc, changed nothing, will try to get it for you soon, out at mo sorry

si458 commented 3 years ago

Hi @kmwoley, forgive my long delay, im not doing anything special Server 2012 R2, up to date

  1. downloaded the repo and extracted to C:\restic
  2. changed the config.ps1
    # backup configuration
    $ExeName = "restic.exe"
    $InstallPath = "C:\restic"
    $ResticExe = Join-Path $InstallPath $ExeName
    $StateFile = Join-Path $InstallPath "state.xml"
    $WindowsExcludeFile = Join-Path $InstallPath "windows.exclude"
    $LocalExcludeFile = Join-Path $InstallPath "local.exclude"
    $LogPath = Join-Path $InstallPath "logs"
    $LogRetentionDays = 30
    $InternetTestAttempts = 10
    $GlobalRetryAttempts = 4
    # maintenance configuration
    $SnapshotMaintenanceEnabled = $true
    $SnapshotRetentionPolicy = @("--group-by", "host", "--keep-daily", "30", "--keep-weekly", "52", "--keep-monthly", "24", "--keep-yearly", "10")
    $SnapshotPrunePolicy = @("--max-unused", "1%")
    $SnapshotMaintenanceInterval = 7
    $SnapshotMaintenanceDays = 30
    $SnapshotDeepMaintenanceDays = 90;
    # email configuration
    $SendEmailOnSuccess = $false
    $SendEmailOnError = $false
    # Paths to backup
    $BackupSources = @{}
    $BackupSources["C:\"] = @(
    'MyFiles'
    )
    #$BackupSources["D:\"] = @(
    #    'Software'
    #)
  3. copied secret_template.ps1 to secret.ps1 and edited it
    # restic backup repository configuration
    $Env:AWS_ACCESS_KEY_ID='MYLONGID'
    $Env:AWS_SECRET_ACCESS_KEY='MYLONGKEY'
    $Env:RESTIC_REPOSITORY='s3:https://mybackups.server.com/MYBUCKET/MYFOLDER'
    $Env:RESTIC_PASSWORD='password'
    # email configuration
    $PSEmailServer='<SMTP SERVER>'
    $ResticEmailConfig=@{UseSsl=$true; Port="587"}
    $ResticEmailTo='<DESTINATION EMAIL ADDRESS>'
    $ResticEmailFrom='<FROM EMAIL ADDRESS>'
    $ResticEmailUsername='<EMAIL LOGIN USERNAME>'
    $ResticEmailPassword='<EMAIL PASSWORD>'
  4. added the [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 to install.ps1 to allow downloading of the restic.zip
  5. then run powershell as admin, and then cd C:\restic then .\install.ps1 which generates a success but never actually successed?
PS C:\restic> .\install.ps1
Fatal: create key in repository at s3:https://mybackups.server.com/MYBUCKET/MYFOLDER failed:
repository master key and config already initialized

WARNING: [[Init]] Repository initialization failed. Check errors and resolve.
Register-ScheduledTask : The parameter is incorrect.
At C:\restic\install.ps1:52 char:9
+         Register-ScheduledTask $backup_task_name -Action $task_action ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Register-Schedule
   dTask], CimException
    + FullyQualifiedErrorId : HRESULT 0x80070057,Register-ScheduledTask

[[Scheduler]] Backup task scheduled.
PS C:\restic>
kmwoley commented 2 years ago

Can you tell me what language your computer is localized to? There's another issue posted recently that as me wondering if there's a localization issue with the script. Thanks!

si458 commented 2 years ago

Can you tell me what language your computer is localized to? There's another issue posted recently that as me wondering if there's a localization issue with the script. Thanks!

Just English United Kingdom

SLiX69 commented 2 years ago

Same error for me on 2012R2, different language. No error on Server 2019, maybe a Windows 8(.1) specific issue.

Exporting the task on Server 2019 and importing on 2012R2 works.

kmwoley commented 1 year ago

@si458 @SLiX69

Hey folks - I've left this issue open hoping for other folks to chime in and see if they've run into the issue, and hopefully found a fix. Did any of you ever find a solution here?

I don't really want to close this issue, but I don't have a way to test or get to the bottom of this issue without additional help debugging from someone who can reproduce the issue.

killmasta93 commented 11 months ago

hi @kmwoley currently im having the same issue

rkl110 commented 10 months ago

@killmasta93 on my system nothing started, the problem is, the SYSTEM user is not the SYTEM user. Please try to select the right user in task scheduler dialog settings.

geozavl commented 6 months ago

The same issue on standalone Windows Server 2012 R2 Standard

Helps the following fix of principal in install script:

    $task_user = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest

Thanks to https://stackoverflow.com/questions/13965997/powershell-set-a-scheduled-task-to-run-when-user-isnt-logged-in and ChatGPT ))