Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
joohanhong
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
JooHan Hong
joohanhong
Commits
cef2f65a
Commit
cef2f65a
authored
Mar 02, 2021
by
nuxer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dbms 백업추가
parent
de486174
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
218 additions
and
0 deletions
+218
-0
README.md
DBMS/DOCKER/BACKUP/README.md
+218
-0
No files found.
DBMS/DOCKER/BACKUP/README.md
0 → 100644
View file @
cef2f65a
[
![logo
](
https://www.hongsnet.net/images/logo.gif
)
](https://www.hongsnet.net)
# MariaDB Backup 구성
> mariabackup을 이용한 일일/증분 백업을 수행한다.
# DB 백업 구성
*
[
]
mariabackup을 이용한 일일백업 ( 경로는 /BACKUP/$service/FULL )
*
[
]
mariabackup을 이용한 증분백업 ( 경로는 /BACKUP/$service/INC )
*
[
]
Backup DATA Review
## mariabackup을 이용한 백업 스크립트 전체
```
bash
# cat /BACKUP/scripts/mariabackup.sh
#!/bin/bash
# Description : MariaDB Full/Inc Backup Script
date
=
`
date
+
"%Y-%m-%d"
`
service
=
"HONGSNET"
dst
=
"/BACKUP/
$service
/FULL"
incdir
=
"/BACKUP/
$service
/INC"
xbk
=
"/usr/bin/mariabackup"
user
=
"아이디"
password
=
"패스워드"
slave
=
"no"
# yes | no
inc
=
30
mkdir
-p
$dst
||
exit
1
mkdir
-p
$incdir
||
exit
1
ulimit
-Sn
65535
ulimit
-Hn
65535
############ FULL ############
if
[
!
-d
$dst
/0
]
;
then
#최초 백업이라면..
if
[[
$slave
==
"yes"
]]
;
then
$xbk
--backup
--slave-info
--target-dir
${
dst
}
/0
--user
${
user
}
--password
${
password
}
else
$xbk
--backup
--no-lock
--target-dir
${
dst
}
/0
--user
${
user
}
--password
${
password
}
fi
else
#최초 백업이 완료되었고, 증분을 수행해야할 경우
if
[[
$slave
==
"yes"
]]
;
then
$xbk
--backup
--slave-info
--target-dir
${
dst
}
/1
--incremental-basedir
${
dst
}
/0
--user
${
user
}
--password
${
password
}
if
[[
-d
${
incdir
}
/
$date
]]
;
then
rm
-rf
${
incdir
}
/
$date
else
cp
-rf
${
dst
}
/1
${
incdir
}
/
$date
fi
else
$xbk
--backup
--no-lock
--target-dir
${
dst
}
/1
--incremental-basedir
${
dst
}
/0
--user
${
user
}
--password
${
password
}
if
[[
-d
${
incdir
}
/
$date
]]
;
then
rm
-rf
${
incdir
}
/
$date
else
cp
-rf
${
dst
}
/1
${
incdir
}
/
$date
fi
fi
#매일 백업된 전체백업의 준비를 한다. 만약 이 과정을 무시하면, 다음의 에러가 발생된다.
#error: applying incremental backup needs a prepared target.
$xbk
--prepare
--target-dir
${
dst
}
/0
#위의 준비가 완료되었으면, 실제로 매일 백업된 증분백업을 전체백업으로 합친다.
$xbk
--prepare
--target-dir
${
dst
}
/0
--incremental-dir
${
dst
}
/1
--user
${
user
}
--password
${
password
}
#이 과정은 전체백업에 대한 부분이므로, 증분백업된 내역은 제거한다.
rm
-rf
${
dst
}
/1
fi
find
$incdir
/
-ctime
+
${
inc
}
-exec
rm
-rf
{}
\;
```
!참고 : Master DBMS가 대상일 경우
**slave=no**
, Slave DBMS가 대상일 경우
**slave=yes**
## mariabackup을 이용한 일일백업
```
bash
if
[
!
-d
$dst
/0
]
;
then
#최초 백업이라면..
if
[[
$slave
==
"yes"
]]
;
then
$xbk
--backup
--slave-info
--target-dir
${
dst
}
/0
--user
${
user
}
--password
${
password
}
else
$xbk
--backup
--no-lock
--target-dir
${
dst
}
/0
--user
${
user
}
--password
${
password
}
fi
```
> BACKUP 디렉토리에 0 디렉토리가 존재하지 않는다면, 최초 백업으로 간주한다.
## mariabackup을 이용한 증분백업
```
bash
else
#최초 백업이 완료되었고, 증분을 수행해야할 경우
if
[[
$slave
==
"yes"
]]
;
then
$xbk
--backup
--slave-info
--target-dir
${
dst
}
/1
--incremental-basedir
${
dst
}
/0
--user
${
user
}
--password
${
password
}
if
[[
-d
${
incdir
}
/
$date
]]
;
then
rm
-rf
${
incdir
}
/
$date
else
cp
-rf
${
dst
}
/1
${
incdir
}
/
$date
fi
else
$xbk
--backup
--no-lock
--target-dir
${
dst
}
/1
--incremental-basedir
${
dst
}
/0
--user
${
user
}
--password
${
password
}
if
[[
-d
${
incdir
}
/
$date
]]
;
then
rm
-rf
${
incdir
}
/
$date
else
cp
-rf
${
dst
}
/1
${
incdir
}
/
$date
fi
fi
#매일 백업된 전체백업의 준비를 한다. 만약 이 과정을 무시하면, 다음의 에러가 발생된다.
#error: applying incremental backup needs a prepared target.
$xbk
--prepare
--target-dir
${
dst
}
/0
#위의 준비가 완료되었으면, 실제로 매일 백업된 증분백업을 전체백업으로 합친다.
$xbk
--prepare
--target-dir
${
dst
}
/0
--incremental-dir
${
dst
}
/1
--user
${
user
}
--password
${
password
}
#이 과정은 전체백업에 대한 부분이므로, 증분백업된 내역은 제거한다.
rm
-rf
${
dst
}
/1
fi
```
**- 지정된 날짜가 지난 증분백업 제거**
```
bash
find
$incdir
/
-ctime
+
${
inc
}
-exec
rm
-rf
{}
\;
```
!참고 : 대상이 되는 디렉토리는
`/BACKUP/$service/INC/`
이다.
## Backup DATA Review
**- 전체 백업**
```
bash
# ls -al /BACKUP/HONGSNET/FULL/0/
total 143532
drwx------ 12 root root 4096 Mar 2 01:03
.
drwxr-xr-x 3 root root 15 Mar 2 01:03 ..
-rw-r-----
1 root root 32768 Mar 2 01:03 aria_log.00000001
-rw-r-----
1 root root 52 Mar 2 01:03 aria_log_control
-rw-r-----
1 root root 324 Dec 12 00:44 backup-my.cnf
drwx------ 2 root root 8192 Mar 2 01:03 edu
drwx------ 2 root root 8192 Mar 2 01:03 hjh
-rw-r-----
1 root root 23455 Dec 12 00:44 ib_buffer_pool
-rw-r-----
1 root root 146800640 Mar 2 01:03 ibdata1
-rw-r-----
1 root root 0 Dec 14 03:20 ib_logfile0
drwx------ 2 root root 4096 Mar 2 01:03 ldswork
drwxr-x--- 2 root root 8192 Mar 2 01:03 MATTERMOST
drwx------ 2 root root 4096 Mar 2 01:03 mysql
drwx------ 2 root root 16384 Mar 2 01:03 newhongsystem
drwx------ 2 root root 20 Mar 2 01:03 performance_schema
drwx------ 2 root root 8192 Mar 2 01:03 tech
drwx------ 2 root root 28 Mar 2 01:03
test
-rw-r-----
1 root root 41 Mar 2 01:03 xtrabackup_binlog_info
-rw-r-----
1 root root 85 Mar 2 01:03 xtrabackup_checkpoints
-rw-r-----
1 root root 644 Mar 2 01:03 xtrabackup_info
drwxr-x--- 2 root root 12288 Mar 2 01:03 ZABBIXDB
```
**- 증분 백업**
```
bash
# ls -al /BACKUP/HONGSNET/INC/
total 128
drwxr-xr-x 33 root root 4096 Mar 2 01:03
.
drwxr-xr-x 4 root root 47 Jan 16 05:17 ..
drwx------ 12 root root 4096 Jan 31 01:01 2021-01-31
drwx------ 12 root root 4096 Feb 1 01:01 2021-02-01
drwx------ 12 root root 4096 Feb 2 01:01 2021-02-02
drwx------ 12 root root 4096 Feb 3 01:01 2021-02-03
drwx------ 12 root root 4096 Feb 4 01:01 2021-02-04
drwx------ 12 root root 4096 Feb 5 01:01 2021-02-05
drwx------ 12 root root 4096 Feb 6 01:01 2021-02-06
drwx------ 12 root root 4096 Feb 7 01:01 2021-02-07
drwx------ 12 root root 4096 Feb 8 01:00 2021-02-08
...하략
```
아래는 특정 일자에 대한 세부적인 확인결과 이다.
```
bash
# ls -al /BACKUP/HONGSNET/INC/2021-02-25/
total 18924
drwx------ 12 root root 4096 Feb 25 01:02
.
drwxr-xr-x 33 root root 4096 Mar 2 01:03 ..
-rw-r-----
1 root root 32768 Feb 25 01:02 aria_log.00000001
-rw-r-----
1 root root 52 Feb 25 01:02 aria_log_control
-rw-r-----
1 root root 324 Feb 25 01:02 backup-my.cnf
drwx------ 2 root root 12288 Feb 25 01:01 edu
drwx------ 2 root root 12288 Feb 25 01:01 hjh
-rw-r-----
1 root root 1268090 Feb 25 01:02 ib_buffer_pool
-rw-r-----
1 root root 16515072 Feb 25 01:01 ibdata1.delta
-rw-r-----
1 root root 45 Feb 25 01:01 ibdata1.meta
-rw-r-----
1 root root 1381888 Feb 25 01:01 ib_logfile0
drwx------ 2 root root 8192 Feb 25 01:01 ldswork
drwx------ 2 root root 16384 Feb 25 01:02 MATTERMOST
drwx------ 2 root root 4096 Feb 25 01:01 mysql
drwx------ 2 root root 24576 Feb 25 01:01 newhongsystem
drwx------ 2 root root 20 Feb 25 01:02 performance_schema
drwx------ 2 root root 8192 Feb 25 01:01 tech
drwx------ 2 root root 20 Feb 25 01:02
test
-rw-r-----
1 root root 42 Feb 25 01:02 xtrabackup_binlog_info
-rw-r-----
1 root root 96 Feb 25 01:02 xtrabackup_checkpoints
-rw-r-----
1 root root 645 Feb 25 01:02 xtrabackup_info
drwx------ 2 root root 16384 Feb 25 01:02 ZABBIXDB
```
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment