Skip to content

Commit d42ccdf

Browse files
committed
Moved function to ghe-backup-config
1 parent f4663b1 commit d42ccdf

File tree

3 files changed

+45
-88
lines changed

3 files changed

+45
-88
lines changed

bin/ghe-backup

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ rm -rf src dest1 dest2
9696
# The cleanup trap also handles disabling maintenance mode on the appliance if
9797
# it was automatically enabled.
9898
cleanup () {
99-
if [ -f ../.in-progress ]; then
100-
progress=$(cat ../.in-progress)
99+
if [ -f ../in-progress ]; then
100+
progress=$(cat ../in-progress)
101101
snapshot=$(echo "$progress" | cut -d ' ' -f 1)
102102
pid=$(echo "$progress" | cut -d ' ' -f 2)
103103
if [ "$snapshot" = "$GHE_SNAPSHOT_TIMESTAMP" ] && [ "$$" = $pid ]; then
104-
unlink ../.in-progress
104+
unlink ../in-progress
105105
fi
106106
fi
107107

@@ -120,30 +120,31 @@ trap 'exit $?' INT # ^C always terminate
120120
ghe_restore_check
121121

122122
# Check to see if there is a running backup
123-
if [ -h ../.in-progress ]; then
123+
if [ -h ../in-progress ]; then
124124
echo "Error: detected a backup already in progress from a previous version of ghe-backup." 1>&2
125125
echo "If there is no backup in progress anymore, please remove" 1>&2
126-
echo "the $GHE_DATA_DIR/.in-progress file." 1>&2
126+
echo "the \"$GHE_DATA_DIR/in-progress\" file and try again." 1>&2
127127
exit 1
128128
fi
129129

130-
if [ -f ../.in-progress ]; then
131-
progress=$(cat ../.in-progress)
130+
if [ -f ../in-progress ]; then
131+
progress=$(cat ../in-progress)
132132
snapshot=$(echo "$progress" | cut -d ' ' -f 1)
133133
pid=$(echo "$progress" | cut -d ' ' -f 2)
134134
if ! ps -p "$pid" >/dev/null 2>&1; then
135-
# We can safely remove .in-progress, ghe-prune-snapshots
135+
# We can safely remove in-progress, ghe-prune-snapshots
136136
# will clean up the failed backup.
137-
unlink ../.in-progress
137+
unlink ../in-progress
138138
else
139139
echo "Error: A backup of $GHE_HOSTNAME may still be running on PID $pid." 1>&2
140-
echo "If PID $pid is not a process related to the backup utilities, please remove" 1>&2
141-
echo "the $GHE_DATA_DIR/.in-progress file and try again." 1>&2
140+
echo 1>&2
141+
echo " If PID $pid is not a process related to the backup utilities, please remove" 1>&2
142+
echo " the \"$GHE_DATA_DIR/in-progress\" file and try again." 1>&2
142143
exit 1
143144
fi
144145
fi
145146

146-
echo "$GHE_SNAPSHOT_TIMESTAMP $$" > ../.in-progress
147+
echo "$GHE_SNAPSHOT_TIMESTAMP $$" > ../in-progress
147148

148149
echo "Starting backup of $GHE_HOSTNAME with backup-utils v$BACKUP_UTILS_VERSION in snapshot $GHE_SNAPSHOT_TIMESTAMP"
149150

bin/ghe-restore

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ cleanup () {
123123
# Cleanup SSH multiplexing
124124
ghe-ssh --clean
125125
# Remove in-progress file
126-
rm -f ${GHE_DATA_DIR}/.in-progress-restore
126+
rm -f ${GHE_DATA_DIR}/in-progress-restore
127127
}
128128

129129
# This function's type definition is being passed to a remote host via `ghe-ssh` but is not used locally.
@@ -155,26 +155,6 @@ cleanup_cluster_nodes() {
155155
ghe_parallel_check
156156

157157
# ghe_restore_check
158-
if [ -h ${GHE_DATA_DIR}/.in-progress-restore ]; then
159-
echo "Error: detected a restore already in progress from a previous version of ghe-restore." 1>&2
160-
echo "If there is no restore in progress anymore, please remove" 1>&2
161-
echo "the $GHE_DATA_DIR/in-progress-restore file." 1>&2
162-
exit 1
163-
fi
164-
165-
echo "${GHE_DATA_DIR}/.in-progress-restore"
166-
if [ -f ${GHE_DATA_DIR}/.in-progress-restore ]; then
167-
progress=$(cat ${GHE_DATA_DIR}/.in-progress-restore)
168-
snapshot=$(echo "$progress" | cut -d ' ' -f 1)
169-
pid=$(echo "$progress" | cut -d ' ' -f 2)
170-
echo "Error: A restore of $GHE_HOSTNAME may still be running on PID $pid." 1>&2
171-
echo "If PID $pid is not a process related to the restore utilities, please remove" 1>&2
172-
echo "the $GHE_DATA_DIR/in-progress-restore file and try again." 1>&2
173-
exit 1
174-
fi
175-
176-
# Check to make sure a restore or backup is not in progress
177-
178158

179159
# Grab the host arg
180160
GHE_HOSTNAME="${GHE_RESTORE_HOST_OPT:-$GHE_RESTORE_HOST}"
@@ -194,23 +174,7 @@ GHE_RESTORE_SNAPSHOT_PATH="$(ghe-restore-snapshot-path "$snapshot_id")"
194174
GHE_RESTORE_SNAPSHOT=$(basename "$GHE_RESTORE_SNAPSHOT_PATH")
195175
export GHE_RESTORE_SNAPSHOT
196176

197-
#ghe_backup_check
198-
if [ -h ${GHE_DATA_DIR}/.in-progress ]; then
199-
echo "Error: detected a backup already in progress from a previous version of ghe-backup." 1>&2
200-
echo "If there is no backup in progress anymore, please remove" 1>&2
201-
echo "the $GHE_DATA_DIR/.in-progress-backup file." 1>&2
202-
exit 1
203-
fi
204-
205-
if [ -f ${GHE_DATA_DIR}/.in-progress ]; then
206-
progress=$(cat ${GHE_DATA_DIR}/.in-progress)
207-
snapshot=$(echo "$progress" | cut -d ' ' -f 1)
208-
pid=$(echo "$progress" | cut -d ' ' -f 2)
209-
echo "Error: A backup of $GHE_HOSTNAME may still be running on PID $pid." 1>&2
210-
echo "If PID $pid is not a process related to the backup utilities, please remove" 1>&2
211-
echo "the $GHE_DATA_DIR/.in-progress file and try again." 1>&2
212-
exit 1
213-
fi
177+
ghe_backup_check
214178

215179
# Detect if the backup we are restoring has a leaked ssh key
216180
echo "Checking for leaked keys in the backup snapshot that is being restored ..."
@@ -295,12 +259,8 @@ echo 'Start time:' $START_TIME
295259
echo "Starting restore of $GHE_HOSTNAME with backup-utils v$BACKUP_UTILS_VERSION from snapshot $GHE_RESTORE_SNAPSHOT"
296260
ghe_remote_logger "Starting restore from $(hostname) with backup-utils v$BACKUP_UTILS_VERSION / snapshot $GHE_RESTORE_SNAPSHOT ..."
297261
# Create an in-progress-restore file to prevent simultaneous backup or restore runs
298-
echo "${START_TIME} $$" > ${GHE_DATA_DIR}/.in-progress-restore
262+
echo "${START_TIME} $$" > ${GHE_DATA_DIR}/in-progress-restore
299263

300-
sleep 120
301-
rm -f ${GHE_DATA_DIR}/.in-progress-restore
302-
echo "finished with fake restore"
303-
exit 1
304264
# Keep other processes on the VM or cluster in the loop about the restore status.
305265
#
306266
# Other processes will look for these states:
@@ -627,7 +587,7 @@ echo 'End time:' $END_TIME
627587
echo 'Runtime:' $(($END_TIME - $START_TIME)) 'seconds'
628588

629589
echo "Restore of $GHE_HOSTNAME from snapshot $GHE_RESTORE_SNAPSHOT finished."
630-
rm -f ${GHE_DATA_DIR}/.in-progress-restore
590+
rm -f ${GHE_DATA_DIR}/in-progress-restore
631591

632592
if ! $instance_configured; then
633593
echo "To complete the restore process, please visit https://$hostname/setup/settings to review and save the appliance configuration."

share/github-backup-utils/ghe-backup-config

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -66,49 +66,45 @@ for f in "$GHE_BACKUP_CONFIG" "$GHE_BACKUP_ROOT/backup.config" \
6666
fi
6767
done
6868

69-
GHE_RESTORE_IN_PROGRESS="../../${GHE_DATA_DIR}/.in-progress-restore"
70-
GHE_BACKUP_IN_PROGRESS="../../${GHE_DATA_DIR}/.in-progress"
69+
GHE_RESTORE_IN_PROGRESS=$(readlink -f "${GHE_DATA_DIR}/in-progress-restore")
70+
GHE_BACKUP_IN_PROGRESS=$(readlink -f "${GHE_DATA_DIR}/in-progress-backup")
7171
export GHE_RESTORE_IN_PROGRESS
7272
export GHE_BACKUP_IN_PROGRESS
7373

74-
#ghe_restore_started() {
75-
#echo "$1 $$" >> $GHE_RESTORE_IN_PROGRESS
76-
#}
77-
7874
ghe_restore_check() {
79-
if [ -h $GHE_RESTORE_IN_PROGRESS ]; then
80-
echo "Error: detected a restore already in progress from a previous version of ghe-restore." 1>&2
81-
echo "If there is no restore in progress anymore, please remove" 1>&2
82-
echo "the $GHE_DATA_DIR/in-progress-restore file." 1>&2
83-
exit 1
84-
fi
75+
if [ -h $GHE_RESTORE_IN_PROGRESS ]; then
76+
echo " Error: detected a restore already in progress from a previous version of ghe-restore." 1>&2
77+
echo " If there is no restore in progress anymore, please remove" 1>&2
78+
echo " the \"$GHE_RESTORE_IN_PROGRESS\" file and try again." 1>&2
79+
exit 1
80+
fi
8581

86-
if [ -f $GHE_RESTORE_IN_PROGRESS ]; then
87-
progress=$(cat $GHE_RESTORE_IN_PROGRESS)
88-
snapshot=$(echo "$progress" | cut -d ' ' -f 1)
89-
pid=$(echo "$progress" | cut -d ' ' -f 2)
90-
echo "Error: A restore of $GHE_HOSTNAME may still be running on PID $pid." 1>&2
91-
echo "If PID $pid is not a process related to the restore utilities, please remove" 1>&2
92-
echo "the $GHE_DATA_DIR/in-progress-restore file and try again." 1>&2
82+
if [ -f $GHE_RESTORE_IN_PROGRESS ]; then
83+
progress=$(cat $GHE_RESTORE_IN_PROGRESS)
84+
snapshot=$(echo "$progress" | cut -d ' ' -f 1)
85+
pid=$(echo "$progress" | cut -d ' ' -f 2)
86+
echo " Error: A restore of $GHE_HOSTNAME may still be running on PID $pid." 1>&2
87+
echo " If PID $pid is not a process related to the restore utilities, please remove" 1>&2
88+
echo " the \"$GHE_RESTORE_IN_PROGRESS\" file and try again." 1>&2
9389
exit 1
9490
fi
9591
}
9692

9793
ghe_backup_check() {
98-
if [ -h $GHE_BACKUP_IN_PROGRESS ]; then
99-
echo "Error: detected a backup already in progress from a previous version of ghe-backup." 1>&2
100-
echo "If there is no backup in progress anymore, please remove" 1>&2
101-
echo "the $GHE_DATA_DIR/in-progress-backup file." 1>&2
102-
exit 1
103-
fi
94+
if [ -h $GHE_BACKUP_IN_PROGRESS ]; then
95+
echo " Error: detected a backup already in progress from a previous version of ghe-backup." 1>&2
96+
echo " If there is no backup in progress anymore, please remove" 1>&2
97+
echo " the \"$GHE_DATA_DIR/i$GHE_BACKUP_IN_PROGRESS\" file and try again." 1>&2
98+
exit 1
99+
fi
104100

105-
if [ -f $GHE_BACKUP_IN_PROGRESS ]; then
106-
progress=$(cat $GHE_BACKUP_IN_PROGRESS)
107-
snapshot=$(echo "$progress" | cut -d ' ' -f 1)
108-
pid=$(echo "$progress" | cut -d ' ' -f 2)
109-
echo "Error: A backup of $GHE_HOSTNAME may still be running on PID $pid." 1>&2
110-
echo "If PID $pid is not a process related to the backup utilities, please remove" 1>&2
111-
echo "the $GHE_DATA_DIR/in-progress file and try again." 1>&2
101+
if [ -f $GHE_BACKUP_IN_PROGRESS ]; then
102+
progress=$(cat $GHE_BACKUP_IN_PROGRESS)
103+
snapshot=$(echo "$progress" | cut -d ' ' -f 1)
104+
pid=$(echo "$progress" | cut -d ' ' -f 2)
105+
echo " Error: A backup of $GHE_HOSTNAME may still be running on PID $pid." 1>&2
106+
echo " If PID $pid is not a process related to the backup utilities, please remove" 1>&2
107+
echo " the \"$GHE_BACKUP_IN_PROGRESS\" file and try again." 1>&2
112108
exit 1
113109
fi
114110
}

0 commit comments

Comments
 (0)