How to back up IIS websites and databases on Windows Server

Back up IIS websites and databases properly: site files, IIS configuration, MySQL/MariaDB and SQL Server dumps, offsite copies to S3, and restore tests.

Cover image: How to back up IIS websites and databases on Windows Server

Key takeaways

  • A full backup of an IIS server has four parts: site files, IIS configuration, database dumps and an offsite copy.
  • Use mariadb-dump or mysqldump with --single-transaction, and SQL Server BACKUP DATABASE WITH COPY_ONLY so you do not break an existing backup chain.
  • Keep at least one copy off the server, encrypted, and keep the encryption key somewhere else.
  • A backup you have never restored is a guess: restore into a test site on a schedule.

To back up IIS websites and databases you need four things: a copy of each site's files, a copy of the IIS configuration, a consistent dump of every database, and a copy of all of it somewhere other than the server. Then you need to prove it works by restoring. This guide shows each step with commands for Windows Server 2019, 2022 and 2025, and ends with how Zopanel for Windows does the same.

How to back up IIS websites and databases: what to include

Part Where it lives Tool
Site files Each site's physical path, for example D:\sites\example.com robocopy, VSS
IIS configuration C:\Windows\System32\inetsrv\config\applicationHost.config and each site's web.config appcmd add backup
Certificates The LocalMachine\My store Export-PfxCertificate
MySQL / MariaDB The database server's data folder mariadb-dump or mysqldump
SQL Server .mdf / .ldf files BACKUP DATABASE
Offsite copy S3 or another server aws s3 cp, rclone, SFTP

Never copy a running database's data files and call it a backup. Use the database's own dump or backup command.

Step 1: back up the IIS configuration

IIS keeps its own configuration snapshots. Take one before every change and as part of each backup:

& "$env:windir\System32\inetsrv\appcmd.exe" add backup "nightly-$(Get-Date -Format yyyyMMdd)"
& "$env:windir\System32\inetsrv\appcmd.exe" list backup

The snapshot goes to C:\Windows\System32\inetsrv\backup\. Copy that folder with the rest of the backup. To restore: appcmd restore backup "nightly-20261127".

IIS also keeps automatic history copies of applicationHost.config in C:\inetpub\history. They help after a bad edit, but they are on the same disk, so they are not a backup.

Export certificates with their private keys if the keys are exportable:

$pw = Read-Host -AsSecureString 'PFX password'
Get-ChildItem Cert:\LocalMachine\My | Where-Object HasPrivateKey | ForEach-Object {
  Export-PfxCertificate -Cert $_ -FilePath "E:\backup\certs\$($_.Thumbprint).pfx" -Password $pw
}

Let's Encrypt certificates can simply be issued again, so many setups skip them.

Step 2: back up site files

robocopy copies changed files only and keeps NTFS permissions with /COPYALL:

robocopy D:\sites E:\backup\sites /MIR /COPYALL /R:1 /W:1 /XJ /NP /LOG:E:\backup\sites.log
  • /MIR makes the target match the source, including deletions, so keep several dated copies or a versioned offsite store; a mirror alone will happily copy a ransomware-encrypted folder.
  • /XJ skips junctions, so a junction a customer creates cannot pull in files from outside their site.
  • Files that are open and locked (some SQLite databases, logs) are skipped. Volume Shadow Copy (VSS) solves this by copying from a snapshot.

Step 3: dump MySQL and MariaDB

For InnoDB tables, --single-transaction gives a consistent dump without locking the site:

$out = "E:\backup\db\shop-$(Get-Date -Format yyyyMMdd-HHmm).sql"
mariadb-dump --single-transaction --routines --triggers --events `
  -h 127.0.0.1 -u backup -p shop --result-file=$out

On MySQL use mysqldump with the same options. Give the backup user read rights only (SELECT, SHOW VIEW, TRIGGER, EVENT, LOCK TABLES), not root. To avoid a password on the command line, put it in an option file readable only by Administrators and pass --defaults-extra-file.

Restore with:

cmd /c "mariadb -h 127.0.0.1 -u root -p shop_restored < `"$out`""

Use cmd /c for the redirect: Windows PowerShell 5.1 has no < operator, and piping a large dump through Get-Content is slow and can change its encoding.

Step 4: back up SQL Server databases

Use COPY_ONLY so an ad hoc or panel backup does not interfere with someone else's differential or log backup chain:

sqlcmd -S .\SQLEXPRESS -E -Q "BACKUP DATABASE [shop] TO DISK = N'E:\backup\db\shop.bak' WITH COPY_ONLY, CHECKSUM, INIT"
sqlcmd -S .\SQLEXPRESS -E -Q "RESTORE VERIFYONLY FROM DISK = N'E:\backup\db\shop.bak' WITH CHECKSUM"

SQL Server Express has no SQL Agent, so schedule the command with Task Scheduler. The SQL Server service account needs write access to the target folder.

Step 5: copy offsite and encrypt

A backup on the same server dies with the server. Copy it somewhere else, encrypted:

aws s3 cp E:\backup s3://my-backups/web01/$(Get-Date -Format yyyyMMdd)/ --recursive --sse AES256

Better still, encrypt before upload (for example with a 7-Zip archive and a long password, or a tool that encrypts client-side) and store the key away from both the server and the bucket. Turn on versioning or object lock on the bucket so that a compromised server cannot delete old backups.

Step 6: schedule it

Wrap steps 1 to 5 in one script and run it from Task Scheduler as SYSTEM:

$action  = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NoProfile -ExecutionPolicy Bypass -File C:\scripts\backup.ps1'
$trigger = New-ScheduledTaskTrigger -Daily -At 2am
Register-ScheduledTask -TaskName 'Nightly web backup' -Action $action -Trigger $trigger -User 'SYSTEM' -RunLevel Highest

Make the script exit with a non-zero code on any failure and send you an alert, otherwise a broken backup goes unnoticed for months.

Step 7: test restores

Pick one site a month and restore it into a separate test site: files into a new folder, the dump into a new database, and browse it on a hostname only you use. Write down how long it took. That number is your real recovery time.

FAQ

Is a VPS snapshot enough?

It helps, but it is usually on the same provider, it captures databases mid-write unless the provider coordinates with VSS, and you cannot restore one site from it easily. Use it in addition to file and database backups.

How long should I keep backups?

A common pattern is 7 daily and 4 weekly copies. Keep fewer on the server and more offsite.

Should I back up the whole C: drive?

For a web server, rebuilding Windows and IIS is usually faster than restoring a full system image. Back up the data and configuration, and keep the rebuild steps written down.

Why COPY_ONLY for SQL Server?

A normal full backup resets the base for differential backups. If a DBA or another tool already takes differentials, your extra full backup would break their chain.

How Zopanel handles it

Zopanel for Windows backs up per account: the files of every site, MariaDB and MySQL databases and MailEnable mailboxes (available), with PostgreSQL and SQL Server in account backups still experimental. Backups are encrypted with AES-256-GCM using a key per account, open files are captured with VSS, and schedules and retention are set per account (the schedule is off until you turn it on). S3-compatible destinations are limited. SFTP, Google Drive, OneDrive and Dropbox are experimental. You can restore single sites, databases or mail domains, and scheduled restore tests in a separate area are limited. Details are in the backup documentation and on the backups feature page. If you are moving from Plesk, see migrating from Plesk on Windows. Download Zopanel and start on the Free plan.