삽더하기실수
Restic 구축 본문
반응형
    
    
    
  1. 설치방법
#ubntu
apt-get install restic
#Rocky
dnf install restic -y
restic init --repo /data/localbackup  #repo 만들어주기
mkdir -p /etc/restic
chmod 700 /etc/restic
echo "passwd" | sudo tee /etc/restic/passwd > /dev/null
sudo chmod 600 /etc/restic/passwd
touch /var/log/restic.log
2. 크론탭을 통한 자동화
00 08 * * * /etc/restic/backup.sh
00 09 * * * restic --repo /backup --password-file /etc/restic/passwd forget --keep-daily 7 --keep-weekly 4 --prune
2-1. backup 스크립트를 작성하여 지속적으로 백업을 진행한다.
#!/bin/bash
# 설정
REPO="/path/to/backup"
PASSWORD_FILE="/secure/path/restic_passwd"
SOURCE=("/important/data" "/configs")
LOG_FILE="/tmp/restic_backup.log"
Server_name=$(hostname)
Server_ip=$(hostname -I | awk '{print $1}')
DATE=$(date '+%Y-%m-%d %H:%M:%S')
EXIT_CODE=0
FAIL_DIRS=()
# 백업 실행
for dir in "${SOURCE[@]}"; do
    restic --repo "$REPO" --password-file "$PASSWORD_FILE" backup "$dir" >> "$LOG_FILE" 2>&1
    if [ $? -ne 0 ]; then
        EXIT_CODE=1
        FAIL_DIRS+=("$dir")
    fi
done
if [ $EXIT_CODE -eq 0 ]; then
    echo "$DATE - Backup succeeded" >> "$LOG_FILE"
else
    echo "$DATE - Backup FAILED (${FAIL_DIRS[*]})" >> "$LOG_FILE"
fi
백업 리스트를 배열로 저장하여, for 문을 통하여 지정 디렉터리 백업을 진행한다.
이후 백업 성공 및 실패 관련 로그를 출력하기 위해 해당 코드를 추가하였다.
3. restic 관련 명령어
restic --repo /backup snapshots #스냅샷 현황 확인
restic --repo /backup --password-file /etc/restic/passwd forget --keep-daily 7 --keep-weekly 4 -- #snapshot 삭제
restic restore -r [repod명] [snapshotID] --target [복구 경로]반응형