Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Cơ Sở Dữ Liệu

Cách Sao Lưu Và Khôi Phục An Toàn Vertica Database

Giới Thiệu

Để đảm bảo bạn có thể recover data trong trường hợp data corruption hoặc xóa nhầm, hãy làm database backups thành routine maintenance activity. Bài viết khám phá Vertica® database backup và restoration.

Giới Thiệu

Vertica, một analytic database management system, là columnar-storage platform thiết kế handle large volumes of data, cho phép fast query performance trong scenarios traditionally resource-intensive.

Vertica cung cấp các lợi ích sau:

  • Cải thiện query performance so với traditional relational database management systems.
  • Cung cấp high availability.
  • Cung cấp petabyte scalability trên commodity enterprise servers.

Cơ chế database backup và recovery giảm downtime trong maintenance và disaster recovery.

Backup Và Restore Database

Với Vertica, bạn có thể tạo hot backups, incremental copies với indefinite number of restore points, và backup của entire database hoặc subset (schemas, tables, etc.) của database. Các backup level sau có sẵn:

  • Full level: Level này đảm bảo bạn có thể backup và restore full Vertica database.
  • Incremental level: Level này là backup tiếp theo chỉ bao gồm data mới hoặc thay đổi.
  • Object-level: Level này là backup của object để restore.

Vertica cung cấp flexibility và granularity levels để restore specific objects (như schemas và tables) từ full backup.

Snapshots

Database snapshots capture consistent image của tất cả objects và data trong database. Bạn có thể chọn subset database objects để include trong object-level snapshot, chứa associated data trong database tại thời điểm snapshot và objects khác trong dependency graph. Bạn có thể đặt tên snapshot như thích (ví dụ: snap, objectsnap1, fullsnap, etc.).

Backup Location

Backup location là directory trên backup host nơi bạn lưu snapshots và associated archives. Vì snapshots compatible, bạn có thể dùng bất kỳ object snapshot nào từ cùng backup location sau khi restore database từ full database snapshot. Tất cả snapshots trong cùng backup location share data files qua hard links.

Hard-Link Backups

Vertica cung cấp low cost và space-efficient copies (hard-link local backups) của database backups trong local cluster infrastructure. Bạn có thể retrieve这些 backups nhanh hơn vì system không copy user data đến external backup environment. Vertica chỉ copy catalog data và khởi tạo Linux®-based hard links trong file system.

Cách Sao Lưu Và Khôi Phục An Toàn Vertica Database

Nguồn hình ảnh: https://www.vertica.com/wp-content/uploads/2016/04/sidestep1.png

Các backup này share cùng set storage blocks, và mỗi backup track point-in-time copy của họ. System không lưu same content ở multiple locations.

Backup Và Restoration Process Flow

Backup và restoration flow bao gồm các bước sau:

  1. Chọn snapshot type: full, incremental, hoặc object-level backup.
  2. Tạo configuration file dùng Vertica Backup and Recovery tool.
  3. Khởi tạo backup location để lưu backup files.
  4. Lấy backup dùng configuration file.
  5. Verify backups trong backup location.
  6. Restore full database hoặc database objects trên similar hoặc different Vertica clusters.
Cách Sao Lưu Và Khôi Phục An Toàn Vertica Database

Nguồn hình ảnh: https://www.vertica.com/kb/Copy-and-Restore-Data-from-a-Vertica-Cluster-to-a-Backup/Content/BestPractices/Copy-and-Restore-Data-from-a-Vertica-Cluster-to-a-Backup.htm

Tạo Configuration File

Tiện ích vbr.py tạo configuration file với thông tin Vertica yêu cầu để backup và restore full, incremental, hoặc object-level snapshots. Bạn không thể backup hoặc restore databases hoặc objects không có configuration file, và không có default file.

Bạn có thể tạo bao nhiêu backup configuration files tùy cần (full hoặc incremental, object hoặc schema-specific, hoặc location-specific files).

Full Backup Configuration File

Các bước sau giúp tạo configuration file để lấy full database backup.

