Skip to content

Commit e44d516

Browse files
committed
Co-authored-by: Chuck Pathanjali <[email protected]>
1 parent 00e57b0 commit e44d516

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

bin/ghe-backup

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ done
4444
# Check to make sure moreutils parallel is installed and working properly
4545
ghe_parallel_check
4646

47+
48+
echo "We got here without any problems"
49+
exit 1
50+
4751
# Used to record failed backup steps
4852
failures=
4953
failures_file="$(mktemp -t backup-utils-backup-failures-XXXXXX)"
@@ -114,6 +118,10 @@ cleanup () {
114118
trap 'cleanup' EXIT
115119
trap 'exit $?' INT # ^C always terminate
116120

121+
122+
# Check to see if there is a running restore
123+
ghe_restore_check
124+
117125
if [ -h ../in-progress ]; then
118126
echo "Error: detected a backup already in progress from a previous version of ghe-backup." 1>&2
119127
echo "If there is no backup in progress anymore, please remove" 1>&2

bin/ghe-restore

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ cleanup () {
122122

123123
# Cleanup SSH multiplexing
124124
ghe-ssh --clean
125+
# Remove in-progress file
126+
ghe_restore_finished
125127
}
126128

127129
# This function's type definition is being passed to a remote host via `ghe-ssh` but is not used locally.
@@ -152,14 +154,17 @@ cleanup_cluster_nodes() {
152154
# Check to make sure moreutils parallel is installed and working properly
153155
ghe_parallel_check
154156

157+
# Check to make sure a restore or backup is not in progress
158+
159+
155160
# Grab the host arg
156161
GHE_HOSTNAME="${GHE_RESTORE_HOST_OPT:-$GHE_RESTORE_HOST}"
157162

158163
# Hostname without any port suffix
159164
hostname=$(echo "$GHE_HOSTNAME" | cut -f 1 -d :)
160165

161166
# Show usage with no <host>
162-
[ -z "$GHE_HOSTNAME" ] && print_usage
167+
#[ -z "$GHE_HOSTNAME" ] && print_usage
163168

164169
# Flag to indicate if this script has stopped Actions.
165170
ACTIONS_STOPPED=false
@@ -170,6 +175,11 @@ GHE_RESTORE_SNAPSHOT_PATH="$(ghe-restore-snapshot-path "$snapshot_id")"
170175
GHE_RESTORE_SNAPSHOT=$(basename "$GHE_RESTORE_SNAPSHOT_PATH")
171176
export GHE_RESTORE_SNAPSHOT
172177

178+
ghe_restore_check
179+
ghe_restore_started $GHE_RESTORE_SNAPSHOT
180+
#ghe_restore_finished
181+
echo "This happened without any problems!"
182+
exit 1
173183
# Detect if the backup we are restoring has a leaked ssh key
174184
echo "Checking for leaked keys in the backup snapshot that is being restored ..."
175185
ghe-detect-leaked-ssh-keys -s "$GHE_RESTORE_SNAPSHOT_PATH" || true

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,67 @@ 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"
71+
export GHE_RESTORE_IN_PROGRESS
72+
export GHE_BACKUP_IN_PROGRESS
73+
74+
ghe_restore_started() {
75+
echo "$1 $$" > $GHE_RESTORE_IN_PROGRESS
76+
}
77+
78+
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
85+
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
93+
exit 1
94+
fi
95+
}
96+
97+
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
104+
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
112+
exit 1
113+
fi
114+
}
115+
116+
ghe_restore_finished() {
117+
echo "$GHE_RESTORE_IN_PROGRESS"
118+
if [ -f $GHE_RESTORE_IN_PROGRESS ]; then
119+
echo "$GHE_RESTORE_IN_PROGRESS exists!" 1>&2
120+
rm -f $GHE_RESTORE_IN_PROGRESS
121+
fi
122+
}
123+
124+
ghe_backup_finished() {
125+
if [ ! -f $GHE_BACKUP_IN_PROGRESS ]; then
126+
rm -f $GHE_BACKUP_IN_PROGRESS
127+
fi
128+
}
129+
69130
ghe_parallel_check() {
70131
if [ "$GHE_PARALLEL_ENABLED" != "yes" ]; then
71132
return 0

0 commit comments

Comments
 (0)