중복제거 (Deduplication)는 백업되는 각각의 데이터는 청크(chunk)로 분할이 되고 청크의 해시값(id_hash)을 비교해서 같은 해시값의 청크는 백업하지 않는 방법이다.
Borg는 중복제거 백업 프로그램이다. 옵션으로 백업에 압축과 인증 및 암호를 사용할 수 있다. 중복제거 개념이기때문에 변경된 사항만 저장되므로 데일리 백업에도 적합하다.
추가적으로 암호화 기능이 존재하여 안전하게 원격지로 백업이 가능하다.
*Deduplication에 대한 자세한 설명은 링크를 참조
설치
> yum install -y epel-release
> yum install -y borgbackup
> borg --version
borg 1.1.15
# Ubuntu
> apt install borgbackup
Borg repo 생성
Repo는 백업에 대한 각종 정보들을 암호화하여 저장하는 공간이다.
암호화 방식은 여러가지가 있지만 여기서는 단순 '암호' 만을 사용하는 repokey
모드를 사용한다.
repokey
모드는 AES-CTR-256 알고리즘으로 암호화(Encryption)를 하고 인증(Authentication)에는 HMAC-SHA256 알고리즘을 사용한다.# 백업서버에 Repo를 생성한다.
> borg init -e repokey borg@backup.idc:/home/borg/wikirepo
borg init -e repokey borg@backup.idc:/home/borg/wikirepo
Enter new passphrase:
Enter same passphrase again:
Do you want your passphrase to be displayed for verification? [yN]: y
Your passphrase (between double-quotes): "dkagh1."
이렇게 입력된 암호는 암호화되어 해당 repo의 config 파일에 저장되어있다.
[borg@tomcat-1 wikirepo]$ ll
total 68
-rw------- 1 borg borg 700 Mar 15 13:52 config
drwx------ 3 borg borg 15 Mar 15 13:52 data
-rw------- 1 borg borg 56 Mar 15 15:41 hints.49
-rw------- 1 borg borg 41258 Mar 15 15:41 index.49
-rw------- 1 borg borg 190 Mar 15 15:41 integrity.49
-rw------- 1 borg borg 88 Mar 15 16:27 lock.roster
-rw------- 1 borg borg 16 Mar 15 15:31 nonce
-rw------- 1 borg borg 73 Mar 15 13:52 README
백업
borg create ARCHIVE [PATH] [PATH ...]]
위에서 만든 'wikirepo'라는 Borg Repository에 /opt/data/confluence/
백업에 대한 정보를 저장한다.
> borg create -v --stats borg@backup.idc:/home/borg/wikirepo::test
Enter passphrase for key ssh://borg@backup.idc/home/borg/wikirepo:
Creating archive at "borg@backup.idc:/home/borg/wikirepo::test"
------------------------------------------------------------------------------
Archive name: test
Archive fingerprint: 78d596abe30f1cfde484fc7b2a1f984d3178d9f89d0a81b83bd6d2e90af50588
Time (start): Mon, 2021-03-15 07:12:28
Time (end): Mon, 2021-03-15 07:12:28
Duration: 0.02 seconds
Number of files: 12
Utilization of max. archive size: 0%
------------------------------------------------------------------------------
Original size Compressed size Deduplicated size
This archive: 2.24 kB 776 B 776 B
All archives: 71.66 kB 40.37 kB 23.68 kB
Unique chunks Total chunks
Chunk index: 29 50
------------------------------------------------------------------------------
repo에 저장된 백업 아카이브 확인
> borg list borg@backup.idc:/home/borg/wikirepo
Enter passphrase for key ssh://borg@backup.idc/home/borg/wikirepo:
Monday1 Mon, 2021-03-15 07:50:34 [d686244bef040f881d9ad0d35689c68ff2d7af7f8f717039da826657ab82e284]
# 파일 확인
> borg list borg@backup.idc:/home/borg/wikirepo::test
Enter passphrase for key ssh://borg@backup.idc/home/borg/wikirepo:
drwxr-xr-x root root 0 Mon, 2021-03-15 06:01:22 opt/data/bamboo
-rw-r--r-- root root 0 Mon, 2021-03-15 05:48:38 opt/data/bamboo/100
-rw-r--r-- root root 0 Mon, 2021-03-15 05:48:38 opt/data/bamboo/101
-rw-r--r-- root root 0 Mon, 2021-03-15 05:48:38 opt/data/bamboo/102
-rw-r--r-- root root 0 Mon, 2021-03-15 05:48:38 opt/data/bamboo/103
-rw-r--r-- root root 0 Mon, 2021-03-15 05:48:38 opt/data/bamboo/104
-rw-r--r-- root root 0 Mon, 2021-03-15 05:48:38 opt/data/bamboo/105
-rw-r--r-- root root 0 Mon, 2021-03-15 06:01:22 opt/data/bamboo/200
-rw-r--r-- root root 0 Mon, 2021-03-15 06:01:22 opt/data/bamboo/201
-rw-r--r-- root root 0 Mon, 2021-03-15 06:01:22 opt/data/bamboo/202
-rw-r--r-- root root 0 Mon, 2021-03-15 06:01:22 opt/data/bamboo/203
-rw-r--r-- root root 0 Mon, 2021-03-15 06:01:22 opt/data/bamboo/204
-rw-r--r-- root root 0 Mon, 2021-03-15 06:01:22 opt/data/bamboo/205
마운트
> borg mount /home/borg/wikirepo::test /home/borg/mount-only/
복원
> borg extract borg@backup.idc:/home/borg/wikirepo::test /
#!/bin/bash
NOW=`date +%Y%m%d`
WIKI_LOG="/var/log/borg/wiki_backup-$NOW"
# Setting this, so the repo does not need to be given on the commandline:
export BORG_REPO=wiki@backup.idc:/home/wiki/wikirepo
# Use Specific User's RSH Key
export BORG_RSH="ssh -i /root/.ssh/id_rsa"
# See the section "Passphrase notes" for more infos.
export BORG_PASSPHRASE='dkagh1.'
# some helpers and error handling:
info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; }
trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM
##
## Output to a Log File
##
exec > >(tee -i ${WIKI_LOG})
exec 2>&1
# Start Backup
info "Starting backup"
# Backup the most important directories into an archive named after
# the machine this script is currently running on:
borg create \
--verbose \
--filter AME \
--list \
--stats \
--show-rc \
--compression lz4 \
--exclude-caches \
\
::wiki-$NOW \
/opt/data/confluence \
backup_exit=$?
info "Pruning repository"
# Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly
# archives of THIS machine. The '{hostname}-' prefix is very important to
# limit prune's operation to this machine's archives and not apply to
# other machines' archives also:
borg prune \
--list \
--prefix '{hostname}-' \
--show-rc \
--keep-daily 7 \
--keep-weekly 4 \
--keep-monthly 3 \
prune_exit=$?
# use highest exit code as global exit code
global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit ))
if [ ${global_exit} -eq 0 ]; then
info "Backup and Prune finished successfully"
elif [ ${global_exit} -eq 1 ]; then
info "Backup and/or Prune finished with warnings"
else
info "Backup and/or Prune finished with errors"
fi
exit ${global_exit}
0 3 * * * /root/borg/backup.sh > /dev/null 2>&1
1G의 더미데이터 100개를 생성(총 100G)하고 원격지의 백업서버에 여러가지 압축유형으로 백업하고 CPU 로드율
, 메모리 사용률
, 백업에 걸리는 시간
, Disk I/O
을 측정하고 우리서버에 적절한 압축옵션을 찾는다.
Borg Backup 수행 시 사용되는 컴퓨터 리소스에 대한 자세한 설명은 링크를 참고한다.
Compression
All data can be optionally compressed:
• lz4 (super fast, low compression)
• zstd (wide range from high speed and low compression to high compression and lower speed)
• zlib (medium speed and compression)
• lzma (low speed, high compression)
더미 파일 생성
> cd /opt/data/confluence
> for i in $(seq 1 100); do echo -n "testfile${i} "; dd if=/dev/zero of=testfile${i} bs=1024 count=1000000 2>&1; done
테스트
# 백그라운드로 실행
. borg_backup.sh &
# top으로 관제
top