Guide
How to schedule SQL Server Express backups with Task Scheduler
SQL Server Express has no SQL Server Agent, so the standard way to schedule SQL Server Express backups is a script that calls sqlcmd, run by Windows Task Scheduler. Below is a complete walkthrough: permissions, a PowerShell script (and a batch alternative) that dates each file and deletes backups older than N days, and the task itself.
What you'll set up
- A Windows account the task runs as, with backup rights in SQL Server.
- A backup folder that both SQL Server and the task can write to.
- A script that backs up every user database with a dated file name and cleans up old files.
- A Task Scheduler task that runs it every night.
You need sqlcmd, which is installed with SQL Server (including Express). Replace .\SQLEXPRESS with your instance name — the default Express instance is usually .\SQLEXPRESS.
Step 1: create a backup account and SQL login
Create a local Windows user such as sqlbackup (Computer Management → Local Users and Groups), then give it a login and the db_backupoperator role in each database. Using a dedicated account instead of an administrator keeps the task's rights small.
-- Run once in SSMS or sqlcmd as an administrator
CREATE LOGIN [MYSERVER\sqlbackup] FROM WINDOWS;
-- Repeat for each database to back up
USE [Sales];
CREATE USER [MYSERVER\sqlbackup] FOR LOGIN [MYSERVER\sqlbackup];
ALTER ROLE db_backupoperator ADD MEMBER [MYSERVER\sqlbackup];
-- SQL Server 2008 R2: EXEC sp_addrolemember 'db_backupoperator', 'MYSERVER\sqlbackup';Step 2: create the backup folder and permissions
This is the step most guides skip. The BACKUP command is executed by the SQL Server service, so its account writes the file — not the task's user. The task's user, in turn, writes the log file and deletes old backups.
mkdir D:\SQLBackups
rem SQL Server service account writes the .bak files
icacls D:\SQLBackups /grant "NT Service\MSSQL$SQLEXPRESS":(OI)(CI)M
rem The task account writes the log and deletes old files
icacls D:\SQLBackups /grant "MYSERVER\sqlbackup":(OI)(CI)MFor a default (non-Express) instance the service account is NT Service\MSSQLSERVER. You can confirm yours in SQL Server Configuration Manager.
Step 3: the backup script
PowerShell (recommended)
This script backs up every online user database, names each file like Sales_FULL_2026-09-29_020000.bak, writes a log and deletes .bak files older than $KeepDays — but only if the whole run succeeded, so a string of failures never deletes your last good backups.
# C:\Scripts\sql-backup.ps1
# Full backup of every online user database, dated file names, keep N days.
$Server = ".\SQLEXPRESS"
$BackupDir = "D:\SQLBackups"
$KeepDays = 7
$Stamp = Get-Date -Format "yyyy-MM-dd_HHmmss"
$Log = Join-Path $BackupDir "backup.log"
function Write-Log([string]$Message) {
Add-Content -Path $Log -Value ("{0} {1}" -f (Get-Date -Format "yyyy-MM-dd HH:mm:ss"), $Message)
}
# List online user databases (database_id > 4 skips master, tempdb, model, msdb)
$query = "SET NOCOUNT ON; SELECT name FROM sys.databases WHERE database_id > 4 AND state_desc = 'ONLINE';"
$dbs = & sqlcmd -S $Server -E -b -h -1 -W -Q $query
if ($LASTEXITCODE -ne 0) { Write-Log "ERROR cannot query $Server"; exit 1 }
$failed = 0
foreach ($db in ($dbs | Where-Object { $_.Trim() })) {
$db = $db.Trim()
$file = Join-Path $BackupDir ("{0}_FULL_{1}.bak" -f $db, $Stamp)
$sql = "BACKUP DATABASE [$db] TO DISK = N'$file' WITH INIT, CHECKSUM;"
& sqlcmd -S $Server -E -b -Q $sql | Out-Null
if ($LASTEXITCODE -eq 0) { Write-Log "OK $file" }
else { Write-Log "FAILED $db"; $failed++ }
}
# Only delete old backups when every backup in this run succeeded
if ($failed -eq 0) {
$cutoff = (Get-Date).AddDays(-$KeepDays)
Get-ChildItem -Path $BackupDir -Filter "*_FULL_*.bak" |
Where-Object { $_.LastWriteTime -lt $cutoff } |
ForEach-Object {
Remove-Item -LiteralPath $_.FullName -Force
Write-Log "DELETED $($_.Name)"
}
}
exit $failed-b makes sqlcmd return a non-zero exit code on SQL errors, which is how the script detects failures. CHECKSUM verifies page checksums as the backup is read. Express can't use WITH COMPRESSION, so files are full size; compress them afterwards with 7-Zip if space is tight.
Batch file alternative
If you only have one database and prefer cmd, this does the same for a single database. The timestamp comes from PowerShell because %DATE% changes format with regional settings.
@echo off
rem C:\Scripts\sql-backup.bat - one database, dated file name, keep 7 days
setlocal
set "SERVER=.\SQLEXPRESS"
set "DB=Sales"
set "DIR=D:\SQLBackups"
set "KEEPDAYS=7"
for /f %%i in ('powershell -NoProfile -Command "Get-Date -Format yyyy-MM-dd_HHmmss"') do set "STAMP=%%i"
sqlcmd -S "%SERVER%" -E -b -Q "BACKUP DATABASE [%DB%] TO DISK = N'%DIR%\%DB%_FULL_%STAMP%.bak' WITH INIT, CHECKSUM"
if errorlevel 1 exit /b 1
forfiles /p "%DIR%" /m "%DB%_FULL_*.bak" /d -%KEEPDAYS% /c "cmd /c del @path" 2>nul
exit /b 0Step 4: test it by hand
Run the script once as the backup account (for example with “Run as different user”) and check the result:
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\Scripts\sql-backup.ps1"
echo Exit code: %ERRORLEVEL%
type D:\SQLBackups\backup.logAn exit code of 0 and an “OK” line per database mean you're ready to schedule it.
Step 5: create the scheduled task
Using the Task Scheduler window
- Open Task Scheduler and choose Create Task… (not “Create Basic Task”, which hides options you need).
- General: name it, click Change User or Group and pick
sqlbackup, then select Run whether user is logged on or not. - Triggers: New → Daily at 02:00 (or a time when nobody is working).
- Actions: New → Start a program. Program:
powershell.exe. Arguments:-NoProfile -ExecutionPolicy Bypass -File "C:\Scripts\sql-backup.ps1". - Settings: tick Run task as soon as possible after a scheduled start is missed, so a server that was off at 2 AM still backs up when it starts.
- Click OK and enter the account password.
Or from the command line
schtasks /Create /TN "SQL Express nightly backup" /SC DAILY /ST 02:00 ^
/TR "powershell.exe -NoProfile -ExecutionPolicy Bypass -File C:\Scripts\sql-backup.ps1" ^
/RU "MYSERVER\sqlbackup" /RP *Check Last Run Result in Task Scheduler the next morning: 0x0 means success; any other value is the number of failed databases (or 1 if SQL Server couldn't be reached).
Going further
Transaction log backups
For databases in the FULL recovery model, add a second task every 30–60 minutes that runs BACKUP LOG, otherwise the log file keeps growing. Why this matters is explained in SQL Server backup types.
# Add inside the loop for databases in FULL recovery, in a second script run every 30 minutes:
$sql = "BACKUP LOG [$db] TO DISK = N'$BackupDir\$($db)_LOG_$Stamp.trn' WITH INIT, CHECKSUM;"An off-site copy
Backups on the same disk die with the disk. At minimum, copy them to a NAS or another machine after the backup:
rem Copy new backups to a NAS (no /MIR, so deletions are NOT mirrored)
robocopy D:\SQLBackups \\nas\sqlbackups *.bak /Z /R:2 /W:30 /NP /LOG+:D:\SQLBackups\copy.logOla Hallengren's Maintenance Solution
A widely used free alternative to writing your own T-SQL: install its stored procedures in master, then call DatabaseBackup from the scheduled task. @CleanupTime is in hours, so 168 keeps seven days.
sqlcmd -S .\SQLEXPRESS -E -d master -b -Q "EXECUTE dbo.DatabaseBackup @Databases = 'USER_DATABASES', @Directory = N'D:\SQLBackups', @BackupType = 'FULL', @CheckSum = 'Y', @Verify = 'Y', @CleanupTime = 168"What this setup still doesn't do
- No alert when a backup fails or the server is off — you have to remember to check.
- No compression or encryption of the .bak files.
- No cloud upload unless you script it, with credentials stored on the server.
- No restore testing; see restoring from a .bak file.
Keep it simple, but keep it checked
A scheduled script is far better than no backup. Whatever you use, look at the log weekly and do a test restore every month.
Scheduling Express backups — FAQ
Why does my scheduled backup work when I run it by hand but not from Task Scheduler?
The task runs as a different account. Check that the task's Windows account has a SQL login with backup rights, that the SQL Server service account can write to the backup folder, and that the task is set to run whether the user is logged on or not.
Can I back up to a network share from Task Scheduler?
Yes, but use a UNC path such as \\nas\sqlbackups, not a mapped drive letter, and give the SQL Server service account write access to the share. Many admins back up locally and copy to the share afterwards.
How do I get an email when the backup fails?
Task Scheduler's built-in email action is deprecated, so you'd have to add Send-MailMessage or a similar call to the script, with SMTP credentials stored on the server. A dedicated backup tool with alerting avoids this.
Skip the scripts
SQLBak Plus schedules SQL Server Express backups without SQL Agent, compresses them with 7-Zip, encrypts them and uploads them to your own storage — with email alerts. Free for one server.
Start freeRelated
- Automatic SQL Server Express backup Schedule SQL Server Express backups without SQL Server Agent: the manual sqlcmd way and the automatic way.
- SQL Server backup types explained Full vs differential vs transaction log backups, recovery models, a sample schedule and restore chains.
- Restore a SQL Server database from .bak Restore a .bak file with SSMS or T-SQL, fix orphaned users and solve errors 3154, 5 and version mismatch.
- SQL Server backup to FTP / SFTP Send SQL Server backups to an SFTP, FTPS or FTP server on a schedule, compressed and encrypted.