-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbackup.sh
executable file
·79 lines (66 loc) · 1.51 KB
/
backup.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
#!/bin/bash
# Cron fix
my_path="$(dirname $0)"
cd "$my_path"
# Require files
source configs.sh
source functions.sh
#
# Step 1 - Check for ftp server
#
if [ exec 6<>"/dev/tcp/$FTP_HOST/$FTP_PORT" ]
then
echo "INF: FTP server is UP" | tee -a "$LOG"
exec 6>&- # close output connection
exec 6<&- # close input connection
else
echo "ERR: FTP server is DOWN" | tee -a "$LOG"
send_mail "ftp" "$EMAIL"
exit
fi
#
# Step 2 - Create the backup via gitlab-rake
#
echo "INF: Initiate the backup by gitlab-rake" | tee -a "$LOG"
/opt/gitlab/bin/gitlab-rake gitlab:backup:create | tee -a "$LOG"
currentDataBackup=`latest_backup`
x=1
ls -t $BACKUP_PATH/$BACKUP_FILEMASK | grep -v "$currentDataBackup" | \
while read filename
do
if [ $x -le $BACKUP_KEEP ]
then
x=$(($x+1))
continue
fi
echo "INF: Remove $filename"
rm $filename
done
# Copy archive to temporary location to allow FTP loading
cp $BACKUP_PATH/$currentDataBackup .
#
# Step 3 - Create the backup of confis
#
confArchiveBackup=$(date "+%s_%Y_%m_%d_gitlab_etc.tar.gz")
tar -cvpzf "$confArchiveBackup" /etc/gitlab/
#
# Step 4 - Push latest backup to ftp server
#
ftp -n $FTP_HOST $FTP_PORT << EOF | tee -a "$LOG"
quote USER $FTP_USER
quote PASS $FTP_PASS
cd $FTP_PATH_MAIN
put $currentDataBackup
cd $FTP_PATH_CONF
put $confArchiveBackup
quit
EOF
#
# Step 5 - Clean up
#
rm -v "$confArchiveBackup" | tee -a "$LOG"
rm -v "$currentDataBackup" | tee -a "$LOG"
#
# Step 6 - All done, send message with log file to owner
#
send_mail "done" "$EMAIL" "$LOG"