Pencadangan dan pemulihan Cassandra

Bagian ini membahas cara mengonfigurasi pencadangan dan pemulihan data untuk ring database Apache Cassandra yang diinstal di platform runtime hybrid Apigee. Lihat juga Database Cassandra.

Yang perlu Anda ketahui tentang pencadangan Cassandra

Cassandra adalah database yang direplikasi dan dikonfigurasi untuk memiliki minimal 3 salinan data Anda di setiap region atau pusat data. Cassandra menggunakan replikasi streaming dan perbaikan baca untuk mempertahankan replika data di setiap region atau pusat data pada waktu tertentu.

Dalam mode campuran, pencadangan Cassandra tidak diaktifkan secara default. Namun, sebaiknya aktifkan pencadangan Cassandra jika data Anda tidak sengaja dihapus.

Apa yang dicadangkan?

Konfigurasi pencadangan yang dijelaskan dalam topik ini mencadangkan entity berikut:

  • Skema Cassandra termasuk skema pengguna (definisi ruang kunci Apigee)
  • Informasi token partisi Cassandra per node
  • Snapshot data Cassandra

Di mana data cadangan disimpan?

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

Menjadwalkan pencadangan Cassandra

Pencadangan dijadwalkan sebagai tugas cron di platform runtime. Untuk menjadwalkan pencadangan Cassandra:

  1. Jalankan perintah create-service-account berikut untuk membuat akun layanan (SA) GCP dengan peran roles/storage.objectAdmin standar. Peran SA ini memungkinkan Anda menulis data cadangan ke Google Cloud Storage (GCS). Jalankan perintah berikut di direktori root penginstalan campuran:
    ./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. 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 kebijakan retensi data yang wajar untuk bucket. Apigee merekomendasikan kebijakan retensi data selama 15 hari.
  4. Buka file overrides.yaml.
  5. Tambahkan properti cassandra.backup berikut untuk mengaktifkan pencadangan. Jangan hapus properti 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 menetapkan properti ini ke true
    serviceAccountPath Jalur di sistem file Anda ke file JSON akun layanan 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 saat pencadangan dimulai, 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. 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 cadangan dan memulihkannya ke cluster Cassandra baru dengan jumlah pod yang sama. Cluster baru harus memiliki namespace yang berbeda dengan cluster platform runtime Anda.

Untuk memulihkan cadangan Cassandra:

  1. Buat cluster Kubernetes baru dengan namespace baru. Anda tidak dapat menggunakan cluster/namespace yang sama dengan yang digunakan untuk penginstalan hybrid asli.
  2. Di direktori penginstalan campuran root, buat file overrides-restore.yaml baru.
  3. Salin konfigurasi Cassandra lengkap dari file overrides.yaml asli ke file baru.
  4. Tambahkan elemen namespace. Jangan gunakan namespace yang sama dengan yang Anda gunakan untuk cluster 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 database Cassandra asli.
    snapshotTimestamp Stempel waktu snapshot cadangan yang akan dipulihkan.
    serviceAccountPath Jalur di sistem file Anda ke akun layanan yang Anda buat untuk pencadangan.
    dbStorageBucket Jalur bucket penyimpanan GCS tempat cadangan Anda disimpan, dalam format ini: 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 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.iam.gserviceaccount.com]
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.iam.gserviceaccount.com]
Activated service account credentials for: [apigee-cassandra-backup-svc@gce-myusername.iam.gserviceaccount.com]
Activated service account credentials for: [apigee-cassandra-backup-svc@gce-myusername.iam.gserviceaccount.com]
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 dijadwalkan. Setelah cronjob dijadwalkan, Anda akan melihat tampilan 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.
  • Menampilkan node untuk mencadangkan data dan menguploadnya secara bersamaan.
  • 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.iam.gserviceaccount.com]
Activated service account credentials for: [apigee-cassandra-backup-svc@gce-myusername.iam.gserviceaccount.com]
Activated service account credentials for: [apigee-cassandra-backup-svc@gce-myusername.iam.gserviceaccount.com]
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.iam.gserviceaccount.com]
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