Migra datos entre SQL Server 2008 y Cloud SQL para SQL Server mediante archivos de copia de seguridad
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
En este instructivo, migrarás datos de SQL Server 2008 a Cloud SQL para SQL Server 2017 Enterprise. Aquí se muestra cómo exportar los datos de SQL Server 2008, cómo importarlos a Cloud SQL para SQL Server 2017 y cómo validar si se importaron de forma correcta.
Este instructivo te será de utilidad si eres administrador de sistemas, desarrollador, ingeniero, administrador de bases de datos o ingeniero DevOps y deseas migrar datos de SQL Server 2008 a Cloud SQL para SQL Server 2017, o bien si deseas actualizar SQL Server 2008 a SQL Server 2017.
En el instructivo, se supone que tienes una licencia para SQL Server 2008 y que estás familiarizado con los siguientes sistemas:
Para generar una estimación de costos en función del uso previsto, usa la calculadora de precios.
Es posible que los usuarios nuevos de Google Cloud califiquen para obtener una prueba gratuita.
Cuando finalices las tareas que se describen en este documento, puedes borrar los recursos que creaste para evitar que continúe la facturación. Para obtener más información, consulta Cómo realizar una limpieza.
Antes de comenzar
En la página del selector de proyectos de la consola de Google Cloud, selecciona o crea un proyecto de Google Cloud.
En la parte inferior de la consola de Google Cloud, se abre una sesión de Cloud Shell en la que se muestra una ventana emergente de línea de comandos. Cloud Shell es un entorno de shell con Google Cloud CLI ya instalada y con valores ya establecidos para el proyecto actual. La sesión puede tardar unos segundos en inicializarse.
Crea la instancia de Cloud SQL y el bucket de Cloud Storage
En Cloud Shell, crea la instancia de Cloud SQL para SQL Server 2017 Enterprise a la que luego migrarás la base de datos:
La creación de la instancia puede tomar unos minutos. El nombre de usuario raíz predeterminado es sqlserver y la contraseña predeterminada es sqlserver12@. Para este instructivo, debes crear la instancia en la zona us-central1-f. Para obtener más información sobre las zonas, consulta Ubicaciones de Cloud.
Crea un bucket de Cloud Storage para almacenar el archivo de copia de seguridad antes de importar los datos a Cloud SQL:
Reemplaza bucket-name por un nombre único para el depósito de Cloud Storage.
Crea una copia de seguridad de tu base de datos
En esta sección, te conectarás a tu servidor de Windows que ejecuta SQL Server 2008, crearás una copia de seguridad de la base de datos y la subirás a Cloud Storage.
Conéctate a tu servidor de Windows que ejecuta SQL Server 2008 mediante RDP. Puede ser el servidor principal o uno de réplica.
Inicia la herramienta de línea de comandos de PowerShell.
Google Cloud crea una cuenta de servicio cuando creas la instancia de Cloud SQL. Debes usar la cuenta de servicio a fin de otorgar permiso a la instancia de Cloud SQL para acceder a los recursos que necesita.
Otorga permiso a la cuenta de servicio para escribir en el bucket de Cloud Storage:
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-07-30 (UTC)"],[],[],null,["*** ** * ** ***\n\nIn this tutorial, you migrate data from SQL Server 2008 to Cloud SQL for SQL Server 2017 Enterprise. The tutorial shows you how to export the data from SQL Server 2008, import the data to Cloud SQL for SQL Server 2017, and validate that the data was successfully imported.\n\n\u003cbr /\u003e\n\nIf you want to migrate data from SQL Server 2017, see\n[Migrating data between SQL Server 2017 and Cloud SQL for SQL Server using backup files](/solutions/migrating-data-between-sql-server-2017-and-cloud-sql-for-sql-server-using-backup-files).\n\nThis tutorial is useful if you are a sysadmin, developer, engineer, database\nadmin, or DevOps engineer who wants to migrate data from SQL Server 2008 to\nCloud SQL for SQL Server 2017 or who wants to upgrade from SQL Server\n2008 to SQL Server 2017.\n\nThe tutorial assumes that you have a license for SQL Server 2008 and that you're\nfamiliar with the following:\n\n- Microsoft SQL Server 2008\n- Microsoft SQL Server 2017\n- Microsoft PowerShell\n- [Cloud Storage](/storage)\n- [Cloud SQL](/sql/docs/sqlserver)\n\nObjectives\n\n- Create a Cloud SQL for SQL Server instance.\n- Create a Cloud Storage bucket.\n- Back up your database.\n- Import the database into Cloud SQL for SQL Server.\n- Validate the imported data.\n\nCosts\n\n\nIn this document, you use the following billable components of Google Cloud:\n\n\n- [Cloud SQL](/sql/pricing)\n- [Cloud Storage](/storage/pricing)\n\n\nTo generate a cost estimate based on your projected usage,\nuse the [pricing calculator](/products/calculator). \nNew Google Cloud users might be eligible for a [free trial](/free). \n\n\u003cbr /\u003e\n\nWhen you finish the tasks that are described in this document, you can avoid\ncontinued billing by deleting the resources that you created. For more information, see\n[Clean up](#clean-up).\n\nBefore you begin\n\n1. In the Google Cloud console, on the project selector page, select or\n create a Google Cloud project.\n\n | **Note:** If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [GO TO THE PROJECT SELECTOR PAGE](https://console.cloud.google.com/projectselector2/home/dashboard)\n2. Make sure that billing is enabled for your Google Cloud project.\n [Learn how to confirm billing is enabled for your project](/billing/docs/how-to/modify-project).\n\n3. Enable the Cloud Storage and Cloud SQL APIs.\n\n [ENABLE THE APIS](https://console.cloud.google.com/flows/enableapi?apiid=sqladmin,storage_component)\n4. [Install and initialize the Google Cloud CLI](/sdk/docs/install)\n on the server that's running SQL Server 2008.\n\n5. In the Google Cloud console, go to Cloud Shell.\n\n [GO TO Cloud Shell](https://console.cloud.google.com/?cloudshell=true)\n\n At the bottom of the Google Cloud console, a\n [Cloud Shell](/shell/docs/features)\n session opens and displays a command-line prompt. Cloud Shell is a shell\n environment with the Google Cloud CLI already installed, and with\n values already set for your current project. It can take a few seconds for\nthe session to initialize. \n\nCreating the Cloud SQL instance and Cloud Storage bucket\n\n1. In Cloud Shell, create the Cloud SQL for SQL Server\n 2017 Enterprise instance that you later migrate the database to:\n\n gcloud beta sql instances create target \\\n --database-version=SQLSERVER_2017_ENTERPRISE \\\n --cpu=2 \\\n --memory=5GB \\\n --root-password=sqlserver12@ \\\n --zone=us-central1-f\n\n It can take a few minutes to create the instance. The default root username\n is `sqlserver` with a default password of `sqlserver12@`. For this tutorial,\n you create the instance in the `us-central1-f` zone. For more information\n about zones, see\n [Cloud locations](/about/locations).\n2. Create a Cloud Storage bucket to store the backup file before\n the data is imported into Cloud SQL:\n\n ```\n gcloud storage buckets create \"gs://bucket-name\" --location=US\n ```\n\n Replace \u003cvar translate=\"no\"\u003ebucket-name\u003c/var\u003e with a unique name for the\n Cloud Storage bucket.\n\nBacking up your database\n\nIn this section, you connect to your Windows server running SQL Server 2008,\ncreate a backup of your database, and upload the backup database to\nCloud Storage.\n\n1. Connect to your Windows server running SQL Server 2008 by using RDP. It\n can be the primary or a replica server.\n\n2. Launch the PowerShell command-line tool.\n\n3. In the terminal where you\n [installed the gcloud CLI](/sdk/docs),\n create a backup folder:\n\n mkdir c:\\backup\n\n4. Create a backup of the database in the backup folder:\n\n ```\n osql -E -Q \"BACKUP DATABASE db-name TO DISK='c:\\backup\\db-name.bak'\"\n ```\n\n Replace \u003cvar translate=\"no\"\u003edb-name\u003c/var\u003e with the name of the database that\n you want to migrate to Cloud SQL.\n5. Copy the backup file to the Cloud Storage bucket:\n\n ```\n $PROJECT_ID = (gcloud sql instances describe target --format='value(project)' )\n gcloud storage cp c:\\backup\\db-name.bak gs://bucket-name --no-clobber\n ```\n\nImporting the backup file to Cloud SQL\n\n1. In Cloud Shell, retrieve the service account that's associated with\n the Cloud SQL instance and save it in a variable:\n\n SVC_EMAIL_ADDRESS=$(gcloud sql instances describe target \\\n --format='value(serviceAccountEmailAddress)')\n echo $SVC_EMAIL_ADDRESS\n\n Google Cloud creates a service account when you created the\n Cloud SQL instance. You use the service account to give the\n Cloud SQL instance permission to access the resources it needs.\n2. Give the service account permission to write to the\n Cloud Storage bucket:\n\n ```\n gcloud storage buckets add-iam-policy-binding gs://bucket-name \\\n --member=serviceAccount:${SVC_EMAIL_ADDRESS} \\\n --role=roles/storage.legacyBucketWriter\n ```\n3. Give the service account permission to read files in the\n Cloud Storage bucket:\n\n ```\n gcloud storage buckets add-iam-policy-binding gs://bucket-name \\\n --member=serviceAccount:${SVC_EMAIL_ADDRESS} \\\n --role=roles/storage.legacyObjectReader\n ```\n4. Import the backup file to the Cloud SQL database:\n\n ```\n gcloud beta sql import bak target \\\n gs://bucket-namedb-name.bak \\\n --database db-name\n ```\n\nValidating the data import\n\nIn this section, you check that the data was successfully imported.\n\n1. In Cloud Shell, install the\n [SQL Server toolkit](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-tools?view=sql-server-ver15):\n\n sudo apt-get install -y mssql-tools\n\n If you accept the license terms, enter `yes` when you're prompted.\n2. To securely access your Cloud SQL instance, download the\n [Cloud SQL proxy](https://cloud.google.com/sql/docs/mysql/sql-proxy):\n\n wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy\n\n3. Start the Cloud SQL proxy:\n\n CONNECTION_NAME=$(gcloud sql instances describe target --format='value(connectionName)')\n ./cloud_sql_proxy -instances=${CONNECTION_NAME}=tcp:1433 &\n\n4. Run a query to validate the data in one or more of the tables:\n\n ```\n /opt/mssql-tools/bin/sqlcmd -U sqlserver -S 127.0.0.1 -Q \"query-string\"\n ```\n\n Replace \u003cvar translate=\"no\"\u003equery-string\u003c/var\u003e with the SQL query that you\n want to run.\n\n When you're prompted, enter the `sqlserver12@` password.\n\nClean up The easiest way to eliminate billing is to delete the Google Cloud project you created for the tutorial.\n\n\u003cbr /\u003e\n\nDelete the project\n\n| **Caution** : Deleting a project has the following effects:\n|\n| - **Everything in the project is deleted.** If you used an existing project for the tasks in this document, when you delete it, you also delete any other work you've done in the project.\n| - **Custom project IDs are lost.** When you created this project, you might have created a custom project ID that you want to use in the future. To preserve the URLs that use the project ID, such as an `appspot.com` URL, delete selected resources inside the project instead of deleting the whole project.\n1. In the Google Cloud console, go to the **Manage resources** page.\n\n [Go to Manage resources](https://console.cloud.google.com/iam-admin/projects)\n2. In the project list, select the project that you want to delete, and then click **Delete**.\n3. In the dialog, type the project ID, and then click **Shut down** to delete the project.\n\nWhat's next\n\n- Read about [customer-managed encryption keys (CMEK) for Cloud SQL for SQL Server](/sql/docs/sqlserver/configure-cmek).\n- Read about [configuring private IP connectivity for Cloud SQL for SQL Server](/sql/docs/sqlserver/configure-private-ip).\n- Explore reference architectures, diagrams, and best practices about Google Cloud. Take a look at our [Cloud Architecture Center](/architecture)."]]