在 SharePoint Server 中移動內容資料庫Move content databases in SharePoint Server

摘要:了解如何在 SharePoint Server 2016 和 SharePoint 2013 中移動內容資料庫。Summary: Learn how to move content databases in SharePoint Server 2016 and SharePoint 2013.

本文說明如何在執行 SQL Server 的伺服器之間、SQL Server 的執行個體之間,或 SharePoint Server Web 應用程式之間移動內容資料庫。This article describes how to move content databases between servers that are running SQL Server, between instances of SQL Server, or from one SharePoint Server web application to another.

重要

[!重要事項] 本文僅說明如何移動內容資料庫。如需如何移動與 SharePoint Server 關聯之其他種類資料庫的詳細資訊,請參閱<在 SharePoint Server 中移動或重新命名服務應用程式資料庫>及<移動 SharePoint Server 中的所有資料庫>。This article only describes how to move content databases. For information about how to move other kinds of databases that are associated with SharePoint Server, see Move or rename service application databases in SharePoint Server and Move all databases in SharePoint Server.

您可以使用 SharePoint 管理中心網站 或 Microsoft PowerShell 及 SQL Server 工具移動內容資料庫。您可使用的工具取決於已部署的環境種類、排程的需求,以及您與組織訂定的服務層級協定。You can move content databases by using the SharePoint Central Administration website or Microsoft PowerShell, and SQL Server tools. Which tool that you use depends on what kind of environment you have deployed, what your schedule requires, and what service level agreements that you have made with your organization.

開始之前Before you begin

移動內容資料庫的作業開始之前,請先檢閱下列工作。每項工作都是一個程序,必須依照列出的順序來進行。請注意,移動內容資料庫時,必須同時使用 SharePoint Server 工具及 SQL Server 工具。您可以使用 管理中心 或 Windows PowerShell 3.0 來進行此作業。Before you begin this operation, moving a content database, review the following tasks. Each task is a procedure that must be done in the order in which it is listed. Note that when you move content databases, you must use both SharePoint Server tools and SQL Server tools. You can use either Central Administration or Windows PowerShell 3.0 for this operation.

  1. 記錄內容資料庫名稱及相關聯的 Web 應用程式。Record the content database name and the web application it is associated with.

  2. 暫停針對內容資料庫所執行的任何服務應用程式及服務,包括計時器工作及搜尋編目。Pause any service applications and services that might run against the content database, including timer jobs and search crawls.

  3. 從 Web 應用程式移除 SharePoint Server 內容資料庫。Remove the SharePoint Server content database from the web application.

  4. 從目前的 SQL Server 執行個體中卸離內容資料庫。Detach the content database from the current SQL Server instance.

    重要

    [!重要事項] 若要在同一個 SQL Server 執行個體內移動內容資料庫檔案,建議您使用 ALTER DATABASE 陳述式的 FILENAME 子句。如需詳細資訊,請參閱< 移動使用者資料庫>。To move the content database file within the same instance SQL Server we recommend that you use the FILENAME clause of the ALTER DATABASE statement. For more information, see Move User Databases.

    重要

    [!重要事項] 若要將內容資料庫移至另一個 SQL Server 執行個體或移至另一個伺服器,建議您使用<資料庫卸離與附加 (SQL Server)>或<SQL Server 資料庫的備份與還原>中所找到的程序。To move a content database to another instance of SQL Server or to another server, we recommend that you use procedures found in Database Detach and Attach (SQL Server) or Back Up and Restore of SQL Server Databases.

  5. 使用 [檔案總管],將內容資料庫 .mdf, .ndf 及 .ldf 檔案從來源位置複製並移動到目的地位置。Copy or move the content database .mdf, .ndf, and .ldf files from the source location to the destination location using File Explorer.

  6. 將內容資料庫附加到新的 SQL Server 執行個體。Attach the content database to the new SQL Server instance.

  7. 將內容資料庫新增到 SharePoint Server 中的目的地 Web 應用程式。Add the content database to the destination web application in SharePoint Server.

    重要

    [!重要事項] 當您新增內容資料庫或 SharePoint Server 建立新內容資料庫時,請使用相同名稱。Use the identical name when you add the content database or SharePoint Server creates a new content database.

  8. 重新啟動所有您在步驟 2 中暫停的服務應用程式及服務。Restart all service applications and services that you paused in step 2.

