Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

BACKUP/MOUNT


To ensure the permanence of the database, the data stored in memory is stored on the disk as soon as possible. In case of a general failure such as Process Failure, Restart Recovery makes the database consistent. However, in case of power failure or hardware damage caused by fire, database recovery is impossible. In order to solve this problem, the database backup and recovery function saves data to another disk or hardware periodically in another area and recovers the data using the corresponding data in case of an emergency.

Database backups are divided into two types depending on when they are performed.

  • Offline Backup
  • Online Backup

First, the Offline Backup function is called Cold Backup as it shuts down the DBMS and copies the database. It is very simple, but it has the disadvantage of the user's service being interrupted. Therefore, it is rarely used during operation and tends to be used only for initial testing or data construction.

Second, Online Backup is called Hot Backup as a function to backup the database when DBMS is running. This function can be performed without interrupting the service, increasing the user's service availability. Most DBMS Backup refers to Online Backup. Unlike other database backups, Machbase, a time-series database, provides Duration Backup. This allows you to specify the time of the database to be backed up at the time of backup so that only the data at the desired time will be backed up.


UI Text Box

Index


Table of Contents



Code Block
backup database into disk = 'backup'; 
backup database from to_date('2015-07-14 00:00:00','YYYY-MM-DD HH24:MI:SS') to to_date('2015-07-14 23:59:59 999:999:999','YYYY-MM-DD HH24:MI:SS mmm:uuu:nnn') 
                into disk = 'backup_20150714';

The backed-up database can be used as an existing database through a recovery process. This recovery method is called Restore. This Restore function deletes the damaged database and restores the backed up database image to the Primary Database. Therefore, when recovering, delete the existing database and restore it using machadmin -r.

Code Block
languagebash
machadmin -r 'backup'

The mount / unmount function is an online function that attaches a backed up database to the currently running database.

Code Block
mount database 'backup' to mountName; 
umount database mountName;


Database Backup

Machbase offers two options for backing up your data. It provides DATABASE backup function which backs up information of running DB and TABLE backup function which can select only necessary tables to back up.
The backup command provided by DB is as follows.

Code Block
BACKUP [ DATABASE | TABLE table_name ]  [ time_duration ] INTO [ DISK | IBFILE ] = 'path/backup_name';
time_duration = FROM start_time TO end_time
path = 'absolute_path' or  'relative_path'


Code Block
# Directory backup
       BACKUP DATABASE INTO DISK = 'backup_dir_name';
# a single file backup  
       BACKUP DATABASE INTO IBFILE = backup_ibfile_name;
# Set backup duration
      - Directory backup
       BACKUP DATABASE FROM TO_DATE('2015-07-14 00:00:00','YYYY-MM-DD HH24:MI:SS')
                         TO TO_DATE('2015-07-14 23:59:59','YYYY-MM-DD HH24:MI:SS')
                         INTO DISK = '/home/machbase/backup_20150714'
     - File backup
       BACKUP DATABASE FROM TO_DATE('2015-07-14 00:00:00','YYYY-MM-DD HH24:MI:SS')
                         TO TO_DATE('2015-07-14 23:59:59','YYYY-MM-DD HH24:MI:SS')
                         INTO IBFILE = '/home/machbase/backup_20150714.ibf'
# a single table backup
      BACKUP TABLE SYSLOG_TABLE INTO IBFILE = '/home/machbase/backup/syslog_table';

When performing a DB backup, the backup type, time duration, and path must be entered as options. When backing up DATABASE entirely, type DATABASE for the backup type. To backup only a specific table, enter TABLE, and then enter the name of the table to be backed up. The TIME_DURATION statement can be set to back up only the data for the required period. In the FROM field, enter the start time of the date you want to back up, and enter the time of the last date in the TO field. In Example 3, the TIME_DURATION is set to FROM, "July 14, 2014, 0, 0, 0", and TO "July 14, 2015, 23:59:59" meaning only 14 days of data are set to be backed up. If information is not entered for the DURATION item, the FROM item is set to 'January 1, 1970, 9:00:00,' and the TO item is automatically set to the time to execute the command.

