Skip to content

Commit 7d117ed

Browse files
committed
Updated hostcheck to use rsync
1 parent f58b8b8 commit 7d117ed

File tree

2 files changed

+85
-10
lines changed

2 files changed

+85
-10
lines changed

bin/ghe-host-check

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,42 +151,54 @@ min_jq=""
151151
# shellcheck source=share/github-backup-utils/requirements.txt
152152
. "$(dirname "${BASH_SOURCE[0]}")/../share/github-backup-utils/requirements.txt"
153153

154+
#source disk size file
155+
. "$(dirname "${BASH_SOURCE[0]}")/../share/github-backup-utils/ghe-rsync-size.sh"
156+
154157
#Display dir requirements for repositories and mysql
155-
backup_dir=${GHE_DATA_DIR}
156-
available_space=$(df $backup_dir | awk 'END{print $4}')
158+
available_space=$(df $GHE_DATA_DIR | awk 'END{print $4}')
159+
echo "Available space: $available_space" 1>&2
160+
157161
repo_disk_size=$(ghe-ssh "$host" sudo du -sh /data/user/repositories | awk '{print $1}')
158-
#mysql_disk_size=$(ghe-ssh "$host" sudo du -sh /data/user/mysql | awk '{print $1}')
159162
# Convert the data size to kilobytes
160163
case "$repo_disk_size" in
161164
*T) repo_disk_size=$(( $(echo "$repo_disk_size" | sed 's/T/000000000/') )) ;;
162165
*G) repo_disk_size=$(( $(echo "$repo_disk_size" | sed 's/G/000000/') )) ;;
163166
*M) repo_disk_size=$(( $(echo "$repo_disk_size" | sed 's/M/000/') )) ;;
164167
*K) repo_disk_size=$(( $(echo "$repo_disk_size" | sed 's/K//') )) ;;
165168
esac
169+
repos_disk_size=$(transfer_size repositories /tmp)
170+
pages_disk_size=$(transfer_size pages /tmp)
171+
es_disk_size=$(transfer_size elasticsearch /tmp)
172+
stor_disk_size=$(transfer_size storage /tmp)
173+
minio_disk_size=$(transfer_size minio /tmp)
174+
min_disk_req=$(( $(echo "$repos_disk_size" | awk '{print $1}') + $(echo "$pages_disk_size" | awk '{print $1}') + $(echo "$es_disk_size" | awk '{print $1}') + $(echo "$stor_disk_size" | awk '{print $1}') + $(echo "$minio_disk_size" | awk '{print $1}') ))
175+
echo "repositories = $repos_disk_size, pages: $pages_disk_size, elasticsearch: $es_disk_size, storage: $stor_disk_size, minio: $minio_disk_size" 1>&2
176+
echo "min_disk_required for backup = $min_disk_req bytes" 1>&2
177+
166178
if [[ $available_space -lt $repo_disk_size ]]; then
167-
echo "There is not enough disk space for the backup"
179+
echo "There is not enough disk space for the backup" 1>&2
168180
exit 1
169181
fi
170182

171183
#Check rsync, openssh & jq versions
172184
rsync_version=$(rsync --version | grep 'version' | awk '{print $3}')
173185
if awk "BEGIN {exit !($rsync_version < $min_rsync)}" &> /dev/null; then
174-
echo "rsync version $rsync_version in backup-host does not meet minimum requirements."
175-
echo "Please make sure you have the minimum required version of rsync: $min_rsync installed"
186+
echo "rsync version $rsync_version in backup-host does not meet minimum requirements." 1>&2
187+
echo "Please make sure you have the minimum required version of rsync: $min_rsync installed" 1>&2
176188
exit 1
177189
fi
178190

179191
ssh_version=$(ssh -V 2>&1 | awk '{print $1}'|grep -oPm 1 '[\d\.]+' |head -1)
180192
if awk "BEGIN {exit !($ssh_version < $min_openssh)}" &> /dev/null; then
181-
echo "openSSH version $ssh_version in backup-host does not meet minimum requirements."
182-
echo "Please make sure the minimum required version of openSSH: $min_openssh is installed"
193+
echo "openSSH version $ssh_version in backup-host does not meet minimum requirements." 1>&2
194+
echo "Please make sure the minimum required version of openSSH: $min_openssh is installed" 1>&2
183195
exit 1
184196
fi
185197

186198
jq_version=$(jq --version |awk -F\- '{print $2}')
187199
if awk "BEGIN {exit !($jq_version < $min_jq)}" &> /dev/null; then
188-
echo "jq version $jq_version in backup-host does not meet minimum requirements."
189-
echo "Please make sure you have the minimum required version of jq: $min_jq installed"
200+
echo "jq version $jq_version in backup-host does not meet minimum requirements." 1>&2
201+
echo "Please make sure you have the minimum required version of jq: $min_jq installed" 1>&2
190202
exit 1
191203
fi
192204

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
# get-rsync-size.sh Get the total size of dir-files to be transfered using rsync --link-dest
3+
#
4+
# Example:
5+
# transfer_size repositories /dest_dir
6+
#
7+
# Sample output:
8+
# Total transferred file size: 80 bytes
9+
10+
# Bring in the backup configuration
11+
# shellcheck source=share/github-backup-utils/ghe-backup-config
12+
. "$(dirname "${BASH_SOURCE[0]}")/ghe-backup-config"
13+
14+
# Location of last good backup for rsync --link-dest
15+
backup_current="$GHE_DATA_DIR/current/"
16+
17+
# If we have a previous increment, avoid using those unchanged files using --link-dest support.
18+
if [ -d "$backup_current" ]; then
19+
link_dest="--link-dest=${GHE_DATA_DIR}/current"
20+
fi
21+
22+
transfer_size()
23+
{
24+
local backup_data=$1
25+
local dir=/data/user/$1/
26+
local dest_dir=$2/
27+
28+
# Define user for rsync-path
29+
case "$backup_data" in
30+
"repositories" | "pages")
31+
user="git"
32+
;;
33+
"storage")
34+
user="alambic"
35+
;;
36+
"elasticsearch")
37+
user="elasticsearch"
38+
;;
39+
"mysql")
40+
user="mysql"
41+
;;
42+
"mssql")
43+
user="mssql"
44+
;;
45+
"minio")
46+
user="minio"
47+
;;
48+
*)
49+
echo "Unknown user: $backup_data"
50+
exit 1
51+
;;
52+
esac
53+
54+
# local total_file_size=$(ghe-ssh "$GHE_HOSTNAME" sudo rsync -arvn $link_dest/$1 --stats "$dir" "$dest_dir" | grep "Total transferred file size" | sed 's/.*size: //; s/,//')
55+
local total_file_size=$(ghe-rsync -arn --stats \
56+
-e "ssh -q $GHE_EXTRA_SSH_OPTS -p 122 -l admin" \
57+
--rsync-path="sudo -u $user rsync" \
58+
$link_dest/$1 \
59+
--ignore-missing-args \
60+
"$GHE_HOSTNAME:$GHE_REMOTE_DATA_USER_DIR/user/$1/" \
61+
"$dest_dir" | grep "Total transferred file size" | sed 's/.*size: //; s/,//g')
62+
echo "$total_file_size"
63+
}

0 commit comments

Comments
 (0)