Scheduled Backup of Important Files

This PowerShell script automates the process of backing up important files from a specified source directory to a target backup directory. Scheduling regular backups is essential for data security and integrity, especially for businesses relying on software solutions like ServerEngine. By using this script, users can ensure their critical data remains safe and can be easily restored in case of accidental loss or corruption.

param (
    [string]$sourceDirectory = "C:\ImportantFiles",
    [string]$backupDirectory = "D:\Backups",
    [string]$dateStamp = (Get-Date -Format "yyyy-MM-dd")
)
# Create a new backup folder with today's date
$backupPath = Join-Path -Path $backupDirectory -ChildPath $dateStamp
New-Item -ItemType Directory -Path $backupPath -Force
# Copy files to the backup directory
Copy-Item -Path $sourceDirectory\* -Destination $backupPath -Recurse -Force
Write-Output "Backup completed successfully. Files from $sourceDirectory have been backed up to $backupPath."