使用 管理中心 移動內容資料庫Moving content databases by using Central Administration

使用下列程序,透過管理中心在 SharePoint Server 伺服器陣列中移動內容資料庫。Use the following procedure to move the content databases in your SharePoint Server farm by using Central Administration.

本節中的程序會使用 管理中心 來移動內容資料庫。不過,執行下列程序時,必須使用正確的工具:The procedures in this section use Central Administration to move content databases. However when you perform the following procedures, you must use the correct tool:

  1. 記錄哪些內容資料庫與每個 Web 應用程式關聯 ─ PowerShellTo record which content databases are associated with each web application ─ PowerShell

  2. 從 SQL Server 卸離內容資料庫 ─ SQL Server 工具To detach the content databases from SQL Server ─ SQL Server tools

  3. 將內容資料庫移動到新位置 ─ 檔案總管或 Windows 檔案總管To move the content databases to a new location ─ File Explorer or Windows Explorer

  4. 將內容資料庫附加到新的 SQL Server 執行個體 ─ SQL Server 工具To attach the content databases to the new instance of SQL Server ─ SQL Server tools

注意

[!附註] 本節中的程序會使用 管理中心 來移動內容資料庫。不過,第一個程序必須使用 PowerShell 執行。The procedures in this section use Central Administration to move content databases. However, the first procedure, must be performed by using PowerShell.

注意

[!附註] 如果您要將內容資料庫移到不同的伺服器陣列,必須在還原過程中將伺服器陣列帳戶設成資料庫伺服器上管理員群組的成員。這允許帳戶複製資料庫的安全性設定。這個存取權層次可以在移動內容資料庫後移除。如需詳細資訊,請參閱<SharePoint Server 2016 中的帳戶權限及安全性設定>。If you are moving a content database to a different farm, you must make the server farm account a member of the Administrators group on the database server during the restore process. This enables the account to replicate the security setting for the databases. This access level can be removed after the content database is moved. For more information, see Account permissions and security settings in SharePoint Server 2016.

目的地伺服器陣列必須執行與來源伺服器陣列執行之 SharePoint Server 相同的版本,或是更新的版本。The destination farm must be running the same version or a later version of SharePoint Server than the source farm is running.

1. 記錄哪些內容資料庫與每個 Web 應用程式關聯1. To record which content databases are associated with each web application

  1. 確認您具備下列成員資格:Verify that you have the following memberships:

    • SQL Server 執行個體上的 securityadmin 固定伺服器角色。securityadmin fixed server role on the SQL Server instance.

    • 所有要更新之資料庫上的 db_owner 固定資料庫角色。db_owner fixed database role on all databases that are to be updated.

    • 正在執行 PowerShell Cmdlet 之所在伺服器上的系統管理員群組。Administrators group on the server on which you are running the PowerShell cmdlets.

    • 目的地伺服器上的 dbcreatorsecurityadmin 固定伺服器角色,以便附加資料庫和設定 SQL Server 登入。The dbcreator and securityadmin fixed server roles on the destination server, in order to attach the database and configure SQL Server logins.

      系統管理員可以使用 Add-SPShellAdmin Cmdlet 授與使用 SharePoint Server Cmdlet 的權限。An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint Server cmdlets.

      注意

      [!附註] 如果您不具備上述權限,請連絡安裝程式系統管理員或 SQL Server 系統管理員要求權限。如需 PowerShell 權限的其他資訊,請參閱 Add-SPShellAdminIf you do not have permissions, contact your Setup administrator or SQL Server administrator to request permissions. For additional information about PowerShell permissions, see Add-SPShellAdmin.

  2. 啟動 SharePoint 管理命令介面。Start the SharePoint Management Shell.

  3. 在 PowerShell 命令提示字元處,輸入下列命令:At the PowerShell command prompt, type the following command:

    Get-SPContentDatabase -WebApplication <http://SiteName>
    

    其中 <http://SiteName> 是 Web 應用程式的 URL。Where: <http://SiteName> is the URL of the web application.

    注意

    [!附註] 建議您在執行命令列管理工作時使用 Windows PowerShell。Stsadm 命令列工具已過時,但為與舊版產品相容,仍會隨附提供。We recommend that you use Microsoft PowerShell when performing command-line administrative tasks. The Stsadm command-line tool has been deprecated, but is included to support compatibility with previous product versions.