$ vbr.py --setupconfig
Snapshot name (backup_snapshot): full_bkp_snap
Backup vertica configurations? (n) [y/n]: y
Number of restore points (1):
Specify objects (no default):
Vertica user name (dbadmin): dbadmin
Save password to avoid runtime prompt? (n) [y/n]: n
Node v_testdb_node0001
Backup host name (no default): v_testdb_node0001
Backup directory (no default): /vert_backup/backup
Node v_testdb_node0002
Backup host name (no default): v_testdb_node0002
Backup directory (no default): /vert_backup/backup
Node v_testdb_node0003
Backup host name (no default): v_testdb_node0003
Backup directory (no default): /vert_backup/backup
Config file name (full_bkp_snap.ini): /vert_backup/backup_conf/full_bkp_snap.ini
Change advanced settings? (n) [y/n]: n
Saved vbr configuration to /vert_backup/backup_conf/full_bkp_snap.ini. 

Object-Specific Backup Configuration File

Thực hiện các bước sau để tạo object-specific configuration file:

  1. Liệt kê objects trong database và chọn cái nào dùng. Objects sau present trong Vertica database:
List of tables
Schema | Name | Kind | Owner | Comment
--------+-------+-------+---------+---------
public | tab1 | table | dbadmin |
public | tab2 | table | dbadmin |
public | tab3 | table | dbadmin |
(3 rows) 
  1. Chạy lệnh sau để tạo configuration file backup public.tab1 table:
$ vbr.py --setupconfig
Snapshot name (backup_snapshot): tab1_bkp_snap
Backup vertica configurations? (n) [y/n]: n
Number of restore points (1):
Specify objects (no default): public.tab1
Vertica user name (dbadmin): dbadmin
Save password to avoid runtime prompt? (n) [y/n]: n
Node v_testdb_node0001
Backup host name (no default): v_testdb_node0001
Backup directory (no default): /vert_backup/backup
Node v_testdb_node0002
Backup host name (no default): v_testdb_node0002
Backup directory (no default): /vert_backup/backup
Node v_testdb_node0003
Backup host name (no default): v_testdb_node0003
Backup directory (no default): /vert_backup/backup
Config file name (tab1_bkp_snap.ini): /vert_backup/backup_conf/tab1_bkp_snap.ini
Change advanced settings? (n) [y/n]: n
Saved vbr configuration to /vert_backup/backup_conf/tab1_bkp_snap.ini. 
  1. Chạy lệnh sau để liệt kê created backup configuration files:
$ cd /vert_backup/backup_conf/
$ ls -la
total 20
drwxr-xr-x. 2 dbadmin dbadmin 4096 Jan 20 14:21 .
-rw-rw-r--. 1 dbadmin dbadmin 488 Jan 20 14:21 tab1_bkp_snap.ini
-rw-rw-r--. 1 dbadmin dbadmin 475 Jan 20 14:04 full_bkp_snap.ini 

Khởi Tạo Backup Location

Để khởi tạo backup locations cho full và object-level backups trên source cluster, chạy các statement init sau:

$ /opt/vertica/bin/vbr.py -t init --config-file full_bkp_snap.ini
$ /opt/vertica/bin/vbr.py -t init --config-file tab1_bkp_snap.ini 

Lấy Backup

Lấy full database hoặc object-level backup.

Full Database Backup

Lấy full database backup dùng configuration file trước tạo, full_bkp_snap.ini:

$ vbr.py --task backup --config-file full_bkp_snap.ini
Please input vertica password: pparing...
Found Database port: 5433
Copying... 348900 out of 348900, 100%
All child processes terminated successfully.
Committing changes on all backup sites...
backup done! 

Single Object Backup

Dùng configuration file tab1_bkp_snap.ini lấy object-level backup:

$ vbr.py --task backup --config-file tab1_bkp_snap.ini
Please input vertica password: pparing...
Found Database port: 5433
Copying... 78920 out of 78920, 100%
All child processes terminated successfully.
Committing changes on all backup sites...
backup done! 

Verify Backup Location

Chạy lệnh sau verify backup location:

