Skip to content

Commit 1eaf809

Browse files
authored
Merge branch 'master' into progress-indicator
2 parents a8e7eca + 8aaccc3 commit 1eaf809

File tree

8 files changed

+174
-95
lines changed

8 files changed

+174
-95
lines changed

bin/ghe-backup

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ if ! output=$(rsync -a src/ dest1 2>&1 && rsync -av src/ --link-dest=../dest1 de
8888
exit 1
8989
fi
9090

91-
if [ "$(ls -il dest1/testfile | awk '{ print $1 }')" != "$(ls -il dest2/testfile | awk '{ print $1 }')" ]; then
91+
if [ "$(stat -c %i dest1/testfile)" != "$(stat -c %i dest2/testfile)" ]; then
9292
log_error "Error: the filesystem containing $GHE_DATA_DIR does not support hard links.\n Backup Utilities use hard links to store backup data efficiently." 1>&2
9393
exit 1
9494
fi
@@ -108,13 +108,13 @@ cleanup () {
108108
progress=$(cat ../in-progress)
109109
snapshot=$(echo "$progress" | cut -d ' ' -f 1)
110110
pid=$(echo "$progress" | cut -d ' ' -f 2)
111-
if [ "$snapshot" = "$GHE_SNAPSHOT_TIMESTAMP" ] && [ "$$" = $pid ]; then
111+
if [ "$snapshot" = "$GHE_SNAPSHOT_TIMESTAMP" ] && [ "$$" = "$pid" ]; then
112112
unlink ../in-progress
113113
fi
114114
fi
115115

116116
rm -rf "$failures_file"
117-
rm -f ${GHE_DATA_DIR}/in-progress-backup
117+
rm -f "${GHE_DATA_DIR}/in-progress-backup"
118118

119119
# Cleanup SSH multiplexing
120120
ghe-ssh --clean
@@ -150,11 +150,11 @@ if [ -f ../in-progress ]; then
150150
fi
151151

152152
echo "$GHE_SNAPSHOT_TIMESTAMP $$" > ../in-progress
153-
echo "$GHE_SNAPSHOT_TIMESTAMP $$" > ${GHE_DATA_DIR}/in-progress-backup
153+
echo "$GHE_SNAPSHOT_TIMESTAMP $$" > "${GHE_DATA_DIR}/in-progress-backup"
154154

155+
START_TIME=$(date +%s)
155156
log_info "Starting backup of $GHE_HOSTNAME with backup-utils v$BACKUP_UTILS_VERSION in snapshot $GHE_SNAPSHOT_TIMESTAMP"
156157

157-
158158
# Perform a host connection check and establish the remote appliance version.
159159
# The version is available in the GHE_REMOTE_VERSION variable and also written
160160
# to a version file in the snapshot directory itself.
@@ -176,9 +176,6 @@ echo "$GHE_BACKUP_STRATEGY" > strategy
176176
# Create benchmark file
177177
bm_init > /dev/null
178178

179-
START_TIME=$(date +%s)
180-
log_info "Starting backup of $GHE_HOSTNAME with backup-utils v$BACKUP_UTILS_VERSION"
181-
182179
ghe-backup-store-version ||
183180
log_warn "Warning: storing backup-utils version remotely failed."
184181

@@ -250,7 +247,7 @@ if [ "$GHE_BACKUP_STRATEGY" = "rsync" ]; then
250247
fi
251248

252249
if [ "$GHE_PARALLEL_ENABLED" = "yes" ]; then
253-
$GHE_PARALLEL_COMMAND $GHE_PARALLEL_COMMAND_OPTIONS -- "${commands[@]}"
250+
"$GHE_PARALLEL_COMMAND" "${GHE_PARALLEL_COMMAND_OPTIONS[@]}" -- "${commands[@]}"
254251
else
255252
for c in "${commands[@]}"; do
256253
eval "$c"
@@ -264,7 +261,7 @@ fi
264261
# git fsck repositories after the backup
265262
if [ "$GHE_BACKUP_FSCK" = "yes" ]; then
266263
log_info "Running git fsck on repositories ..."
267-
ghe-backup-fsck $GHE_SNAPSHOT_DIR || failures="$failures fsck"
264+
ghe-backup-fsck "$GHE_SNAPSHOT_DIR" || failures="$failures fsck"
268265
fi
269266

270267
# If everything was successful, mark the snapshot as complete, update the
@@ -279,13 +276,15 @@ if [ -z "$failures" ]; then
279276
ghe-prune-snapshots
280277
fi
281278

279+
END_TIME=$(date +%s)
280+
log_info "Runtime: $((END_TIME - START_TIME)) seconds"
282281
log_info "Completed backup of $GHE_HOSTNAME in snapshot $GHE_SNAPSHOT_TIMESTAMP at $(date +"%H:%M:%S")"
283282

284283
# Exit non-zero and list the steps that failed.
285284
if [ -z "$failures" ]; then
286285
ghe_remote_logger "Completed backup from $(hostname) / snapshot $GHE_SNAPSHOT_TIMESTAMP successfully."
287286
else
288-
steps="$(echo $failures | sed 's/ /, /g')"
287+
steps="${failures// /, }"
289288
ghe_remote_logger "Completed backup from $(hostname) / snapshot $GHE_SNAPSHOT_TIMESTAMP with failures: ${steps}."
290289
log_error "Error: Snapshot incomplete. Some steps failed: ${steps}. "
291290
ghe_backup_finished
@@ -296,11 +295,7 @@ fi
296295
log_info "Checking for leaked ssh keys ..."
297296
ghe-detect-leaked-ssh-keys -s "$GHE_SNAPSHOT_DIR" || true
298297

299-
END_TIME=$(date +%s)
300-
log_info "Runtime: $((${END_TIME} - ${START_TIME})) seconds"
301298
log_info "Backup of $GHE_HOSTNAME finished."
302-
# Make sure we exit zero after the conditional
303-
true
304299

305300
# Remove in-progress file
306301
ghe_backup_finished

bin/ghe-host-check

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ if [[ "$CALLING_SCRIPT" == "ghe-backup" ]]; then
159159
#Display dir requirements for repositories and mysql
160160
echo "Checking host for sufficient space for a backup..." 1>&2
161161
available_space=$(df -B 1k $GHE_DATA_DIR | awk 'END{printf "%.0f", $4 * 1024}')
162-
printf "Available space: %d MB. We recommend allocating at least 5x the amount of storage allocated to the primary GitHub appliance for historical snapshots and growth over time.\n" "$((available_space / 1024 ** 2))" 1>&2
162+
echo "We recommend allocating at least 5x the amount of storage allocated to the primary GitHub appliance for historical snapshots and growth over time." 1>&2
163163

164164
repos_disk_size=$(transfer_size repositories /tmp)
165165
pages_disk_size=$(transfer_size pages /tmp)
@@ -170,17 +170,29 @@ if [[ "$CALLING_SCRIPT" == "ghe-backup" ]]; then
170170
actions_disk_size=$(transfer_size actions /tmp)
171171
mssql_disk_size=$(transfer_size mssql /tmp)
172172

173-
#min_disk_req=$(( $(echo "$repos_disk_size" | awk '{printf "%.0f", $1}') + $(echo "$pages_disk_size" | awk '{printf "%.0f", $1}') + $(echo "$es_disk_size" | awk '{printf "%.0f", $1}') + $(echo "$stor_disk_size" | awk '{printf "%.0f", $1}') + $(echo "$minio_disk_size" | awk '{printf "%.0f", $1}') + $(echo "$mysql_disk_size" | awk '{printf "%.0f", $1/2}') + $(echo "$actions_disk_size" | awk '{printf "%.0f", $1}') + $(echo "$mssql_disk_size" | awk '{printf "%.0f", $1}') ))
174-
min_disk_req=$(( $(echo "$repos_disk_size") + $(echo "$pages_disk_size") + $(echo "$es_disk_size") + $(echo "$stor_disk_size") + $(echo "$minio_disk_size") + $(echo "$mysql_disk_size") + $(echo "$actions_disk_size") + $(echo "$mssql_disk_size") ))
175-
echo -e "### Data Transfer Sizes \nrepositories: $repos_disk_size \npages: $pages_disk_size \nelasticsearch: $es_disk_size \nstorage: $stor_disk_size \nminio: $minio_disk_size \nmysql: $mysql_disk_size \nactions: $actions_disk_size \nmssql: $mssql_disk_size" 1>&2
176-
printf "min_disk_required for this backup is at least %d MB\n" "$((min_disk_req / 1024 ** 2))" 1>&2
173+
min_disk_req=$((repos_disk_size + pages_disk_size + es_disk_size + stor_disk_size + minio_disk_size + mysql_disk_size + actions_disk_size + mssql_disk_size))
174+
echo "Available space: $((available_space / (1024 ** 2))) MB" 1>&2
175+
echo -e "Min Disk required for this backup is at least $min_disk_req MB\n" 1>&2
176+
177+
cat <<DATA_TRANSFER_SIZE 1>&2
178+
### Data Transfer Sizes
179+
repositories: $repos_disk_size MB
180+
pages: $pages_disk_size MB
181+
elasticsearch: $es_disk_size MB
182+
storage: $stor_disk_size MB
183+
minio: $minio_disk_size MB
184+
mysql: $mysql_disk_size MB
185+
actions: $actions_disk_size MB
186+
mssql: $mssql_disk_size MB
187+
DATA_TRANSFER_SIZE
177188

178189
if [[ $available_space -lt $min_disk_req ]]; then
179190
echo "There is not enough disk space for the backup. Please allocate more space and continue." 1>&2
180191
exit 1
181192
fi
182193

183194
#Check rsync, openssh & jq versions
195+
echo "### Software versions" 1>&2
184196
rsync_version=$(rsync --version | grep 'version' | awk '{print $3}')
185197
if awk "BEGIN {exit !($rsync_version < $min_rsync)}" &> /dev/null; then
186198
echo "rsync version $rsync_version in backup-host does not meet minimum requirements." 1>&2

0 commit comments

Comments
 (0)