2. 使用 管理中心 暫停計時器工作2. To pause timer jobs by using Central Administration

  1. 確認執行此程序的使用者帳戶為 SharePoint 伺服器陣列管理員群組的成員。Verify that the user account that is performing this procedure is a member of the Farm Administrators SharePoint group.

  2. 在管理中心的 [監視] 區段中,按一下 [檢查工作狀態]。In Central Administration, in the Monitoring section, click Check Job Status.

  3. 對於每個您要移動內容資料庫上執行的排程工作,按一下該工作以開啟 [編輯計時器工作] 頁面上,按一下 [停用,然後按一下 [確定]For each scheduled job that runs against the content database that you are moving, click the job to open the Edit Timer Job page, click Disable, and then click OK.

3. 使用 管理中心 從 Web 應用程式卸離內容資料庫3. To detach the content databases from a web application by using Central Administration

  1. 確認執行此程序的使用者帳戶為 SharePoint 伺服器陣列管理員群組的成員。Verify that the user account that is performing this procedure is a member of the Farm Administrators SharePoint group.

  2. 在管理中心的 [應用程式管理] 區段中按一下 [管理內容資料庫]。In Central Administration, in the Application Management section, click Manage Content databases.

  3. 在 [管理內容資料庫] 頁面上,按一下您要移動的內容資料庫。On the Manage Content Databases page, click the content database that you want to move.

    管理內容資料庫設定] 頁面隨即開啟。The Manage Content Database Settings page opens.

    注意

    如果未出現在清單中的內容資料庫,您可能與另一個 web 應用程式相關聯。若要選取另一個 web 應用程式,在 [ Web 應用程式] 功能表上的按一下 [變更 Web 應用程式If the content database does not appear in the list, it might be associated with another web application. To select another web application, on the Web Application menu, click Change Web Application.

  4. 在 [管理內容資料庫設定] 頁面上的 [移除內容資料庫] 區段中選取 [移除內容資料庫] 核取方塊,然後再按一下 [確定]On the Manage Content Database Settings page, in the Remove Content Database section, select the Remove content database check box, and then click OK.

    注意

    [!附註] 移除內容資料庫不會刪除該資料庫,只會移除資料庫與 Web 應用程式相關聯的部分。Removing the content database does not delete the database. It only removes the association of the database with the web application.

  5. 對每一個要移動的內容資料庫重複步驟 3 和 4。Repeat steps 3 and 4 for each content database that you want to move.

4. 從 SQL Server 卸離內容資料庫4. To detach the content databases from SQL Server

  1. 確認執行此程序的使用者帳戶是儲存各資料庫之資料庫伺服器上的 db_owner 固定資料庫角色成員。Verify that the user account that is performing this procedure is a member of the db_owner fixed database role on the database server where each database is stored.

  2. 在 SQL Server Management Studio] 開啟來源 SQL Server 執行個體,然後展開 [資料庫] 節點。In SQL Server Management Studio, open the source SQL Server instance, and then expand the Databases node.

  3. 以滑鼠右鍵按一下 [內容資料庫,並指向 [工作],然後按一下 [卸離。針對每一個您要移動的內容資料庫重複此步驟。Right-click the content database, point to Tasks, and then click Detach. Repeat this step for each content database that you want to move.

    注意

    只能使用此程序移動內容資料庫。請勿卸離其他種類的資料庫。Use this procedure to move only content databases. Do not detach any other kinds of databases.

5. 將內容資料庫移至新位置5. To move the content databases to a new location

  1. 確認執行此程序的使用者帳戶具有來源及目的地資料夾的寫入權限。Verify that the user account that is performing this procedure has Write access to both the source and destination folders.

  2. 使用 [檔案總管] 找出內容資料庫的 .mdf, .ldf 和 .ndf 檔案。Using File Explorer, locate the .mdf, .ldf, and .ndf files for the content databases.

  3. 選取要移動之資料庫的 .mdf, .ldf 和 .ndf 檔案,然後將其複製或移往目的地目錄。Select the .mdf, .ldf, and .ndf files for the database that you want to move and either copy or move them to the destination directory.

6. 將內容資料庫附加到新的 SQL Server 執行個體6. To attach the content databases to the new instance of SQL Server

  1. 確認執行此程序的使用者帳戶是儲存各資料庫之資料庫伺服器上的 dbcreator 固定伺服器角色成員。Verify that the user account that is performing this procedure is a member of the dbcreator fixed server role on the database server where each database is stored.

  2. 在 Management Studio 中,開啟目的地 SQL Server 執行個體。In Management Studio, open the destination SQL Server instance.

  3. 以滑鼠右鍵按一下 [資料庫] 節點,並指向 [工作],然後按一下 [附加Right-click the Databases node, point to Tasks, and then click Attach.

  4. [附加資料庫] 對話方塊中,瀏覽至您轉接通話的.mdf、.ldf 和.ndf 檔案、 選取您想要附加之資料庫的.mdf 檔案並再按一下 [確定]In the Attach Database dialog box, browse to where you transferred the .mdf, .ldf, and .ndf files, select the .mdf file for the database that you want to attach, and then click OK.

  5. 對每個您要移動的內容資料庫重複此步驟。Repeat for each content database that you are moving.

7. 使用 管理中心 將內容資料庫附加到 Web 應用程式7. To attach the content databases to the web application by using Central Administration

  1. 確認執行此程序的使用者帳戶是伺服器陣列管理員群組的成員。Verify that the user account that is performing this procedure is a member of the Farm Administrators group.

  2. 在管理中心的 [應用程式管理] 區段中按一下 [管理內容資料庫]。In Central Administration, in the Application Management section, click Manage Content databases.

  3. 在 [管理內容資料庫] 頁面中,按一下 [加入內容資料庫]。On the Manage Content Databases page, click Add a content database.

  4. 在 [新增內容資料庫] 頁面上,確認 [ Web 應用程式] 功能表顯示正確的 web 應用程式。On the Add Content Database page, verify that the Web Application menu displays the correct web application.

  5. 在 [伺服器] 方塊中指定的資料庫伺服器主控資料庫。In the Server box, specify the database server that hosts the database.

  6. 在 [資料庫名稱] 方塊中輸入已傳輸內容資料庫的正確名稱。In the Database Name box, type the exact name of the transferred content database.

    注意

    [!附註] 請確認名稱是否正確。如果不正確,將會建立新資料庫。Verify that the name is correct. If it is not, a new database will be created.

  7. 指定資料庫的驗證方法,然後按一下 [確定]Specify the authentication method for the database, and then click OK.

  8. 您要新增的每個資料庫重複這些步驟。請確定從每個資料庫的Web 應用程式] 功能表中選取正確的 web 應用程式。Repeat these steps for each database that you are adding. Be sure that you select the correct web application from the Web Application menu for each database.

8. 使用 管理中心 重新啟動計時器工作8. To restart timer jobs by using Central Administration

  1. 確認執行此程序的使用者帳戶是伺服器陣列管理員群組的成員。Verify that the user account that is performing this procedure is a member of the Farm Administrators group.

  2. 在管理中心的 [監視] 區段中,按一下 [檢查工作狀態]。In Central Administration, in the Monitoring section, click Check Job Status.

  3. 對於每個之前停用的排程工作,按一下該工作以開啟 [編輯計時器工作] 頁面上,按一下 [啟用] 然後按一下 [確定]For each scheduled job that you disabled previously, click the job to open the Edit Timer Job page, click Enable, and then click OK.

使用 PowerShell 移動內容資料庫Moving content databases by using PowerShell

使用下列程序,透過PowerShell在 SharePoint Server 伺服器陣列中移動內容資料庫。Use the following procedure to move the content databases in your SharePoint Server farm by using PowerShell

本節中的程序會使用 PowerShell 來移動內容資料庫。不過,執行下列程序時,必須使用正確的工具:The procedures in this section use PowerShell to move content databases. However when you perform the following procedures, you must use the correct tool:

  1. 從 SQL Server 卸離內容資料庫 ─ SQL Server 工具To detach the content databases from SQL Server ─ SQL Server tools

  2. 將內容資料庫移動到新位置 ─ 檔案總管To move the content databases to a new location ─ File Explorer

  3. 將內容資料庫附加到新的 SQL Server 執行個體 ─ SQL Server 工具To attach the content databases to the new instance of SQL Server ─ SQL Server tools

注意

[!附註] 如果您要將內容資料庫移到不同的伺服器陣列,必須在還原過程中將伺服器陣列帳戶設成資料庫伺服器上管理員群組的成員。這允許帳戶複製資料庫的安全性設定。這個存取權層次可以在移動內容資料庫後移除。If you are moving a content database to a different farm, you must make the server farm account a member of the Administrators group on the database server during the restore process. This enables the account to replicate the security setting for the databases. This access level can be removed after the content database is moved.

目的地伺服器陣列必須執行與來源伺服器陣列執行之 SharePoint Server 相同的版本,或是更新的版本。The destination farm must be running the same version or a later version of SharePoint Server than the source farm is running.

1. 記錄哪些內容資料庫與每個 Web 應用程式關聯1. To record which content databases are associated with each web application

  1. 確認您具備下列成員資格:Verify that you have the following memberships:

    • SQL Server 執行個體上的 securityadmin 固定伺服器角色。securityadmin fixed server role on the SQL Server instance.

    • 所有要更新之資料庫上的 db_owner 固定資料庫角色。db_owner fixed database role on all databases that are to be updated.

    • 正在執行 PowerShell Cmdlet 之所在伺服器上的系統管理員群組。Administrators group on the server on which you are running the PowerShell cmdlets.

    • 目的地伺服器上的 dbcreatorsecurityadmin 固定伺服器角色,以便附加資料庫和設定 SQL Server 登入。The dbcreator and securityadmin fixed server roles on the destination server, in order to attach the database and configure SQL Server logins.

      系統管理員可以使用 Add-SPShellAdmin Cmdlet 授與使用 SharePoint Server Cmdlet 的權限。An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint Server cmdlets.

      注意

      [!附註] 如果您不具備上述權限,請連絡安裝程式系統管理員或 SQL Server 系統管理員要求權限。如需 PowerShell 權限的其他資訊,請參閱 Add-SPShellAdminIf you do not have permissions, contact your Setup administrator or SQL Server administrator to request permissions. For additional information about PowerShell permissions, see Add-SPShellAdmin.

  2. 啟動 SharePoint 管理命令介面。Start the SharePoint Management Shell.

  3. 在 PowerShell 命令提示字元處,輸入下列命令:At the PowerShell command prompt, type the following command:

    Get-SPContentDatabase -WebApplication <http://SiteName>
    

    其中 <http://SiteName> 是 Web 應用程式的 URL。Where: <http://SiteName> is the URL of the web application.

如需詳細資訊,請參閱<Get-SPContentDatabaseFor more information, see Get-SPContentDatabase

注意

[!附註] 建議您在執行命令列管理工作時使用 Windows PowerShell。Stsadm 命令列工具已過時,但為與舊版產品相容,仍會隨附提供。We recommend that you use Microsoft PowerShell when performing command-line administrative tasks. The Stsadm command-line tool has been deprecated, but is included to support compatibility with previous product versions.

2. 使用 PowerShell 暫停計時器工作2. To pause timer jobs by using PowerShell

  1. 確認您具備下列成員資格:Verify that you have the following memberships:

    • SQL Server 執行個體上的 securityadmin 固定伺服器角色。securityadmin fixed server role on the SQL Server instance.

    • 所有要更新之資料庫上的 db_owner 固定資料庫角色。db_owner fixed database role on all databases that are to be updated.

    • 正在執行 PowerShell Cmdlet 之所在伺服器上的系統管理員群組。Administrators group on the server on which you are running the PowerShell cmdlets.

    • 目的地伺服器上的 dbcreatorsecurityadmin 固定伺服器角色,以便附加資料庫和設定 SQL Server 登入。The dbcreator and securityadmin fixed server roles on the destination server, in order to attach the database and configure SQL Server logins.

      系統管理員可以使用 Add-SPShellAdmin Cmdlet 授與使用 SharePoint Server Cmdlet 的權限。An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint Server cmdlets.

      注意

      [!附註] 如果您不具備上述權限,請連絡安裝程式系統管理員或 SQL Server 系統管理員要求權限。如需 PowerShell 權限的其他資訊,請參閱 Add-SPShellAdminIf you do not have permissions, contact your Setup administrator or SQL Server administrator to request permissions. For additional information about PowerShell permissions, see Add-SPShellAdmin.

  2. 啟動 SharePoint 管理命令介面。Start the SharePoint Management Shell.

  3. 在 PowerShell 命令提示字元處,輸入下列命令:At the PowerShell command prompt, type the following command:

    Get-SPTimerJob -webapplication <http://WebApplicationURL> | select name | Out-File <c:\timerjobfile.txt> -Append -Encoding ascii
    ForEach($tmrjob in (Get-Content <c:\timerjobfile.txt>)) { Get-SPTimerJob -Identity $tmrjob | Disable-SPTimerjob }
    

    其中:Where:

    • <http://WebApplicationURL> 是與您要移動之內容資料庫關聯的 Web 應用程式。<http://WebApplicationURL> is the Web application associated with the content database that you are moving.

    • <c:\timerjobfile.txt> 是您要建立含有與 Web 應用程式關聯之所有計時器工作的檔案位置。<c:\timerjobfile.txt> is the location of the file that you are creating that lists all timer jobs associated with the Web application.

如需詳細資訊,請參閱<Get-SPTimerJob>、<Out-File>、<ForEach-Object>、<Get-Content>、<Disable-SPTimerJob>。For more information, see Get-SPTimerJob, Out-File, ForEach-Object, Get-Content, and Disable-SPTimerJob.

注意

[!附註] 建議您在執行命令列管理工作時使用 Windows PowerShell。Stsadm 命令列工具已過時,但為與舊版產品相容,仍會隨附提供。We recommend that you use Microsoft PowerShell when performing command-line administrative tasks. The Stsadm command-line tool has been deprecated, but is included to support compatibility with previous product versions.

3. 使用 PowerShell 從 Web 應用程式卸離內容資料庫3. To detach content databases from a web application by using PowerShell

  1. 確認您具備下列成員資格:Verify that you have the following memberships:

    • SQL Server 執行個體上的 securityadmin 固定伺服器角色。securityadmin fixed server role on the SQL Server instance.

    • 所有要更新之資料庫上的 db_owner 固定資料庫角色。db_owner fixed database role on all databases that are to be updated.

    • 正在執行 PowerShell Cmdlet 之所在伺服器上的系統管理員群組。Administrators group on the server on which you are running the PowerShell cmdlets.

    • 目的地伺服器上的 dbcreatorsecurityadmin 固定伺服器角色,以便附加資料庫和設定 SQL Server 登入。The dbcreator and securityadmin fixed server roles on the destination server, in order to attach the database and configure SQL Server logins.

      系統管理員可以使用 Add-SPShellAdmin Cmdlet 授與使用 SharePoint Server Cmdlet 的權限。An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint Server cmdlets.

      注意

      [!附註] 如果您不具備上述權限,請連絡安裝程式系統管理員或 SQL Server 系統管理員要求權限。如需 PowerShell 權限的其他資訊,請參閱 Add-SPShellAdminIf you do not have permissions, contact your Setup administrator or SQL Server administrator to request permissions. For additional information about PowerShell permissions, see Add-SPShellAdmin.

  2. 啟動 SharePoint 管理命令介面。Start the SharePoint Management Shell.

  3. 在 PowerShell 命令提示字元處,輸入下列命令:At the PowerShell command prompt, type the following command:

    Dismount-SPContentDatabase "<ContentDB>"
    

    其中 <ContentDB> 是內容資料庫的名稱。Where: <ContentDB> is the name of the content database.

    注意

    [!附註] 如果有多個內容資料庫具有相同的名稱,在此命令中就必須使用內容資料庫 GUID,而非使用內容資料庫名稱。若要擷取內容資料庫的 GUID,請執行 Get-SPContentDatabase cmdlet,並且不加任何引數。If you have multiple content databases that have the same name, you must use the content database GUID in this command instead of using the content database name. To retrieve the GUID of the content database, run the Get-SPContentDatabase cmdlet without arguments.

    如需詳細資訊,請參閱<Dismount-SPContentDatabase>和<Get-SPContentDatabase>。For more information, see Dismount-SPContentDatabase and Get-SPContentDatabase.

    注意

    [!附註] 建議您在執行命令列管理工作時使用 Windows PowerShell。Stsadm 命令列工具已過時,但為與舊版產品相容,仍會隨附提供。We recommend that you use Microsoft PowerShell when performing command-line administrative tasks. The Stsadm command-line tool has been deprecated, but is included to support compatibility with previous product versions.

4. 從 SQL Server 卸離內容資料庫4. To detach the content databases from SQL Server

  1. 確認執行此程序的使用者帳戶是儲存各資料庫之資料庫伺服器上的 db_owner 固定資料庫角色成員。Verify that the user account that is performing this procedure is a member of the db_owner fixed database role on the database server where each database is stored.

  2. 在 Management Studio 中,開啟來源 SQL Server 執行個體,然後展開 [資料庫] 節點。In Management Studio, open the source SQL Server instance, and then expand the Databases node.

  3. 以滑鼠右鍵按一下 [內容資料庫,並指向 [工作],然後按一下 [卸離。針對每一個您要移動的內容資料庫重複此步驟。Right-click the content database, point to Tasks, and then click Detach. Repeat this step for each content database that you want to move.

    注意

    只能使用此程序移動內容資料庫。請勿卸離其他種類的資料庫。Use this procedure to move only content databases. Do not detach any other kinds of databases.

5. 將內容資料庫移至新位置5. To move the content databases to a new location

  1. 確認執行此程序的使用者帳戶具有來源及目的地資料夾的寫入權限。Verify that the user account that is performing this procedure has Write access to both the source and destination folders.

  2. 使用 [檔案總管] 找出內容資料庫的 .mdf, .ldf 和 .ndf 檔案。Using File Explorer, locate the .mdf, .ldf, and .ndf files for the content databases.

  3. 選取要移動之資料庫的 .mdf, .ldf 和 .ndf 檔案,然後將其複製或移往目的地目錄。Select the .mdf, .ldf, and .ndf files for the database that you want to move and either copy or move them to the destination directory.

6. 將內容資料庫附加到新的 SQL Server 執行個體6. To attach the content databases to the new instance of SQL Server

  1. 確認執行此程序的使用者帳戶是儲存各資料庫之資料庫伺服器上的 dbcreator 固定伺服器角色成員。Verify that the user account that is performing this procedure is a member of the dbcreator fixed server role on the database server where each database is stored.

  2. 在 Management Studio 中,開啟目的地 SQL Server 執行個體。In Management Studio, open the destination SQL Server instance.

  3. 以滑鼠右鍵按一下 [資料庫] 節點,並指向 [工作],然後按一下 [附加Right-click the Databases node, point to Tasks, and then click Attach.

  4. [附加資料庫] 對話方塊中,瀏覽至您轉接通話的.mdf、.ldf 和.ndf 檔案、 選取您想要附加之資料庫的.mdf 檔案並再按一下 [確定]In the Attach Database dialog box, browse to where you transferred the .mdf, .ldf, and .ndf files, select the .mdf file for the database that you want to attach, and then click OK.

  5. 對每個您要移動的內容資料庫重複此步驟。Repeat for each content database that you are moving.

7. 使用 PowerShell 從 Web 應用程式附加內容資料庫7. To attach content databases from a web application by using PowerShell

  1. 確認您具備下列成員資格:Verify that you have the following memberships:

    • SQL Server 執行個體上的 securityadmin 固定伺服器角色。securityadmin fixed server role on the SQL Server instance.

    • 所有要更新之資料庫上的 db_owner 固定資料庫角色。db_owner fixed database role on all databases that are to be updated.

    • 正在執行 PowerShell Cmdlet 之所在伺服器上的系統管理員群組。Administrators group on the server on which you are running the PowerShell cmdlets.

    • 目的地伺服器上的 dbcreatorsecurityadmin 固定伺服器角色,以便附加資料庫和設定 SQL Server 登入。The dbcreator and securityadmin fixed server roles on the destination server, in order to attach the database and configure SQL Server logins.

      系統管理員可以使用 Add-SPShellAdmin Cmdlet 授與使用 SharePoint Server Cmdlet 的權限。An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint Server cmdlets.

      注意

      [!附註] 如果您不具備上述權限,請連絡安裝程式系統管理員或 SQL Server 系統管理員要求權限。如需 PowerShell 權限的其他資訊,請參閱 Add-SPShellAdminIf you do not have permissions, contact your Setup administrator or SQL Server administrator to request permissions. For additional information about PowerShell permissions, see Add-SPShellAdmin.

  2. 啟動 SharePoint 管理命令介面。Start the SharePoint Management Shell.

  3. 在 PowerShell 命令提示字元處,輸入下列命令:At the PowerShell command prompt, type the following command:

    Mount-SPContentDatabase "<ContentDB>" -DatabaseServer "<DBServer>" -WebApplication <http://SiteName>
    

    其中:Where:

    • <ContentDB> 是要附加的內容資料庫的名稱。<ContentDB> is the name of the content database to be attached.

    • <DBServer> 是資料庫伺服器的名稱。<DBServer> is the name of the database server.

    • <http://SiteName> 是要附加內容資料庫之 Web 應用程式的 URL。<http://SiteName> is the URL of the Web application to which the content database is being attached.

      如需詳細資訊,請參閱<Mount-SPContentDatabase>。For more information, see Mount-SPContentDatabase.

      注意

      [!附註] 建議您在執行命令列管理工作時使用 Windows PowerShell。Stsadm 命令列工具已過時,但為與舊版產品相容,仍會隨附提供。We recommend that you use Microsoft PowerShell when performing command-line administrative tasks. The Stsadm command-line tool has been deprecated, but is included to support compatibility with previous product versions.

8. 使用 PowerShell 重新啟動計時器工作8. To restart timer jobs by using PowerShell

  1. 確認您具備下列成員資格:Verify that you have the following memberships:

    • SQL Server 執行個體上的 securityadmin 固定伺服器角色。securityadmin fixed server role on the SQL Server instance.

    • 所有要更新之資料庫上的 db_owner 固定資料庫角色。db_owner fixed database role on all databases that are to be updated.

    • 正在執行 PowerShell Cmdlet 之所在伺服器上的系統管理員群組。Administrators group on the server on which you are running the PowerShell cmdlets.

    • 目的地伺服器上的 dbcreatorsecurityadmin 固定伺服器角色,以便附加資料庫和設定 SQL Server 登入。The dbcreator and securityadmin fixed server roles on the destination server, in order to attach the database and configure SQL Server logins.

      系統管理員可以使用 Add-SPShellAdmin Cmdlet 授與使用 SharePoint Server Cmdlet 的權限。An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint Server cmdlets.

      注意

      [!附註] 如果您不具備上述權限,請連絡安裝程式系統管理員或 SQL Server 系統管理員要求權限。如需 PowerShell 權限的其他資訊,請參閱 Add-SPShellAdminIf you do not have permissions, contact your Setup administrator or SQL Server administrator to request permissions. For additional information about PowerShell permissions, see Add-SPShellAdmin.

  2. 啟動 SharePoint 管理命令介面。Start the SharePoint Management Shell.

  3. 在 PowerShell 命令提示字元處,輸入下列命令:At the PowerShell command prompt, type the following command:

    ForEach($tmrjob in (Get-Content <c:\timerjobfile.txt>)) {Get-SPTimerJob -Identity $tmrjob | Enable-SPTimerjob}
    

    其中 <c:\timerjobfile.txt> 是您要建立含有與 Web 應用程式關聯的所有計時器作業的檔案位置。Where: <c:\timerjobfile.txt> is the location of the file that you created that lists all of the timer jobs associated with the Web application.

    如需詳細資訊,請參閱<Get-SPTimerJob>、<ForEach-Object>、<Get-Content>及<Enable-SPTimerJob>。For more information, see Get-SPTimerJob, ForEach-Object, Get-Content, and Enable-SPTimerJob.

    注意

    [!附註] 建議您在執行命令列管理工作時使用 Windows PowerShell。Stsadm 命令列工具已過時,但為與舊版產品相容,仍會隨附提供。We recommend that you use Microsoft PowerShell when performing command-line administrative tasks. The Stsadm command-line tool has been deprecated, but is included to support compatibility with previous product versions.

另請參閱See also

概念Concepts

移動 SharePoint Server 中的所有資料庫Move all databases in SharePoint Server