Created
October 18, 2025 07:18
-
-
Save hitesh83/ec37595c0b2430e29f773662a4877405 to your computer and use it in GitHub Desktop.
Simple Backup Script
This file contains hidden or 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
| # ================================ | |
| # Auto Backup Script - Windows 11 | |
| # ================================ | |
| # === CONFIGURATION === | |
| $SourceFolder = "C:\S1" | |
| $DestinationRoot = "D:\D1" | |
| $DateStamp = Get-Date -Format "dd-MM-yyyy" | |
| $DestinationFolder = Join-Path -Path $DestinationRoot -ChildPath $DateStamp | |
| $ZipFile = Join-Path -Path $DestinationRoot -ChildPath ("backup_{0}.zip" -f $DateStamp) | |
| Write-Host "=== Starting Backup Process ===" -ForegroundColor Cyan | |
| Write-Host "Source: $SourceFolder" | |
| Write-Host "Destination: $DestinationFolder" | |
| Write-Host "Zip Target: $ZipFile" | |
| Write-Host "" | |
| # === 1. Create destination date folder === | |
| if (!(Test-Path -Path $DestinationFolder)) { | |
| New-Item -ItemType Directory -Path $DestinationFolder | Out-Null | |
| Write-Host "Created folder: $DestinationFolder" | |
| } else { | |
| Write-Host "Folder already exists: $DestinationFolder" | |
| } | |
| # === 2. Copy files === | |
| Write-Host "Copying files..." | |
| Copy-Item -Path "$SourceFolder\*" -Destination $DestinationFolder -Recurse -Force | |
| Write-Host "Copy completed." | |
| # === 3. Wait 5 seconds === | |
| Write-Host "Sleeping for 5 seconds..." | |
| Start-Sleep -Seconds 5 | |
| # === 4. Create ZIP backup === | |
| if (Test-Path $ZipFile) { | |
| Write-Host "Removing existing zip file: $ZipFile" | |
| Remove-Item $ZipFile -Force | |
| } | |
| Write-Host "Creating zip archive..." | |
| Compress-Archive -Path $DestinationFolder -DestinationPath $ZipFile -Force | |
| Write-Host "Zip created: $ZipFile" | |
| # === 5. Delete temporary date folder === | |
| Write-Host "Deleting temporary folder: $DestinationFolder" | |
| Remove-Item -Path $DestinationFolder -Recurse -Force | |
| Write-Host "" | |
| Write-Host "✅ Backup completed successfully!" -ForegroundColor Green | |
| Write-Host "" | |
| Write-Host "Press ENTER to exit..." | |
| [void][System.Console]::ReadLine() |
This file contains hidden or 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
| pwsh -ExecutionPolicy Bypass -File "D:\d1\backup.ps1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment