Linux Subsystem
Enable the Windows Subsystem for Linux
From Powershell:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Restart after install
Download a Linux distribution
Windows server doesn't have the windows store, so you'll have to do this manually. Link here:
https://docs.microsoft.com/en-us/windows/wsl/install-manual
Extract and install a Linux distribution
Extract the <distro>.appx package contents, using PowerShell:
Rename-Item .\Debian.appx .\Debian.zip
Expand-Archive .\Debian.zip .\Debian
Move the folder to the location where you want the linux distro to live, then from powershell run the exe from the folder. For example: Debian.exe, or ubuntu.exe
Note: This partition must be NTFS not ReFS
You should then see a prompt:
"Installing, this may take a few minutes..."
Once it's ready, you'll be prompted to create a UNIX username & password:
Add distro to path variable:
$userenv = [System.Environment]::GetEnvironmentVariable("Path", "User")
[System.Environment]::SetEnvironmentVariable("PATH", $userenv + ";C:\Users\Administrator\Ubuntu", "User")
Update and install linux software:
When logged into the distro
sudo su -
apt-get update && apt-get upgrade
apt-get install openssh-client vim zsh
After Linux Setup: Rsync
Setting Up Automatic Login over SSH with Passwordless Public/Private Key Authentication:
ssh-keygen
It is going to ask you for a series of inputs including where to save it & to password protect the key. If you have a directory where you want the files you can put that in or just hit enter for the default .ssh directory. For password protection DO NOT PUT ONE IN. Leave the field empty and just hit enter. A passwordless key pair will be generated:
Once this is done we need to put the public key on our server. The command below will have to be edited to suit your use case but will follow this structure:
ssh-copy-id -i .ssh/id_rsa.pub root@192.168.0.247
With this passwordless public/private key authentication is configured and you'll be given the following prompt:
You can now log into the remote server without supplying a password.
Create the Rsync Script
Create a script on your system that looks something similar to:
#!/bin/bash
# -------------- system commands used by this script -----------------
ID=/usr/bin/id;
ECHO=/bin/echo;
TOUCH=/usr/bin/touch;
RSYNC=/usr/bin/rsync;
RM=/bin/rm;
MV=/bin/mv;
CP=/bin/cp;
# -------------- file locations --------------------------------------
SOURCE="/store/"
DESTINATION="/backup/files/"
EXCLUDES="/backup/bin/exclude-from"
LOG="/backup/bin/backup.log"
# -------------- file server location --------------------------------
USER="user"
SERVER="server.domain.local"
# --------------------------------------------------------------------
# make sure we're running as root
#if (( `$ID -u` != 0 )); then \
#$ECHO "Sorry, must be root. Exiting..."; \
#exit; \
#fi
$RSYNC -avzh -e 'ssh -p 22' --delete --delete-excluded --exclude-from=$EXCLUDES \
--stats --log-file=$LOG $USER@$SERVER:$SOURCE $DESTINATION
You can use a command similar to this to this in the Task Scheduler to launch the script
-cmd /C wsl sh /backup/bin/backup.sh
Resources:
https://docs.microsoft.com/en-us/windows/wsl/install-on-server
https://docs.microsoft.com/en-us/windows/wsl/install-manual
https://gist.github.com/JonasAlfredsson/6bb80ee951c61655424b9bb9f6380c75