-
-
Save tonymet/816290ca37eab78353c9b760d127ee31 to your computer and use it in GitHub Desktop.
backup wsl to onedrive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# backup wsl contents on a schedule | |
# set & truncate $logfile | |
$logfile="$HOME\backup-wsl.log.txt" | |
if ((Get-Item $logfile).length -gt 128000){ | |
Remove-Item $logfile | |
} | |
$src="\\wsl.localhost\Debian\home\${env:Username}\sotion" | |
$dest=$(Join-Path ${env:OneDrive} "Documents\Sotion") | |
Write-EventLog -LogName Application -Source "Backup-WSL" -EventID 3001 -Message "Starting Backup" | |
$t0=(Get-Date) | |
robocopy $src $dest /W:1 /R:0 /E /xd node_modules /NFL /NDL /LOG+:$logfile | |
$exitcoderobo=$LASTEXITCODE | |
$t1=(Get-Date) | |
$delta =($t1-$t0) | |
$message="Finished Backup. Duration = $delta" | |
if($exitcoderobo -ne 0){ | |
$message="ERROR: Finished Backup. Backup failed. Duration = $delta . Check $logfile for error" | |
} | |
Write-EventLog -LogName Application -Source "Backup-WSL" -EventID 3001 -Message $message | |
exit $exitcoderobo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
New-EventLog -LogName Application -Source "Backup-WSL" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$time = New-ScheduledTaskTrigger -Daily -At 2pm | |
$user = (whoami) | |
$action = New-ScheduledTaskAction -Execute "${env:ProgramFiles}\PowerShell\7\pwsh.exe" -Argument "-noninteractive -nologo -noprofile $HOME\scripts\backup-wsl\backup-wsl.ps1" | |
Register-ScheduledTask -TaskName "Backup-WSL" -Trigger $Time -User $User -Action $action |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment