Here’s a quick example using dbatools’ Sync-DbaDatabase to keep a database named DB1 in sync between two instances. You can drop in your real server names, credentials or switches as needed:
# 1. (If you haven't already) install & import dbatools
Install-Module dbatools -Scope CurrentUser -Force
Import-Module dbatools
# 2. Synchronize DB1 from Source → Destination
Sync-DbaDatabase `
-Source 'SQLSRC\INSTANCE' `
-Destination 'SQLDEST\INSTANCE' `
-Database 'DB1' `
-BackupPath '\\MYBACKUP\share\DBBackups' `
-BackupRestore `
-Compression `
-Checksum `
-CopyLogin `
-TrustCertificate `
-NetworkShare `
-Force
Parameter highlights
• Source / Destination
The names (or connection strings) of your SQL Server instances.
• Database
The database you want to sync—in this case, “DB1.”
• BackupPath
A UNC path (or local folder) where dbatools will stage backups.
• BackupRestore
Tell dbatools to take a backup on the source, copy it, then restore to the destination.
• Compression / Checksum
Enable backup compression & checksum validation.
• CopyLogin
Copy orphaned logins from source → destination.
• TrustCertificate
If you’re using self-signed or untrusted certificates on your endpoint.
• NetworkShare
If the destination server can directly access the BackupPath share (avoids streaming).
• Force
Overwrites any existing database on the destination.
—–
Dry-run first
If you just want to see what would happen without making any changes, tack on -WhatIf:
Sync-DbaDatabase -Source SQLSRC -Destination SQLDEST -Database DB1 -BackupPath '\\share\DBBackups' -BackupRestore -WhatIf
That will give you a play-by-play of the steps without executing them.
Feel free to tweak or let me know if you need more details (e.g. credential objects, specific backup options, filtering objects, etc.). 🛠️