# Creating a PowerShell Backup Script for VPS Syncthing Folders

I'm using Robocopy to sync folders with logic to skip unchanged files.

```powershell
# Define source and destination paths
$source1 = "C:\Users\aonat\BookStack-VPS-Backups"
$source2 = "C:\Users\aonat\Default Folder"
$destination = "E:\VPS-Backups"

# Ensure destination exists
if (!(Test-Path -Path $destination)) {
    New-Item -Path $destination -ItemType Directory
}

# Mirror BookStack-VPS-Backups
Robocopy $source1 "$destination\BookStack-VPS-Backups" /MIR /Z /FFT /XA:H /W:5 /R:3 /XO

# Mirror Default Folder
Robocopy $source2 "$destination\Default Folder" /MIR /Z /FFT /XA:H /W:5 /R:3 /XO
```

The only thing that is confusing in the script is all the logic trailing the Robocopy commands. Here is the breakdown of that:

- `/MIR` – Mirrors folder (adds new, removes deleted files)
- `/XO` – Excludes older files (does not overwrite newer destination files)
- `/Z` – Enables restartable mode (safe for external drives)
- `/FFT` – Treats file times as FAT-style (2-second tolerance; good for cross-OS syncing)
- `/XA:H` – Skips hidden files
- `/W:5` / `/R:3` – Waits 5 seconds and retries 3 times on errors

I tested and made sure the script worked as intended:

[![2025-05-17 18_01_57-Administrator_ Windows PowerShell ISE.png](https://docs.natenetworks.com/uploads/images/gallery/2025-05/scaled-1680-/at7mh6uk5Oq92QR5-2025-05-17-18-01-57-administrator-windows-powershell-ise.png)](https://docs.natenetworks.com/uploads/images/gallery/2025-05/at7mh6uk5Oq92QR5-2025-05-17-18-01-57-administrator-windows-powershell-ise.png)

It indeed copied the folders and files I needed:

[![2025-05-17 18_23_57-1TB SSD (E_) and 1 more tab - File Explorer.png](https://docs.natenetworks.com/uploads/images/gallery/2025-05/scaled-1680-/derjQqmAwIXEVjeg-2025-05-17-18-23-57-1tb-ssd-e-and-1-more-tab-file-explorer.png)](https://docs.natenetworks.com/uploads/images/gallery/2025-05/derjQqmAwIXEVjeg-2025-05-17-18-23-57-1tb-ssd-e-and-1-more-tab-file-explorer.png)

[![2025-05-17 18_24_25-screenshots and 1 more tab - File Explorer.png](https://docs.natenetworks.com/uploads/images/gallery/2025-05/scaled-1680-/wEpjlIxGiorXgOIy-2025-05-17-18-24-25-screenshots-and-1-more-tab-file-explorer.png)](https://docs.natenetworks.com/uploads/images/gallery/2025-05/wEpjlIxGiorXgOIy-2025-05-17-18-24-25-screenshots-and-1-more-tab-file-explorer.png)

I then created a task in the Task Scheduler by doing Win + R and entering taskschd.msc

[![2025-05-17 18_02_46-Run.png](https://docs.natenetworks.com/uploads/images/gallery/2025-05/scaled-1680-/qfOZM40KhQj4jbR5-2025-05-17-18-02-46-run.png)](https://docs.natenetworks.com/uploads/images/gallery/2025-05/qfOZM40KhQj4jbR5-2025-05-17-18-02-46-run.png)

Create New Task:

[![2025-05-17 18_03_12-Task Scheduler.png](https://docs.natenetworks.com/uploads/images/gallery/2025-05/scaled-1680-/XqK9H7LvyRpQpqas-2025-05-17-18-03-12-task-scheduler.png)](https://docs.natenetworks.com/uploads/images/gallery/2025-05/XqK9H7LvyRpQpqas-2025-05-17-18-03-12-task-scheduler.png)

Under General Tab create a Name and check the 2 boxes below:

[![2025-05-17 18_04_10-Create Task.png](https://docs.natenetworks.com/uploads/images/gallery/2025-05/scaled-1680-/REhPex7vCOI7x8AS-2025-05-17-18-04-10-create-task.png)](https://docs.natenetworks.com/uploads/images/gallery/2025-05/REhPex7vCOI7x8AS-2025-05-17-18-04-10-create-task.png)

Under the Triggers tab click New, Begin Task at Logon, and for Any User:

[![2025-05-17 18_04_43-Create Task.png](https://docs.natenetworks.com/uploads/images/gallery/2025-05/scaled-1680-/oO1ARx53mS0oO9pD-2025-05-17-18-04-43-create-task.png)](https://docs.natenetworks.com/uploads/images/gallery/2025-05/oO1ARx53mS0oO9pD-2025-05-17-18-04-43-create-task.png)

[![2025-05-17 18_05_30-New Trigger.png](https://docs.natenetworks.com/uploads/images/gallery/2025-05/scaled-1680-/V33A7jeQyzkIcygE-2025-05-17-18-05-30-new-trigger.png)](https://docs.natenetworks.com/uploads/images/gallery/2025-05/V33A7jeQyzkIcygE-2025-05-17-18-05-30-new-trigger.png)

Under the Actions Tab, Click New &gt; Start a Program &gt; powershell.exe

[![2025-05-17 18_08_34-New Action.png](https://docs.natenetworks.com/uploads/images/gallery/2025-05/scaled-1680-/roVMrokJAvdstkoP-2025-05-17-18-08-34-new-action.png)](https://docs.natenetworks.com/uploads/images/gallery/2025-05/roVMrokJAvdstkoP-2025-05-17-18-08-34-new-action.png)

Add this argument script in the Add arguments section replacing the path to the script:

```powershell
-NoProfile -ExecutionPolicy Bypass -File "C:\Path\To\backup-vps-folders.ps1"
```

[![2025-05-17 18_09_29-New Action.png](https://docs.natenetworks.com/uploads/images/gallery/2025-05/scaled-1680-/eBuC9vZlBEAVdEKa-2025-05-17-18-09-29-new-action.png)](https://docs.natenetworks.com/uploads/images/gallery/2025-05/eBuC9vZlBEAVdEKa-2025-05-17-18-09-29-new-action.png)

Under Settings do the following:

[![2025-05-17 18_10_26-Create Task.png](https://docs.natenetworks.com/uploads/images/gallery/2025-05/scaled-1680-/644N3t3hOQhDcgl1-2025-05-17-18-10-26-create-task.png)](https://docs.natenetworks.com/uploads/images/gallery/2025-05/644N3t3hOQhDcgl1-2025-05-17-18-10-26-create-task.png)

Click OK and then it will prompt you for your logon password:

[![2025-05-17 18_11_31-Task Scheduler.png](https://docs.natenetworks.com/uploads/images/gallery/2025-05/scaled-1680-/OQSZYRPYAUUKlfaZ-2025-05-17-18-11-31-task-scheduler.png)](https://docs.natenetworks.com/uploads/images/gallery/2025-05/OQSZYRPYAUUKlfaZ-2025-05-17-18-11-31-task-scheduler.png)

Once you enter that correctly this will run on logon and make sure you have another offsite backup out of Syncthing.