-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrestore.sh
executable file
·87 lines (65 loc) · 2.72 KB
/
restore.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
# Cron fix
my_path="$(dirname $0)"
cd "$my_path"
source configs.sh
source functions.sh
echo "INF: Initiate the restore" | tee -a "$LOG"
FTP_FILES=`ftp_list_files`
backups=`echo "$FTP_FILES" | sort | grep '_backup.tar'`
configs=`echo "$FTP_FILES" | sort | grep '_etc.tar'`
#
# Stage 1 - Get the latest files for restore
#
ftp_latest_backup=$(echo "$backups" | tail -n 1)
ftp_latest_config=$(echo "$configs" | tail -n 1)
#
# Stage 2 - Restore files
#
echo "INF: Last backup is $ftp_latest_backup" | tee -a "$LOG"
echo "INF: Stop some services" | tee -a "$LOG"
gitlab-ctl stop unicorn | tee -a "$LOG"
gitlab-ctl stop sidekiq | tee -a "$LOG"
echo "INF: Check the status" | tee -a "$LOG"
gitlab-ctl status | tee -a "$LOG"
echo "INF: Copy backup from FTP to local path" | tee -a "$LOG"
cd /var/opt/gitlab/backups/
ftp -n $FTP_HOST << EOF | tee -a "$LOG"
quote USER $FTP_USER
quote PASS $FTP_PASS
cd $FTP_PATH_CONF
get $ftp_latest_backup
quit
EOF
# Parse the string
backup_date=`echo "$ftp_latest_backup" | awk -F '_gitlab' '{print $1}'` | tee -a "$LOG"
# This command will overwrite the contents of your GitLab database!
gitlab-rake gitlab:backup:restore BACKUP="$backup_date"
echo "INF: Start the GitLab" | tee -a "$LOG"
gitlab-ctl start | tee -a "$LOG"
echo "INF: Run simple check" | tee -a "$LOG"
gitlab-rake gitlab:check SANITIZE=true | tee -a "$LOG"
#
# Stage 3 - Restore main configuration
#
if yesno --default no "Restore the /etc/gitlab configuration? [yes|no] ";
then
echo "INF: You answered yes"
else
echo "INF: You answered no"
send_mail "restore" "$EMAIL" "$LOG"
exit
fi
cd "$my_path"
ftp -n $FTP_HOST << EOF | tee -a "$LOG"
quote USER $FTP_USER
quote PASS $FTP_PASS
cd $FTP_PATH_MAIN
get $ftp_latest_config
quit
EOF
echo "INF: Extract the configs from archive" | tee -a "$LOG"
tar -xvpzf "$ftp_latest_config" -C / | tee -a "$LOG"
echo "INF: Run simple check" | tee -a "$LOG"
gitlab-ctl reconfigure | tee -a "$LOG"
send_mail "restore" "$EMAIL" "$LOG"