Powershell Full Database and Transaction Log Backup Script (works with SQLExpress)

Loosely based off of other examples I found, this script will perform full database backups of all databases or tran log backups of all full/bulk-logged databases.  In addition, it will utilize the default backup path (if one is not given), and delete old backup files (that conform to the file naming convention) that are older than a given number of retention hours (default to 48 hours):
Full backup to a given path, retaining only 26 hour old backups on disk
. .\backup.ps1 SQLINSTANCE\Name full 26 "C:\some\path"
Log backup (to the default instance configured backup path), retaining default 48 hours of logs on disk
. .\backup.ps1 SQLINSTANCE\Name log
Assumes that the given windows user has necessary permissions to perform backups.  Compression is not specified, so will assume instance default config

Leave a Reply