CopyDB.cmd is a DOS-summon script that permits you to duplicate an SQL Server database, starting with one SQL Server and then the next, having a few choices. It’s also possible to make a duplicate of a database on the same server. The complete duplicate procedure will be finished with only one single charge from summon brief.

How CopyDB.CMD functions

You can pick between two approaches to duplicate a database.

  • Back up the database on the source server, duplicate the reinforcement set to the objective, and restore the reinforcement set.
  • Set the database on the source server as disconnected from the net, duplicate the database records to the objective server, and joins them on the objective server.

The reinforcement-and-restore strategy is the standard technique. The script gathers all data by executing some SQL summons on the source and the objective SQL-Server by utilizing “SQLCMD.” The rest is finished with MSDOS batch orders.

After the exchange of the database, the script sets the similarity level to the adaptation of the objective server and fixes the orphan clients on the off chance that they are accessible on the objective server.

Arrangement

In the first place, copy the order record (CopyDB.cmd) to a neighborhood organizer, e.g., C:\TEMP.

Next, open a command line ([WIN]+[R] -> CMD -> [ENTER])

Finally, change the present index (sort: C: [ENTER] then “Album C:\TEMP [ENTER])

Use:

CopyDB PARAMETERS 
Source-DB_Server[\Instance] 
Target-DB_Server[\Instance] 
Database Name 
Discretionary: New Database Name 
Discretionary [datestamp|offline]

Cases:

  1. Duplicate the database TestDB from server1\Inst1 to server2:

    C:\Temp> CopyDB Server1\Ins1 Server2 TestDB

  2. Duplicate the database TestDB from server1 Port 22 to server2 port 443:

    C:\Temp> CopyDB “Server1,1234” “Server2,4567 TestDB

  3. As in Example 1, yet the name of the objective DB changes to TestDB2:

    C:\Temp> CopyDB Server1\Ins1 Server2 TestDB TestDB2

  4. As in Example 1, yet utilizing the disconnected from the net mode:

    C:\Temp> CopyDB Server1\Ins1 Server2 TestDB TestDB2 logged off

  5. as in Example 1, yet there will be added a timestamp to the new name for the objective: DB (TestDB_YYYYMMDD)

    C:\Temp> CopyDB Server1\Ins1 Server2 TestDB datestamp

Prerequisites:

The client running the script must be separate from the nearby administrator bunch on the source and the objective server. The client running the script should likewise be separate from the sysadmin server role of the source and the objective SQ -Server.

When you run the script, it will make transitory documents and a log record of the database exchange. These records will be put in the envelope where the script document is kept running. This can be your PC or one of the servers (source or target server). Thus you require compose consents for the index where you call the script, e.g., C:\Temp. Don’t hesitate to change the path for the logfile in the script at line 48.

Notes/Features:

The script is effectively tried on SQL-Server 9 (2005), 10 (2008), 10.5 (2008R2) and 11 (2012).

On the off chance that the database to be duplicated still exists in the objective, the script requests that it be dropped. At this point, you can break further execution. On the off chance that the database to be duplicated still exists and is running in an Availability Group (SQL-Server 2012 Always On highlight), you first need to expel it from this Availability Group.

The script utilizes the default information, log, and reinforcement paths characterized in source and target SQL Server for the exchange. The script consequently decides the dynamic hub of an Always on server (SQL Server 2012 and higher) on the off chance that you utilized the virtual name as source or target server name.

On the off chance that the clients of the database exist on the target SQL Server, the script consequently alters the stranded clients.