SQL database backup with Powershell

 

This backup script will do backup for all databases within my instance SQLINSTANCE\SQLINSTANCE and store it to BACKUP folder configured during the SQL installation.

Import-Module “sqlps” -DisableNameChecking            
            
Set-Location SQLSERVER:\SQL\SQLINSTANCE\SQLINSTANCE\Databases            
foreach ($db in (Get-ChildItem))            
       {            
         $dbname = $db.Name            
         $dt = Get-Date -Format yyyyMMddHHmmss            
         Backup-SqlDatabase -Database $dbname -BackupFile "$($dbname)_db_$($dt).bak"            
        }            

Pridaj komentár

Vaša e-mailová adresa nebude zverejnená. Vyžadované polia sú označené *