gitlab 데이타와 첨부 파일을 백업하는 방법

 

Backup

bundle exec rake RAILS_ENV=production gitlab:backup:create 명령어로 백업할 수 있다. 백업 파일 관련 설정은 config/gitlab.yml 에서 설정할 수 있다.

 ## Backup settings
  backup:
    # 백업 파일을 저장할 경로
    path: "tmp/backups"   # Relative paths are relative to Rails.root (default: tmp/backups/)
    # 오래된 백업 파일 삭제 여부. 0 이면 삭제하지 않는다. 604800 일 경우 일주일이 지난 백업 파일은 삭제한다.
    keep_time: 604800   # default: 0 (forever) (in seconds)

BASH

 

기본적으로 백업 경로는 /home/git/gitlab/tmp/backups 이고 예전 파일 삭제는 하지 않는다. 실제 프로젝트를 진행하게 되면 일정 기간이 지난 파일은 삭제하게 하는게 좋다. backup: 의 keep_time 에 초단위로 설정할 수 있다.

604800 라 설정하면 1주일이 지난 파일은 모두 삭제하게 된다.

 

gitlab backup

$ cd /home/git/gitlab
$ sudo -u git -H bundle exec rake RAILS_ENV=production gitlab:backup:create
Dumping database ... 
done
Dumping repositories ...
 * root/ini-and-script ... [SKIPPED]
 * lesstif/util-script ... [DONE]
 * lesstif/util-script.wiki ...  [SKIPPED]
done
Dumping uploads ... 
done
Creating backup archive: 1387289435_gitlab_backup.tar ... done
Deleting tmp directories ... done
Deleting old backups ... skipping
BASH

위의 경우 생성된 백업파일은 1387289435_gitlab_backup.tar 이다.

cron 과 연계하면 자동으로 백업할 수 있다.

 

  1. cd /home/git/gitlab
  2. sudo - git -h crontab -e
# Create a full backup of the GitLab repositories and SQL database every day at 2am
0 2 * * * cd /home/git/gitlab && PATH=/usr/local/bin:/usr/bin:/bin bundle exec rake gitlab:backup:create RAILS_ENV=production
CODE

 

Restore

다음 명령어를 실행하면 백업 파일중 가장 최신 타임스탬프의 파일을 복구한다.

$ cd /home/git/gitlab
$ sudo -u git -H bundle exec rake RAILS_ENV=production gitlab:backup:restore
BASH
특정 타임스탬프의 백업을 복구하려면 BACKUP 옵션에 타임스탬프값만 적어줘야 한다. 위에서 백업된 파일명이 1387289435_gitlab_backup.tar 이고 타임스탬프는 앞에 숫자값이다.
 
$ cd /home/git/gitlab
$ sudo -u git -H bundle exec rake RAILS_ENV=production gitlab:backup:restore BACUP=1387289435
 
Unpacking backup ... done
Restoring database ... 
Restoring MySQL database gitlabhq_production ... [DONE]
done
Restoring repositories ...
springwebdevel/spring-web ... [DONE]
lesstif/spring-web ... [DONE]
Put GitLab hooks in repositories dirs [DONE]
done
Restoring uploads ... 
done
This will rebuild an authorized_keys file.
You will lose any data stored in authorized_keys file.
Do you want to continue (yes/no)? yes
..Deleting tmp directories ... done
CODE

 

Ref