From 9cee4a13f0c5886d61296feb05b2d13b79e5249d Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Wed, 12 Feb 2025 09:03:05 +0100 Subject: [PATCH] Renamed to sync-dir.ps1 and updated it --- scripts/{sync-folder.ps1 => sync-dir.ps1} | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) rename scripts/{sync-folder.ps1 => sync-dir.ps1} (75%) diff --git a/scripts/sync-folder.ps1 b/scripts/sync-dir.ps1 similarity index 75% rename from scripts/sync-folder.ps1 rename to scripts/sync-dir.ps1 index c6b8a697..f068cbc6 100755 --- a/scripts/sync-folder.ps1 +++ b/scripts/sync-dir.ps1 @@ -1,16 +1,16 @@ <# .SYNOPSIS - Syncronizes two folders + Sync two dirs .DESCRIPTION This PowerShell script synchronizes (mirrors) the content of 2 directory trees by using Robocopy. Typical use cases are backups: at first everything is copied (full backup), afterward only changes are copied (incremental backup). IMPORTANT NOTE: Make sure the target path is correct because the content gets replaced (DATA LOSS)! .PARAMETER sourcePath - Specifies the path to the source folder + Specifies the path to the source dir (to be entered by default) .PARAMETER targetPath - Specifies the path to the target folder + Specifies the path to the target dir (to be entered by default) .EXAMPLE - PS> ./sync-folder.ps1 C:\MyPhotos D:\Backups\MyPhotos + PS> ./sync-dir.ps1 C:\Photos D:\Backups\Photos .LINK https://github.com/fleschutz/PowerShell .NOTES @@ -20,22 +20,23 @@ param([string]$sourcePath = "", [string]$targetPath = "") try { - if ($sourcePath -eq "") { $sourcePath = Read-Host "Enter the path to the source folder" } - if ($targetPath -eq "") { $targetPath = Read-Host "Enter the path to the target folder" } + if ($sourcePath -eq "") { $sourcePath = Read-Host "Enter the path to the source directory" } + if ($targetPath -eq "") { $targetPath = Read-Host "Enter the path to the target directory" } $stopWatch = [system.diagnostics.stopwatch]::startNew() $robocopyParameters = $sourcePath, $targetPath, '/MIR', '/FFT', '/NDL', '/NP', '/NS' + # # /MIR = mirror a directory tree # /FFT = assume FAT file times (2-second granularity) # /NDL = don't log directory names # /NP = don't display percentage copied # /NS = don't log file sizes - - robocopy.exe $robocopyParameters + # + & robocopy.exe $robocopyParameters if ($lastExitCode -gt 3) { throw 'Robocopy failed.' } [int]$elapsed = $stopWatch.Elapsed.TotalSeconds - "✅ Synced 📂$sourcePath to 📂$targetPath in $elapsed sec" + "✅ Synced 📂$sourcePath to 📂$targetPath in $($elapsed)s." exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"