Skip to content

Commit f4663b1

Browse files
committed
Working but rough version of changes
Co-authored-by: Chuck Pathanjali <[email protected]>
1 parent dcfe6cc commit f4663b1

File tree

3 files changed

+61
-25
lines changed

3 files changed

+61
-25
lines changed

bin/ghe-backup

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ done
4545
ghe_parallel_check
4646

4747

48-
echo "We got here without any problems"
49-
exit 1
50-
5148
# Used to record failed backup steps
5249
failures=
5350
failures_file="$(mktemp -t backup-utils-backup-failures-XXXXXX)"
@@ -99,12 +96,12 @@ rm -rf src dest1 dest2
9996
# The cleanup trap also handles disabling maintenance mode on the appliance if
10097
# it was automatically enabled.
10198
cleanup () {
102-
if [ -f ../in-progress ]; then
103-
progress=$(cat ../in-progress)
99+
if [ -f ../.in-progress ]; then
100+
progress=$(cat ../.in-progress)
104101
snapshot=$(echo "$progress" | cut -d ' ' -f 1)
105102
pid=$(echo "$progress" | cut -d ' ' -f 2)
106103
if [ "$snapshot" = "$GHE_SNAPSHOT_TIMESTAMP" ] && [ "$$" = $pid ]; then
107-
unlink ../in-progress
104+
unlink ../.in-progress
108105
fi
109106
fi
110107

@@ -123,30 +120,30 @@ trap 'exit $?' INT # ^C always terminate
123120
ghe_restore_check
124121

125122
# Check to see if there is a running backup
126-
if [ -h ../in-progress ]; then
123+
if [ -h ../.in-progress ]; then
127124
echo "Error: detected a backup already in progress from a previous version of ghe-backup." 1>&2
128125
echo "If there is no backup in progress anymore, please remove" 1>&2
129-
echo "the $GHE_DATA_DIR/in-progress file." 1>&2
126+
echo "the $GHE_DATA_DIR/.in-progress file." 1>&2
130127
exit 1
131128
fi
132129

133-
if [ -f ../in-progress ]; then
134-
progress=$(cat ../in-progress)
130+
if [ -f ../.in-progress ]; then
131+
progress=$(cat ../.in-progress)
135132
snapshot=$(echo "$progress" | cut -d ' ' -f 1)
136133
pid=$(echo "$progress" | cut -d ' ' -f 2)
137134
if ! ps -p "$pid" >/dev/null 2>&1; then
138-
# We can safely remove in-progress, ghe-prune-snapshots
135+
# We can safely remove .in-progress, ghe-prune-snapshots
139136
# will clean up the failed backup.
140-
unlink ../in-progress
137+
unlink ../.in-progress
141138
else
142139
echo "Error: A backup of $GHE_HOSTNAME may still be running on PID $pid." 1>&2
143140
echo "If PID $pid is not a process related to the backup utilities, please remove" 1>&2
144-
echo "the $GHE_DATA_DIR/in-progress file and try again." 1>&2
141+
echo "the $GHE_DATA_DIR/.in-progress file and try again." 1>&2
145142
exit 1
146143
fi
147144
fi
148145

149-
echo "$GHE_SNAPSHOT_TIMESTAMP $$" > ../in-progress
146+
echo "$GHE_SNAPSHOT_TIMESTAMP $$" > ../.in-progress
150147

151148
echo "Starting backup of $GHE_HOSTNAME with backup-utils v$BACKUP_UTILS_VERSION in snapshot $GHE_SNAPSHOT_TIMESTAMP"
152149

bin/ghe-restore

Lines changed: 44 additions & 5 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-
ghe_restore_finished
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.
@@ -154,6 +154,25 @@ cleanup_cluster_nodes() {
154154
# Check to make sure moreutils parallel is installed and working properly
155155
ghe_parallel_check
156156

157+
# 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+
157176
# Check to make sure a restore or backup is not in progress
158177

159178

@@ -175,8 +194,23 @@ GHE_RESTORE_SNAPSHOT_PATH="$(ghe-restore-snapshot-path "$snapshot_id")"
175194
GHE_RESTORE_SNAPSHOT=$(basename "$GHE_RESTORE_SNAPSHOT_PATH")
176195
export GHE_RESTORE_SNAPSHOT
177196

178-
ghe_backup_check
179-
ghe_restore_check
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
180214

181215
# Detect if the backup we are restoring has a leaked ssh key
182216
echo "Checking for leaked keys in the backup snapshot that is being restored ..."
@@ -260,8 +294,13 @@ START_TIME=$(date +%s)
260294
echo 'Start time:' $START_TIME
261295
echo "Starting restore of $GHE_HOSTNAME with backup-utils v$BACKUP_UTILS_VERSION from snapshot $GHE_RESTORE_SNAPSHOT"
262296
ghe_remote_logger "Starting restore from $(hostname) with backup-utils v$BACKUP_UTILS_VERSION / snapshot $GHE_RESTORE_SNAPSHOT ..."
263-
ghe_restore_started $START_TIME
297+
# Create an in-progress-restore file to prevent simultaneous backup or restore runs
298+
echo "${START_TIME} $$" > ${GHE_DATA_DIR}/.in-progress-restore
264299

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

590629
echo "Restore of $GHE_HOSTNAME from snapshot $GHE_RESTORE_SNAPSHOT finished."
591-
ghe_restore_finished
630+
rm -f ${GHE_DATA_DIR}/.in-progress-restore
592631

593632
if ! $instance_configured; then
594633
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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ 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="../../${GHE_DATA_DIR}/.in-progress-restore"
70+
GHE_BACKUP_IN_PROGRESS="../../${GHE_DATA_DIR}/.in-progress"
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-
}
74+
#ghe_restore_started() {
75+
#echo "$1 $$" >> $GHE_RESTORE_IN_PROGRESS
76+
#}
7777

7878
ghe_restore_check() {
7979
if [ -h $GHE_RESTORE_IN_PROGRESS ]; then
@@ -122,7 +122,7 @@ ghe_restore_finished() {
122122
}
123123

124124
ghe_backup_finished() {
125-
if [ ! -f $GHE_BACKUP_IN_PROGRESS ]; then
125+
if [ -f $GHE_BACKUP_IN_PROGRESS ]; then
126126
rm -f $GHE_BACKUP_IN_PROGRESS
127127
fi
128128
}

0 commit comments

Comments
 (0)