Finally, a storage medium to store needs to be configured to store the results of the backup. If you want to create a backup in a single file, set the creation type to IBFILE, or enter DISK to create it in directory units. Note that you can specify the PATH information to store the product. If you enter a relative path, it will be created in the path specified in the DB_PATH item of the current DB configuration. If you want to store it somewhere other than DB_PATH, you must enter an absolute path starting with '/'.

Database Restore

The Database Restore feature is not provided as a syntax, and can be recovered offline using machadmin -r. You must check the following before restoration.

  • Has Machbase been shutdown?
  • Has the previously created DB been deleted?
Code Block
languagebash
machadmin -r backup_database_path;


Code Block
backup database into disk = '/home/machbase/backup';


Code Block
languagebash
machadmin -k
machadmin -d
machadmin -r /home/machbase/backup;


Extract Single File

A single backup file created in the form of INTO IBFILE can not be restored immediately, and must be converted to a directory using machadmin.
After the conversion, files in the form of directory backup are created in the path of target_path/backup_file_name.

Code Block
machadmin -x single_file_backup_file_name extract_target_path


Code Block
machadmin -x backup_20150101.ibf /db/data/
machadmin -r /db/data/backup_20150101.ibf/


Single Backup File Information Retrieval

Information about a single backup file created by the backup command can be retrieved with the machadmin -w command.

Code Block
machadmin -w single_backup_file_name


Code Block
machadmin -w ib_backup01
...
Display information of Backup Image successfully.
-----------------------------------------------------------------
     File name        - mach_backup_19700101090000_20150725142017_3
     Create time      - 2015-07-25 14:19:22
     Data duration    - 1970-01-01 09:00:00 ~ 2015-07-25 14:20:17
     Backup duration  - 2015-07-25 14:20:18 ~ 2015-07-25 14:20:18
     Version          - DB(4.0) Meta(1.6) CM(1.5)
---------------------------------------------------------


Database Mount

The following problems arise when periodically backing up a large number of databases and adding data continuously in preparation for a system failure.

  • Increased disk cost to store data
  • Limitations of the physical disk space of the running machine

In order to solve this problem, periodical deletion is performed by leaving only data necessary for the current service. However, if you need to refer to the past data, you need to restore the backed up database. In case of a very large backup image, recovery time is long and additional equipment is needed. This is because the Restore function can only be performed by deleting the currently running database. To solve this problem, Machbase provides the Database Mount function.

The Database Mount function is an online function that attaches a backed up database to the currently running database. By attaching multiple backup databases to the primary database, the user can refer to multiple backup databases as if they were one database. The mounted database is read-only.

The Mount DATABASE command is a function that prepares the database or table DATA created by Backup in a state that it can be viewed from the currently running database. So, Mounted DATABASE can query the data using the same DB command.

The current Database Mount function restrictions are as follows.

  • The backup information must be compatible with the database to be mounted, the DB major number, and the Meta major number.
  • When mounting backup data, it is read-only and does not support index creation, data entry or insertion or deletion.
  • Information about the currently mounted DATABASE can be found by querying V$STORAGE_MOUNT_DATABASES.

Mount

To execute the mount command, Backup_database_path information and DatabaseName are required. Backup_database_path is the location information of the DB created by Backup command. DatabaseName is the name that can be distinguished when mounting to Database. Backup_database_path is searched based on the directory specified in the DB_PATH set in the environment variable of the DB when the relative path is entered in the same way as when performing the backup.

Code Block
MOUNT DATABASE 'backup_database_path' TO mount_name;


Code Block
MOUNT DATABASE '/home/machbase/backup' TO mountdb;


Unmount

If the mounted database will no longer be used, it can be removed using the unmount command.

Code Block
UNMOUNT DATABASE mount_name;


Code Block
UNMOUNT DATABASE mountdb;


MOUNT DB Data Retrieval

When querying DATA of Backup DB, it can be retrieved by using the same SQL statement when querying the DATA of the DB in operation.

The mounted DB can retrieve data only by the SYS admin user of the DB in operation. To retrieve the data, you must put MountDBName and UserName in front of the TableName to be queried, and use '.' for each delimiter. MountDBName is used to refer to a specific DB among currently mounted DBs, and UserName refers to the information of the user that owns the mounted DB table.

Code Block
SELECT column_name FROM mount_name.user_name.table_name;


Code Block
SELECT * FROM mountdb.sys.backuptable;