Migrer des données entre SQL Server 2008 et Cloud SQL pour SQL Server à l'aide de fichiers de sauvegarde
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Dans ce tutoriel, vous allez migrer des données de SQL Server 2008 vers Cloud SQL pour SQL Server 2017 Enterprise. Ce tutoriel explique comment exporter les données à partir de SQL Server 2008, les importer dans Cloud SQL pour SQL Server 2017 et vérifier qu'elles ont bien été importées.
Ce tutoriel s'adresse aux administrateurs système, développeurs, ingénieurs, administrateurs de bases de données ou ingénieurs DevOps souhaitant migrer des données de SQL Server 2008 vers Cloud SQL pour SQL Server 2017 ou effectuer une mise à niveau de SQL Server 2008 vers SQL Server 2017.
Dans ce tutoriel, nous partons du principe que vous disposez d'une licence pour SQL Server 2008 et que vous connaissez bien les produits suivants :
Obtenez une estimation des coûts en fonction de votre utilisation prévue à l'aide du simulateur de coût.
Les nouveaux utilisateurs de Google Cloud peuvent bénéficier d'un essai gratuit.
Une fois que vous avez terminé les tâches décrites dans ce document, vous pouvez éviter de continuer à payer des frais en supprimant les ressources que vous avez créées. Pour en savoir plus, consultez la section Effectuer un nettoyage.
Avant de commencer
Dans la console Google Cloud, sur la page de sélection du projet, sélectionnez ou créez un projet Google Cloud.
En bas de la fenêtre de la console Google Cloud, une session Cloud Shell s'ouvre et affiche une invite de ligne de commande. Cloud Shell est un environnement de shell dans lequel Google Cloud CLI est déjà installée, et dans lequel des valeurs sont déjà définies pour votre projet actuel. L'initialisation de la session peut prendre quelques secondes.
Créer l'instance Cloud SQL et le bucket Cloud Storage
Dans Cloud Shell, créez l'instance Cloud SQL pour SQL Server 2017 Enterprise vers laquelle vous migrerez ultérieurement la base de données :
La création de l'instance peut prendre quelques minutes. Le nom d'utilisateur racine par défaut est sqlserver et le mot de passe par défaut est sqlserver12@. Pour ce tutoriel, vous créez l'instance dans la zone us-central1-f. Pour en savoir plus sur les zones, consultez la page Emplacements Cloud.
Créez un bucket Cloud Storage pour stocker le fichier de sauvegarde avant l'importation des données dans Cloud SQL :
Remplacez bucket-name par un nom unique pour le bucket Cloud Storage.
Sauvegarder la base de données
Dans cette section, vous allez vous connecter au serveur Windows exécutant SQL Server 2008, créer une sauvegarde de la base de données et importer la base de données de sauvegarde dans Cloud Storage.
Connectez-vous au serveur Windows exécutant SQL Server 2008 via RDP. Il peut s'agir du serveur principal ou d'une instance de serveur répliquée.
Lancez l'outil de ligne de commande PowerShell.
Dans le terminal à partir duquel vous avez installé la CLI gclous, créez un dossier de sauvegarde :
mkdirc:\backup
Créez une sauvegarde de la base de données dans le dossier de sauvegarde :
osql -E -Q "BACKUP DATABASE db-name TO DISK='c:\backup\db-name.bak'"
Remplacez db-name par le nom de la base de données que vous souhaitez migrer vers Cloud SQL.
Copiez le fichier de sauvegarde dans le bucket Cloud Storage :
Google Cloud crée un compte de service lorsque vous créez l'instance Cloud SQL. Vous utilisez le compte de service pour autoriser l'instance Cloud SQL à accéder aux ressources dont elle a besoin.
Autorisez le compte de service à écrire dans le bucket Cloud Storage :
Découvrez des architectures de référence, des schémas et des bonnes pratiques concernant Google Cloud.
Consultez notre Cloud Architecture Center.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/07/30 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 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)."]]