Server

Compressing Backup by Named Pipe

posted Jul 17, 2020

Author: Sungjin Kim

 

CUBRID 10.2 was released on December 18 last year. Starting from this version, named pipes can be used for backup.

 

Named Pipe

When pipes are used to connect commands, or when using command or process substitution, pipes are automatically created and used during command execution and then disappear.

 

The pipe created at this time is called an unnamed pipe or anonymous pipe because there is no name. On the other hand, the named pipe makes a file directly and uses it.

 

Now let's create a Named Pipe! One way to create it will be like this: 

$ mkfifo backup_pipe
$ ls -al backup_pipe
prw-rw-r--. 1 hiclass hiclass 0 May 25 10:40 backup_pipe

 Or 

$ mknod backup_pipe p
$ ls -al backup_pipe
prw-rw-r--. 1 hiclass hiclass 0 May 25 10:40 backup_pipe

 

Now let's back up using the created pipe. First, for capacity comparison, let's do a normal backup without pipes.

$ cubrid backupdb demodb -S -l 0 -z -D . -o bk.out
Backup Volume Label: Level: 0, Unit: 0, Database demodb, Backup Time: Mon May 25 10:30:50 2020
$ ll
total 251124
prw-rw-r--. 1 hiclass hiclass         0 May 25 10:29 backup_pipe
-rw-------. 1 hiclass hiclass      1000 May 25 10:30 bk.out
-rw-------. 1 hiclass hiclass 134217728 May 25 10:30 demodb
-rw-------. 1 hiclass hiclass   6304768 May 25 10:30 demodb_bk0v000
-rw-------. 1 hiclass hiclass        64 May 25 10:30 demodb_bkvinf
-rw-------. 1 hiclass hiclass 104857600 May 25 10:30 demodb_lgar_t
-rw-------. 1 hiclass hiclass 104857600 May 25 10:30 demodb_lgat
-rw-------. 1 hiclass hiclass       221 May 25 10:28 demodb_lginf
-rw-rw-r--. 1 hiclass hiclass      2414 May 25 10:28 demodb_loaddb.log
-rw-------. 1 hiclass hiclass       298 May 25 10:28 demodb_vinf
drwxrwxr-x. 2 hiclass hiclass         6 Mar 12 12:20 lob

-rw-------. 1 hiclass hiclass   6304768 May 25 10:30 demodb_bk0v000

The capacity of the backup file is about 6.1M.

 

Now, let's do a compressed backup using the named pipe.

$ cubrid backupdb demodb -S -l 0 -z -D backup_pipe -o bk.out & cat backup_pipe | gzip > demodb_bk0v000.gz
[1] 7483
Backup Volume Label: Level: 0, Unit: 0, Database demodb, Backup Time: Mon May 25 10:30:59 2020
$ 
[1]+  Done                    cubrid backupdb demodb -S -l 0 -z -D backup_pipe -o bk.out
$ ls -al
total 254172
drwxrwxr-x. 3 hiclass hiclass       236 May 25 10:30 .
drwxrwxr-x. 5 hiclass hiclass       103 May 25 10:28 ..
prw-rw-r--. 1 hiclass hiclass         0 May 25 10:30 backup_pipe
-rw-------. 1 hiclass hiclass      1000 May 25 10:30 bk.out
-rw-------. 1 hiclass hiclass 134217728 May 25 10:30 demodb
-rw-------. 1 hiclass hiclass   6304768 May 25 10:30 demodb_bk0v000
-rw-rw-r--. 1 hiclass hiclass   3117962 May 25 10:30 demodb_bk0v000.gz
-rw-------. 1 hiclass hiclass        61 May 25 10:30 demodb_bkvinf
-rw-------. 1 hiclass hiclass 104857600 May 25 10:30 demodb_lgar_t
-rw-------. 1 hiclass hiclass 104857600 May 25 10:30 demodb_lgat
-rw-------. 1 hiclass hiclass       221 May 25 10:28 demodb_lginf
-rw-rw-r--. 1 hiclass hiclass      2414 May 25 10:28 demodb_loaddb.log
-rw-------. 1 hiclass hiclass       298 May 25 10:28 demodb_vinf
drwxrwxr-x. 2 hiclass hiclass         6 Mar 12 12:20 lob

-rw-rw-r--. 1 hiclass hiclass   3117962 May 25 10:30 demodb_bk0v000.gz

The backup file has a capacity of about 3M.

 

In addition to the above method, backup using pipe can be directly transferred to another server using ssh. Also, because the above method is backed up using a FIFO pipe, it can be used even when there is insufficient physical space.

 

I hope you can use the new method of backup to help DBA role.