$ cd vert_backup/
$ ls -la
total 16
drwxr-xr-x. 4 dbadmin dbadmin 4096 Jan 20 13:40 .
dr-xr-xr-x. 28 root root 4096 Jan 20 13:53 ..
drwxr-xr-x. 5 dbadmin dbadmin 4096 Jan 20 15:22 backup
drwxr-xr-x. 2 dbadmin dbadmin 4096 Jan 20 15:29 backup_conf
$ cd backup/
$ ll
total 12
drwxrwxr-x. 8 dbadmin dbadmin 4096 Jan 20 15:29 v_testdb_node0001
drwxrwxr-x. 8 dbadmin dbadmin 4096 Jan 20 15:29 v_testdb_node0002
drwxrwxr-x. 8 dbadmin dbadmin 4096 Jan 20 15:29 v_testdb_node0003
$ cd v_testdb_node0001/
$ ll
total 12
drwx------. 3 dbadmin dbadmin 4096 Jan 20 15:29 tab1_bkp_snap
drwx------. 3 dbadmin dbadmin 4096 Jan 20 15:22 full_bkp_snap 

Restore Backup

Restore full hoặc object-level backup.

Restore Từ Full Database Backup

Lưu ý: Database phải down để restore full backup.

Dùng các bước sau thực hiện full-database restore:

  1. Drop tất cả objects trong database và restore với backup gần tạo:
cluster=> dt
List of tables
Schema | Name | Kind | Owner | Comment
--------+-------+-------+---------+---------
public | tab1 | table | dbadmin |
public | tab2 | table | dbadmin |
public | tab3 | table | dbadmin |
(3 rows)
cluster=> drop table tab1,tab2,tab3;
DROP TABLE
cluster=> dt
No relations found. 
  1. Với database down, restore database dùng full backup:
$ vbr.py --task restore --config-file full_bkp_snap.ini
Please input vertica password:
Preparing...
Found Database port: 5433
Copying... 248556 out of 248556, 100%
All child processes terminated successfully.
restore done! 
  1. Khởi động database và kiểm tra object restoration succeeded. Ví dụ sau cho thấy restore succeeded:
cluster=> dt
List of tables
Schema | Name | Kind | Owner | Comment
--------+-------+-------+---------+---------
public | tab1 | table | dbadmin |
public | tab2 | table | dbadmin |
public | tab3 | table | dbadmin |
(3 rows) 

Restore Object-Level Backup

Lưu ý: Database phải up và running cho object-level restore.

Để restore object, bạn cần dùng existing object-level backup. Code sau drop tab1 chuẩn bị restoration:

cluster=> drop table tab1;
DROP TABLE
cluster=> dt
List of tables
Schema | Name | Kind | Owner | Comment
-------+-------+-------+---------+---------
public | tab2 | table | dbadmin |
public | tab3 | table | dbadmin |
(2 rows) 

Thực hiện các bước sau restore object từ object-level backup:

  1. Restore object:
$ vbr.py --task restore --config-file tab1_bkp_snap.ini
Please input vertica password:xxxxxxxx
Preparing...
Found Database port: 5433
Copying... out of , 100%
All child processes terminated successfully.
Copying... 2970 out of 2970, 100%
All child processes terminated successfully.
restore done! 
  1. Kiểm tra object restoration succeeded. Ví dụ sau cho thấy successful restoration public.tab1 từ object-level backup:
$ vsql
Password:xxxxxxx
dbadmin=> dt
List of tables
Schema | Name | Kind | Owner | Comment
--------+-------+-------+---------+---------
public | tab1 | table | dbadmin |
public | tab2 | table | dbadmin |
public | tab3 | table | dbadmin |
(3 rows)
dbadmin=> d tab1 ;
List of Fields by Tables
Schema | Table | Column | Type | Size | Default | Not Null | Primary Key | Foreign Key
--------+-------+--------+--------------+------+---------+----------+-------------+-------------
public | tab1 | col1 | numeric(3,) | 8 | | f | f | 

Kết Luận

Bài viết highlight logic đằng sau Vertica database backup và recovery process. Nó cũng cung cấp steps backup và restore Vertica database ở các level: full, incremental, và object-level.