MySQL 고급

백업

백업 정책 수립

일간 백업 설정을 위해서 설정파일을 common 디렉토리에 복사한다.

cd /etc/mysql-zrm;
mkdir common;
cp mysql-zrm.conf common/;

정책 파일에는 비밀번호등이 저장 되므로 인가된 사용자 외에는 볼 수 없게 권한을 제한한다.

chmod -R 700 common

정책 파일을 수정한다.

vi common/mysql-zrm.conf

백업 형태를 지정한다. 0은 전체 백업, 1은 증분 백업이다.
증분백업을 하면 바이너리 로그를 저장하고, flush log를 실행해서 로그 파일을 변경한다.

# Backup level. It can be full or incremental
# Use 0 for full and 1 for incremental backups
# This parameter is optional and default value is full backup.
#
backup-level=1

증분백업을 하려면 바이너리 로그의 경로를 지정해야 한다.

# Directory where MySQL binary logs can be found. The parameter is optional.
#
mysql-binlog-path="/var/log/mysql"

mysql에서 바이너리 로그를 활성화 하려면 mysql의 my.cnf 파일의 log_bin 설정을 수정해야 한다.
my.cnf 파일은 보통 /etc/my.cnf나 /etc/mysql/my.cnf 에 위치한다.

log_bin                 = /var/log/mysql/mysql-bin.log

mysql에서 바이너리 로그를 활성화 했다면 DB를 새로 시작해야 한다.

/etc/init.d/mysql restart

논리적 백업을 할지 raw백업을 할지 선택한다.
논리적 백업은 mysqldump의 결과로 만들어지는 백업이고, raw백업은 데이터 파일과 dump 파일을 저장한다.
증분백업을 하면 이 설정을 무시하고 바이너리로그만을 저장한다.
(참고)

# Backup method
# Values can be "raw" or "logical". Logical backup are backups using
# mysqldump(1) tool
# This parameter is optional and default value is "raw".
#
backup-mode=logical 

백업을 저장할 기간을 지정한다. 아래는 각 백업을 10일간 저장 하도록 설정한 예

# Specifies how long the backup should be retained. The value can be 
# specified in days (suffix D), weeks (suffix: W), months (suffix: M) or 
# years (suffix Y). 30 days in a month and 365 days in a year are assumed
# This parameter is optional and the default is the backups are retained 
# forever.
# 
retention-policy=10D

백업 결과를 압축할 것인지를 지정

# This parameter should be set to 1 if backups should be compressed. If this
# parameter is set, gzip(1) command is used by default. If different 
# compression algorithm should be used, it must be set in "compress-plugin"
# parameter. Default: There is no data compression.
compress=1

데이터베이스 전체를 백업 대상으로 지정

# This parameter should be set to 1 if all databases are part of this backup set

all-databases=1

백업을 실행할 mysql 사용자의 아이디와 비밀번호를 지정

# MySQL database user used for backup and recovery of the backup set. 
# This parameter is optional. If this parameter is not specified, values from 
# my.cnf configuration file. 
# 
user="backup-user" 
 
# MySQL database user password.  
# This parameter is optional. If this parameter is not specified, values from 
# my.cnf configuration file or no password is used. 
# 

#password="pass123" 

백업결과를 통보 받을 이메일을 지정

# After a backup run the backup report is emailed to the mailto address
# This parameter is optional and default behavior is not to send mail
# notifications.
#
mailto="codingeverybody@gmail.com"

백업실행

즉시 실행

mysql-zrm-scheduler --now --backup-set common

스케줄링

매일 오후 1시 35분에 common 설정을 사용해 백업한다.

mysql-zrm-scheduler --add --interval daily --start 13:35 --backup-set common

매주 화,수요일에 백업한다.

mysql-zrm-scheduler --add --interval weekly --day-of-week 2-3 --backup-set common

매월 10일에 백업한다.

mysql-zrm-scheduler --add --interval monthly --day-of-month 10 --backup-set common

매일 13:35분에 실행되는 스케줄을 삭제

mysql-zrm-scheduler --delete --interval daily --start 13:35

매주 화,수요일에 실행되는 스케줄을 삭제

mysql-zrm-scheduler --delete --interval weekly --day-of-week 2-3 --backup-set common

댓글

댓글 본문
버전 관리
egoing
현재 버전
선택 버전
graphittie 자세히 보기