Skip to content

Instantly share code, notes, and snippets.

@spy86
Created August 3, 2017 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spy86/1336aa1a8f65e30c5b6d1a346cf7d35a to your computer and use it in GitHub Desktop.
Save spy86/1336aa1a8f65e30c5b6d1a346cf7d35a to your computer and use it in GitHub Desktop.
$date = Get-Date -UFormat %Y-%m-%d;
$source = "C:\inetpub\wwwroot\site\Website"
$dest = "C:\Backup\IIS\site_$date"
$exclude = @('temp','app_data')
$destzippath = "C:\Backup\IIS\site\archive_$date.zip"
Write-Host "File backup started."
if(!(Test-Path -Path $dest)) {
New-Item -ItemType directory -Path $dest;
Write-Host "Source: " $source
Write-Host "Destination: " $destzippath
Write-Host "Scanning files ..."
Write-Host "Scanning completed."
Write-Host "Copying files..."
Get-ChildItem $source -Recurse -Exclude $exclude | Copy-Item -Destination {Join-Path $dest $_.FullName.Substring($source.length)}
Add-Type -assembly "system.io.compression.filesystem"
If(Test-path $destzippath) {Remove-item $destzippath}
[io.compression.zipfile]::CreateFromDirectory($dest, $destzippath)
Remove-Item -Recurse -Force $dest
Write-Host "File backup completed."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment