Memigrasikan data antara SQL Server 2008 dan Cloud SQL untuk SQL Server menggunakan file cadangan
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Dalam tutorial ini, Anda akan memigrasikan data dari SQL Server 2008 ke Cloud SQL
untuk SQL Server 2017 Enterprise. Tutorial ini menunjukkan cara mengekspor data dari SQL Server 2008, mengimpor data ke Cloud SQL untuk SQL Server 2017, dan memvalidasi bahwa data berhasil diimpor.
Tutorial ini berguna jika Anda merupakan admin sistem, developer, engineer, admin database, atau engineer DevOps yang ingin memigrasikan data dari SQL Server 2008 ke Cloud SQL untuk SQL Server 2017 atau yang ingin mengupgrade dari SQL Server 2008 ke SQL Server 2017.
Tutorial ini mengasumsikan bahwa Anda memiliki lisensi SQL Server 2008 dan sudah
mengetahui hal-hal berikut:
Untuk membuat perkiraan biaya berdasarkan proyeksi penggunaan Anda,
gunakan kalkulator harga.
Pengguna Google Cloud baru mungkin memenuhi syarat untuk mendapatkan uji coba gratis.
Setelah menyelesaikan tugas yang dijelaskan dalam dokumen ini, Anda dapat menghindari penagihan berkelanjutan dengan menghapus resource yang Anda buat. Untuk mengetahui informasi selengkapnya, lihat
Pembersihan.
Sebelum memulai
Di Google Cloud konsol, pada halaman pemilih project, pilih atau
buat project Google Cloud .
Di bagian bawah konsol Google Cloud , sesi
Cloud Shell
akan terbuka dan menampilkan perintah command line. Cloud Shell adalah lingkungan shell dengan Google Cloud CLI yang sudah terinstal, dan dengan nilai yang sudah ditetapkan untuk project Anda saat ini. Perlu waktu beberapa detik hingga sesi dimulai.
Membuat instance Cloud SQL dan bucket Cloud Storage
Di Cloud Shell, buat instance Cloud SQL untuk SQL Server 2017 Enterprise yang nantinya akan menjadi tujuan migrasi database:
Diperlukan waktu beberapa menit untuk membuat instance. Nama pengguna root default
adalah sqlserver dengan sandi default sqlserver12@. Untuk tutorial ini, Anda akan membuat instance di zona us-central1-f. Untuk mengetahui informasi selengkapnya tentang zona, lihat Lokasi Cloud.
Buat bucket Cloud Storage untuk menyimpan file cadangan sebelum data diimpor ke Cloud SQL:
Ganti bucket-name dengan nama unik untuk bucket Cloud Storage.
Mencadangkan database Anda
Di bagian ini, Anda akan terhubung ke server Windows yang menjalankan SQL Server 2008,
membuat cadangan database, dan mengupload database cadangan ke
Cloud Storage.
Hubungkan ke server Windows yang menjalankan SQL Server 2008 menggunakan RDP. Server tersebut dapat berupa server utama atau replika.
Google Cloud membuat akun layanan saat Anda membuat instance Cloud SQL. Anda dapat menggunakan akun layanan untuk memberikan izin instance Cloud SQL guna mengakses resource yang diperlukan.
Beri akun layanan izin untuk menulis ke bucket Cloud Storage:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-05 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)."]]