11 lines
448 B
PowerShell
11 lines
448 B
PowerShell
# Sql Instance Backup
|
|
|
|
$BackupRootPath = "E:\Backup"
|
|
$SqlServerInstance = "SQL-SERVER\INSTANCE"
|
|
|
|
$Dbs = Invoke-Sqlcmd -ServerInstance $SqlServerInstance -Query "SELECT name,database_id FROM sys.databases" -TrustServerCertificate
|
|
foreach ($Db in $Dbs) {
|
|
$BackupQuery = "BACKUP DATABASE [$($Db.name)] to DISK = '$BackupRootPath\$($Db.name).bak'"
|
|
Invoke-Sqlcmd -ServerInstance $SqlServerInstance -Query $BackupQuery -TrustServerCertificate
|
|
}
|
|
|