Skip to content

Instantly share code, notes, and snippets.

@luckysitara
Created August 21, 2025 09:08
Show Gist options
  • Save luckysitara/8142a6ca5f77fe4bfa18882e615db0c4 to your computer and use it in GitHub Desktop.
Save luckysitara/8142a6ca5f77fe4bfa18882e615db0c4 to your computer and use it in GitHub Desktop.
Backing up windows pc to a remote server

Here is a detailed to set up encrypted, compressed, automated weekly backups from a Windows PC to your Ubuntu server using Restic over SFTP β€” just like we did with your Parrot OS system.


βœ… What You'll Get

  • Only specific folders backed up (you choose)
  • Encrypted and compressed backups using Restic
  • Secure transfer over SSH (SFTP)
  • Automatic weekly backups (using Task Scheduler)
  • Easy restore process

🧱 Step-by-Step Guide for Windows β†’ Ubuntu Server Backups


πŸ–₯️ 1. Install Restic on Windows

  1. Download the latest Restic release: πŸ‘‰ https://restic.net/

  2. Extract the restic.exe file into a folder like:

    C:\Program Files\Restic\
    
  3. Add Restic to the system PATH:

    • Press Win + R, type sysdm.cpl

    • Go to Advanced > Environment Variables

    • Under System Variables, edit Path, add:

      C:\Program Files\Restic\
      
  4. Open a new Command Prompt and test:

    restic version

βœ… If it prints the version, Restic is installed.


πŸ” 2. Set Up SSH Access to Ubuntu Server

You’ll need an SSH key pair for passwordless access.

a. Install OpenSSH client (usually pre-installed)

Check:

where ssh

If not installed:

  • Go to Settings > Apps > Optional Features > Add a feature
  • Add OpenSSH Client

b. Generate SSH key pair

In PowerShell:

ssh-keygen -t ed25519

Press Enter to accept the default path and no passphrase.

This creates:

  • Public key: C:\Users\<YourUsername>\.ssh\id_ed25519.pub
  • Private key: C:\Users\<YourUsername>\.ssh\id_ed25519

c. Copy the public key to your Ubuntu server

Use PowerShell:

type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh backupuser@<server_ip> "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

Test SSH connection:

ssh backupuser@<server_ip>

βœ… You should be logged in without a password.


πŸ“‚ 3. Initialize the Backup Repository (Once)

Set environment variables temporarily in Command Prompt:

set RESTIC_REPOSITORY=sftp:backupuser@<server_ip>:/srv/backups/windows-pc
set RESTIC_PASSWORD=YourStrongPassword

restic init

βœ… If successful, it says:

"created restic repository..."


πŸ“ 4. Create a Restic Backup Script (.bat)

Create a file: C:\Users\<YourUsername>\restic-backup.bat

Example:

@echo off
setlocal

REM === Configuration ===
set RESTIC_REPOSITORY=sftp:backupuser@<server_ip>:/srv/backups/windows-pc
set RESTIC_PASSWORD=YourStrongPassword
set RESTIC_EXCLUDES=%USERPROFILE%\restic-exclude.txt

REM === Run Backup ===
restic backup ^
  "C:\Users\<YourUsername>\Documents" ^
  "C:\Users\<YourUsername>\Pictures" ^
  --exclude-file "%RESTIC_EXCLUDES%"

REM === Forget old backups ===
restic forget --keep-weekly 4 --prune

endlocal

βœ… Change paths as needed.


🚫 5. (Optional) Exclude File Types or Folders

Create: C:\Users\<YourUsername>\restic-exclude.txt

Example content:

*.mp4
*.iso
C:\Users\<YourUsername>\Downloads

πŸ§ͺ 6. Test Your Script

Double-click restic-backup.bat or run it in cmd.

You should see:

  • Files backed up
  • Snapshots created
  • Old ones pruned

βœ… Backup complete!


⏰ 7. Automate Weekly with Task Scheduler

  1. Open Task Scheduler

  2. Create Task

    • General:

      • Name: Weekly Restic Backup
      • Run whether user is logged in or not
      • Run with highest privileges
  3. Trigger:

    • New β†’ Weekly β†’ Monday β†’ 3:00 AM
  4. Action:

    • Program/script: C:\Users\<YourUsername>\restic-backup.bat
  5. Save and enter your Windows password when prompted.

βœ… Now Restic will run automatically each week.


πŸ” 8. Restore Files (When Needed)

To see backups:

restic snapshots

To restore:

restic restore latest --target C:\RestoredFiles

βœ… Done!

You now have automated, encrypted, incremental, compressed backups from Windows to Ubuntu, using only:

  • Restic
  • SSH
  • Task Scheduler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment