Pencadangan dan pemulihan Cassandra

Bagian ini membahas cara mengonfigurasi pencadangan dan pemulihan data untuk cincin database Apache Cassandra yang terinstal di bidang runtime hybrid Apigee. Lihat juga Database Cassandra.

Yang perlu Anda ketahui tentang pencadangan Cassandra

Cassandra adalah {i>database<i} replika yang dikonfigurasi untuk memiliki minimal 3 salinan data di setiap region atau pusat data. Cassandra menggunakan replikasi streaming dan membaca perbaikan untuk memelihara replika data di setiap region atau pusat data pada titik tertentu.

Dalam hybrid, pencadangan Cassandra tidak diaktifkan secara default. Ini adalah praktik yang baik, namun, untuk mengaktifkan pencadangan Cassandra jika data Anda tidak sengaja terhapus.

Apa yang dicadangkan?

Konfigurasi pencadangan yang dijelaskan dalam topik ini mencadangkan entitas:

  • Skema Cassandra termasuk skema pengguna (definisi keyspace Apigee)
  • Informasi token partisi Cassandra per node
  • Ringkasan data Cassandra

Di mana data cadangan disimpan?

Data yang dicadangkan disimpan dalam bucket Google Cloud Storage (GCS) yang harus dibuat. Pembuatan dan konfigurasi bucket dibahas dalam topik ini.

Menjadwalkan pencadangan Cassandra

Pencadangan dijadwalkan sebagai cron job di bidang runtime. Untuk menjadwalkan Cadangan Cassandra:

  1. Jalankan create-service-account berikut command line Cloud Shell untuk membuat akun layanan (SA) GCP dengan Peran roles/storage.objectAdmin. Peran SA ini memungkinkan Anda menulis data cadangan ke Google Cloud Storage (GCS). Jalankan perintah berikut di penginstalan hybrid direktori {i>root<i}:
    ./tools/create-service-account apigee-cassandra output-dir
    Contoh:
    ./tools/create-service-account apigee-cassandra ./service-accounts
    Untuk informasi selengkapnya tentang akun layanan GCP, lihat Membuat dan mengelola akun layanan.
  2. Perintah create-service-account menyimpan file JSON yang berisi kunci pribadi akun layanan Anda. File disimpan di direktori yang sama tempat perintah dijalankan. Anda akan memerlukan jalur ke file ini dalam langkah-langkah berikut.
  3. Buat bucket GCS. Tentukan retensi data yang wajar untuk bucket. Apigee merekomendasikan retensi data kebijakan 15 hari.
  4. Buka file overrides.yaml.
  5. Tambahkan properti cassandra.backup berikut untuk mengaktifkan pencadangan. Larangan menghapus properti apa pun yang sudah dikonfigurasi.
    cassandra:
      ...
    
      backup:
        enabled: true
        serviceAccountPath: sa_json_file_path
        dbStorageBucket: gcs_bucket_path
        schedule: backup_schedule_code
    
      ...
    Di mana:
    Properti Deskripsi
    enabled Pencadangan dinonaktifkan secara default. Anda harus menyetel ini properti ke true
    serviceAccountPath Jalur di sistem file Anda ke akun layanan File JSON yang didownload saat Anda menjalankan ./tools/create-service-account
    dbStorageBucket Jalur bucket penyimpanan GCS dalam format ini: gs://bucket_name. gs:// wajib diisi.
    schedule Waktu mulai pencadangan, yang ditentukan dalam sintaksis crontab standar. Default: 0 2 * * *

    Catatan: Hindari menjadwalkan pencadangan yang dimulai dalam waktu singkat setelah Anda menerapkan konfigurasi pencadangan ke cluster Anda. Saat Anda menerapkan konfigurasi pencadangan, Kubernetes akan membuat ulang Node Cassandra. Jika pencadangan dimulai sebelum node dimulai ulang (mungkin beberapa menit) pencadangan akan gagal.

    Contoh:
    ...
    
    cassandra:
      storage:
        type: gcepd
        capacity: 50Gi
        gcepd:
          replicationType: regional-pd
      sslRootCAPath: "/Users/myhome/ssh/cassandra.crt"
      sslCertPath: "/Users/myhome/ssh/cassandra.crt"
      sslKeyPath: "/Users/myhome/ssh/cassandra.key"
      auth:
        default:
          password: "abc123"
        admin:
          password: "abc234"
        ddl:
          password: "abc345"
        dml:
          password: "abc456"
      nodeSelector:
        key: cloud.google.com/gke-nodepool
        value: apigee-data
      backup:
        enabled: true
        serviceAccountPath: "/Users/myhome/.ssh/my_cassandra_backup.json"
        dbStorageBucket: "gs://myname-cassandra-backup"
        schedule: "45 23 * * 6"
    
      ... 
  6. Terapkan perubahan konfigurasi ke cluster baru. Contoh:
    ./apigeectl apply -c 2_cassandra -v beta2

Memulihkan cadangan

Pemulihan mengambil data dari lokasi pencadangan dan memulihkannya ke dalam gugus Cassandra baru dengan jumlah pod. Cluster baru harus memiliki namespace yang berbeda dari cluster bidang runtime.

Untuk memulihkan cadangan Cassandra:

  1. Buat cluster Kubernetes baru dengan namespace baru. Anda tidak dapat menggunakan cluster/namespace yang Anda gunakan untuk instalasi hybrid asli.
  2. Di direktori penginstalan root hybrid, buat file overrides-restore.yaml baru.
  3. Salin konfigurasi Cassandra lengkap dari overrides.yaml asli Anda ke file yang baru.
  4. Tambahkan elemen namespace. Jangan gunakan namespace yang sama dengan yang digunakan untuk file asli .
  5. namespace: your-restore-namespace
    
    cassandra:
      storage:
        type: gcepd
        capacity: 50Gi
        gcepd:
          replicationType: regional-pd
      nodeSelector:
        key: cloud.google.com/gke-nodepool
        value: apigee-data
      sslRootCAPath: path_to_root_ca_file
      sslCertPath: path_to_ssl_cert_file
      sslKeyPath: path_to_ssl_key_file
      auth:
        default:
          password: your_cassandra_password
        admin:
          password: admin_password
        ddl:
          password: ddl_password
        dml:
          password: dml_password
    
      restore:
          enabled: true
          snapshotTimestamp: timestamp
          serviceAccountPath: sa_json_file_path
          dbStorageBucket: gcs_bucket_path
          image:
            pullPolicy: Always
    Di mana:
    Properti Deskripsi
    ssl*Path, auth.* Gunakan kredensial autentikasi TLS yang sama dengan yang Anda gunakan untuk membuat {i>database<i} Cassandra asli.
    snapshotTimestamp Stempel waktu pencadangan untuk memulihkan snapshot.
    serviceAccountPath Jalur pada sistem file Anda ke akun layanan yang Anda buat untuk cadangan.
    dbStorageBucket jalur bucket penyimpanan GCS tempat cadangan Anda disimpan, dalam format: gs://bucket_name. gs:// wajib diisi.
    Contoh:
    namespace: cassandra-restore
    
    cassandra:
      storage:
        type: gcepd
        capacity: 50Gi
        gcepd:
          replicationType: regional-pd
      sslRootCAPath: "/Users/myhome/ssh/cassandra.crt"
      sslCertPath: "/Users/myhome/ssh/cassandra.crt"
      sslKeyPath: "/Users/myhome/ssh/cassandra.key"
      auth:
        default:
          password: "abc123"
        admin:
          password: "abc234"
        ddl:
          password: "abc345"
        dml:
          password: "abc456"
      nodeSelector:
        key: cloud.google.com/gke-nodepool
        value: apigee-data
      restore:
        enabled: true
        snapshotTimestamp: "20190417002207"
        serviceAccountPath: "/Users/myhome/.ssh/my_cassandra_backup.json"
        dbStorageBucket: "gs://myname-cassandra-backup"
        image:
          pullPolicy: Always

    Dengan snapshotTimestamp adalah stempel waktu yang terkait dengan cadangan yang Anda pulihkan.

  6. Buat cluster Cassandra baru:
      ./apigeectl apply -c 2_cassandra -v beta2 -f ./overrides-restore.yaml
      ./apigeectl apply -c 2_cassandra-role -v beta2 

Melihat log pemulihan

Anda dapat memeriksa log tugas pemulihan dan grep untuk error guna memastikan log pemulihan tidak memiliki error.

Memverifikasi bahwa pemulihan telah selesai

Untuk memeriksa apakah operasi pemulihan telah selesai:

kubectl get pods

NAME                           READY     STATUS      RESTARTS   AGE
apigee-cassandra-0             1/1       Running     0          1h
apigee-cassandra-1             1/1       Running     0          1h
apigee-cassandra-2             1/1       Running     0          59m
apigee-cassandra-restore-b4lgf 0/1       Completed   0          51m

Melihat log pemulihan

Untuk melihat log pemulihan:

kubectl logs -f apigee-cassandra-restore-b4lgf

Restore Logs:

Activated service account credentials for: [apigee-cassandra-backup-svc@gce-myusername.]
to download file gs://gce-myusername-apigee-cassandra-backup/apigeecluster/dc-1/backup_20190405011309_schema.tgz
INFO: download sucessfully extracted the backup files from gs://gce-myusername-apigee-cassandra-backup/apigeecluster/dc-1
finished downloading schema.cql
to create schema from 10.32.0.28

Warnings :
dclocal_read_repair_chance table option has been deprecated and will be removed in version 4.0

dclocal_read_repair_chance table option has been deprecated and will be removed in version 4.0


Warnings :
dclocal_read_repair_chance table option has been deprecated and will be removed in version 4.0

dclocal_read_repair_chance table option has been deprecated and will be removed in version 4.0

INFO: the schema has been restored
starting apigee-cassandra-0 in default
starting apigee-cassandra-1 in default
starting apigee-cassandra-2 in default
84 95 106
waiting on waiting nodes $pid to finish  84
Activated service account credentials for: [apigee-cassandra-backup-svc@gce-myusername.]
Activated service account credentials for: [apigee-cassandra-backup-svc@gce-myusername.]
Activated service account credentials for: [apigee-cassandra-backup-svc@gce-myusername.]
INFO: restore downloaded  tarball and extracted the file from  gs://gce-myusername-apigee-cassandra-backup/apigeecluster/dc-1
INFO: restore downloaded  tarball and extracted the file from  gs://gce-myusername-apigee-cassandra-backup/apigeecluster/dc-1
INFO: restore downloaded  tarball and extracted the file from  gs://gce-myusername-apigee-cassandra-backup/apigeecluster/dc-1
INFO  12:02:28 Configuration location: file:/etc/cassandra/cassandra.yaml
…...

INFO  12:02:41 [Stream #e013ee80-5863-11e9-8458-353e9e3cb7f9] All sessions completed

Summary statistics:
   Connections per host    : 3
   Total files transferred : 2
   Total bytes transferred : 0.378KiB
   Total duration          : 5048 ms
   Average transfer rate   : 0.074KiB/s
   Peak transfer rate      : 0.075KiB/s

progress: [/10.32.1.155]0:1/1 100% 1:1/1 100% [/10.32.0.28]1:1/1 100% 0:1/1 100% [/10.32.3.220]0:1/1 100% 1:1/1 100% total: 100% 0.000KiB/s (avg: 0.074KiB/s)
INFO  12:02:41 [Stream #e013ee80-5863-11e9-8458-353e9e3cb7f9] All sessions completed
progress: [/10.32.1.155]0:1/1 100% 1:1/1 100% [/10.32.0.28]1:1/1 100% 0:1/1 100% [/10.32.3.220]0:1/1 100% 1:1/1 100% total: 100% 0.000KiB/s (avg: 0.074KiB/s)
INFO  12:02:41 [Stream #e013ee80-5863-11e9-8458-353e9e3cb7f9] All sessions completed
INFO  12:02:41 [Stream #e013ee80-5863-11e9-8458-353e9e3cb7f9] All sessions completed
INFO: ./apigee/data/cassandra/data/ks1/user-9fbae960571411e99652c7b15b2db6cc restored successfully
INFO: Restore 20190405011309 completed
INFO: ./apigee/data/cassandra/data/ks1/user-9fbae960571411e99652c7b15b2db6cc restored successfully
INFO: Restore 20190405011309 completed
waiting on waiting nodes $pid to finish  106
Restore finished

Memverifikasi tugas pencadangan

Anda juga dapat memverifikasi tugas pencadangan setelah cronjob pencadangan Anda dijadwalkan. Sesudah {i>cronjob<i} telah dijadwalkan, Anda akan melihat sesuatu seperti ini:

kubectl get pods
NAME                        READY     STATUS      RESTARTS   AGE
apigee-cassandra-0          1/1       Running     0          2h
apigee-cassandra-1          1/1       Running     0          2h
apigee-cassandra-2          1/1       Running     0          2h
apigee-cassandra-backup-1554515580-pff6s   0/1       Running     0          54s

Memeriksa log pencadangan

Tugas pencadangan:

  • Membuat file schema.cql.
  • Menguploadnya ke bucket penyimpanan Anda.
  • Menggemakan {i>node<i} untuk mencadangkan data dan mengunggahnya di perangkat lain di waktu yang sama.
  • Menunggu hingga semua data diupload.
kubectl logs -f apigee-cassandra-backup-1554515580-pff6s

myusername-macbookpro:cassandra-backup-utility myusername$ kubectl logs -f apigee-cassandra-backup-1554577680-f9sc4
starting apigee-cassandra-0 in default
starting apigee-cassandra-1 in default
starting apigee-cassandra-2 in default
35 46 57
waiting on process  35
Activated service account credentials for: [apigee-cassandra-backup-svc@gce-myusername.]
Activated service account credentials for: [apigee-cassandra-backup-svc@gce-myusername.]
Activated service account credentials for: [apigee-cassandra-backup-svc@gce-myusername.]
Requested creating snapshot(s) for [all keyspaces] with snapshot name [20190406190808] and options {skipFlush=false}
Snapshot directory: 20190406190808
INFO: backup created cassandra snapshot 20190406190808
tar: Removing leading `/' from member names
/apigee/data/cassandra/data/ks1/mytest3-37bc2df0587811e98e8d875b0ed64754/snapshots/
/apigee/data/cassandra/data/ks1/mytest3-37bc2df0587811e98e8d875b0ed64754/snapshots/20190406190808/
/apigee/data/cassandra/data/ks1/mytest3-37bc2df0587811e98e8d875b0ed64754/snapshots/20190406190808/mc-1-big-Data.db
Requested creating snapshot(s) for [all keyspaces] with snapshot name [20190406190808] and options {skipFlush=false}
Requested creating snapshot(s) for [all keyspaces] with snapshot name [20190406190808] and options {skipFlush=false}
Snapshot directory: 20190406190808
INFO: backup created cassandra snapshot 20190406190808
tar: Removing leading `/' from member names
/apigee/data/cassandra/data/system/hints-2666e20573ef38b390fefecf96e8f0c7/snapshots/
/apigee/data/cassandra/data/system/hints-2666e20573ef38b390fefecf96e8f0c7/snapshots/20190406190808/
/apigee/data/cassandra/data/system/hints-2666e20573ef38b390fefecf96e8f0c7/snapshots/20190406190808/manifest.json
/apigee/data/cassandra/data/system/prepared_statements-18a9c2576a0c3841ba718cd529849fef/snapshots/
/apigee/data/cassandra/data/system/prepared_statements-18a9c2576a0c3841ba718cd529849fef/snapshots/20190406190808/
/apigee/data/cassandra/data/system/prepared_statements-18a9c2576a0c3841ba718cd529849fef/snapshots/20190406190808/manifest.json
/apigee/data/cassandra/data/system/range_xfers-55d764384e553f8b9f6e676d4af3976d/snapshots/
/apigee/data/cassandra/data/system/range_xfers-55d764384e553f8b9f6e676d4af3976d/snapshots/20190406190808/
/apigee/data/cassandra/data/system/range_xfers-55d764384e553f8b9f6e676d4af3976d/snapshots/20190406190808/manifest.json
/apigee/data/cassandra/data/system/peer_events-59dfeaea8db2334191ef109974d81484/snapshots/
/apigee/data/cassandra/data/system/peer_events-59dfeaea8db2334191ef109974d81484/snapshots/20190406190808/
/apigee/data/cassandra/data/system/peer_events-59dfeaea8db2334191ef109974d81484/snapshots/20190406190808/manifest.json
/apigee/data/cassandra/data/system/built_views-4b3c50a9ea873d7691016dbc9c38494a/snapshots/
/apigee/data/cassandra/data/system/built_views-4b3c50a9ea873d7691016dbc9c38494a/snapshots/20190406190808/
/apigee/data/cassandra/data/system/built_views-4b3c50a9ea873d7691016dbc9c38494a/snapshots/20190406190808/manifest.json
……
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-3-big-Filter.db
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-2-big-CompressionInfo.db
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-2-big-Index.db
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-3-big-Statistics.db
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-2-big-Data.db
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-1-big-Index.db
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-1-big-Statistics.db
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-2-big-TOC.txt
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-2-big-Statistics.db
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-1-big-Summary.db
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-1-big-Filter.db
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-2-big-Summary.db
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-3-big-Index.db
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/manifest.json
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-2-big-Filter.db
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-2-big-Digest.crc32
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-3-big-Summary.db
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-3-big-Data.db
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-1-big-TOC.txt
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/schema.cql
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-3-big-CompressionInfo.db
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-1-big-Digest.crc32
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-3-big-TOC.txt
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-1-big-Data.db
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-3-big-Digest.crc32
/apigee/data/cassandra/data/ks2/user-d6d39d70586311e98e8d875b0ed64754/snapshots/20190406190808/mc-1-big-CompressionInfo.db
……
/tmp/tokens.txt
/ [1 files][    0.0 B/    0.0 B]
Operation completed over 1 objects.
/ [1 files][    0.0 B/    0.0 B]
Operation completed over 1 objects.
INFO: backup created tarball and transfered the file to gs://gce-myusername-apigee-cassandra-backup/apigeecluster/dc-1
INFO: removing cassandra snapshot
INFO: backup created tarball and transfered the file to gs://gce-myusername-apigee-cassandra-backup/apigeecluster/dc-1
INFO: removing cassandra snapshot
Requested clearing snapshot(s) for [all keyspaces]
INFO: Backup 20190406190808 completed
waiting on process  46
Requested clearing snapshot(s) for [all keyspaces]
INFO: Backup 20190406190808 completed
Requested clearing snapshot(s) for [all keyspaces]
waiting on process  57
INFO: Backup 20190406190808 completed
waiting result
to get schema from 10.32.0.28
INFO: /tmp/schema.cql has been generated
Activated service account credentials for: [apigee-cassandra-backup-svc@gce-myusername.]
tar: removing leading '/' from member names
tmp/schema.cql
Copying from ...
/ [1 files][    0.0 B/    0.0 B]
Operation completed over 1 objects.
INFO: backup created tarball and transfered the file to gs://gce-myusername-apigee-cassandra-backup/apigeecluster/dc-1
finished uploading schema.cql