Posts

Showing posts from September, 2022

Adding database to Always On Availability Groups(AOAG) with Powershell, Add-SQLAvailabilityDatabase

Image
By using the below Powershell Command we can add database to AOAG instantly. But ensure that the path we have given for data and log files should be similar(same drive and folder strucute) in both the replicas. CLS #Change the dircectory CD to primary replica node SQL Server CD SQLSERVER : \SQL\NODE1 #Please provide shared path info dont give individual acccount $DatabaseBackupFile = "\\node1\aoag_backup\C\C_FULL_09172022.BAK" $LogBackupFile = "\\node1\aoag_backup\C\C_log_09172022.trn" #If your sql server instance is DEFULT instance please provide DEFAULT below, if it is named instance servername\instancename $MyAgPrimaryPath = "SQLSERVER:\SQL\NODE1\DEFAULT\AvailabilityGroups\AG1" $MyAgSecondaryPath = "SQLSERVER:\SQL\NODE2\DEFAULT\AvailabilityGroups\AG1" #Take the FULL and transaction log backup in from the primary replica Backup-SqlDatabase -Database "C" -BackupFile $DatabaseBackupFile -ServerInstance "N