Skip to content

Commit df48797

Browse files
authored
Merge pull request #1008 from github/sync-private-to-public
Sync private to public
2 parents 8bbd273 + 16ad611 commit df48797

17 files changed

+360
-127
lines changed

.github/workflows/docker-image.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ jobs:
1515
steps:
1616
- uses: actions/checkout@v3
1717
- name: Build the Debian Docker image
18-
run: docker build . --file Dockerfile --tag backup-utils-debian:${GITHUB_RUN_ID}
18+
run: docker build . --file Dockerfile --tag backup-utils:${GITHUB_RUN_ID}
1919
- name: Build the Alpine Docker image
2020
run: docker build . --file Dockerfile.alpine --tag backup-utils-alpine:${GITHUB_RUN_ID}
2121
- name: Run tests in Debian Docker image
22-
run: docker run backup-utils-debian:${GITHUB_RUN_ID} ghe-backup --version
22+
run: docker run backup-utils:${GITHUB_RUN_ID} ghe-backup --version
2323
- name: Run tests in Alpine Docker image
2424
run: docker run backup-utils-alpine:${GITHUB_RUN_ID} ghe-backup --version
2525

.github/workflows/main.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ name: Test and build
22

33
on: [pull_request]
44

5+
56
jobs:
67
build:
78
strategy:
89
matrix:
9-
os: ['ubuntu-22.04', 'ubuntu-20.04', 'ubuntu-18.04', 'macos-latest']
10+
# macos-latest references are kept here for historical purposes. removed macos-latest from the
11+
#matrix as it is not a typical case for users and causes a lot of friction with other linux-based
12+
# installs. Recommend developing on codespaces or using an ubuntu container.
13+
os: ['ubuntu-22.04', 'ubuntu-20.04', 'ubuntu-18.04']
1014
fail-fast: false
1115
runs-on: ${{ matrix.os }}
1216
steps:

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM debian:buster-slim
1+
FROM ubuntu:focal
22

33
RUN apt-get -q -y update && \
44
apt-get install -y --no-install-recommends \

RELEASING.md

Lines changed: 0 additions & 66 deletions
This file was deleted.

bin/ghe-backup

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

47+
4748
# Used to record failed backup steps
4849
failures=
4950
failures_file="$(mktemp -t backup-utils-backup-failures-XXXXXX)"
@@ -63,7 +64,7 @@ touch "incomplete"
6364
# Exit early if the snapshot filesystem doesn't support hard links, symlinks and
6465
# if rsync doesn't support hardlinking of dangling symlinks
6566
trap 'rm -rf src dest1 dest2' EXIT
66-
mkdir src
67+
mkdir -p src
6768
touch src/testfile
6869
if ! ln -s /data/does/not/exist/hooks/ src/ >/dev/null 2>&1; then
6970
echo "Error: the filesystem containing $GHE_DATA_DIR does not support symbolic links." 1>&2
@@ -105,6 +106,7 @@ cleanup () {
105106
fi
106107

107108
rm -rf "$failures_file"
109+
rm -f ${GHE_DATA_DIR}/in-progress-backup
108110

109111
# Cleanup SSH multiplexing
110112
ghe-ssh --clean
@@ -114,10 +116,15 @@ cleanup () {
114116
trap 'cleanup' EXIT
115117
trap 'exit $?' INT # ^C always terminate
116118

119+
120+
# Check to see if there is a running restore
121+
ghe_restore_check
122+
123+
# Check to see if there is a running backup
117124
if [ -h ../in-progress ]; then
118125
echo "Error: detected a backup already in progress from a previous version of ghe-backup." 1>&2
119126
echo "If there is no backup in progress anymore, please remove" 1>&2
120-
echo "the $GHE_DATA_DIR/in-progress file." 1>&2
127+
echo "the $GHE_DATA_DIR/in-progress file and try again." 1>&2
121128
exit 1
122129
fi
123130

@@ -131,13 +138,15 @@ if [ -f ../in-progress ]; then
131138
unlink ../in-progress
132139
else
133140
echo "Error: A backup of $GHE_HOSTNAME may still be running on PID $pid." 1>&2
134-
echo "If PID $pid is not a process related to the backup utilities, please remove" 1>&2
135-
echo "the $GHE_DATA_DIR/in-progress file and try again." 1>&2
141+
echo 1>&2
142+
echo " If PID $pid is not a process related to the backup utilities, please remove" 1>&2
143+
echo " the $GHE_DATA_DIR/in-progress file and try again." 1>&2
136144
exit 1
137145
fi
138146
fi
139147

140148
echo "$GHE_SNAPSHOT_TIMESTAMP $$" > ../in-progress
149+
echo "$GHE_SNAPSHOT_TIMESTAMP $$" > ${GHE_DATA_DIR}/in-progress-backup
141150

142151
START_TIME=$(date +%s)
143152
echo 'Start time:' $START_TIME
@@ -278,3 +287,6 @@ ghe-detect-leaked-ssh-keys -s "$GHE_SNAPSHOT_DIR" || true
278287

279288
# Make sure we exit zero after the conditional
280289
true
290+
291+
# Remove in-progress file
292+
ghe_backup_finished

bin/ghe-restore

Lines changed: 11 additions & 0 deletions
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+
rm -f ${GHE_DATA_DIR}/in-progress-restore
125127
}
126128

127129
# This function's type definition is being passed to a remote host via `ghe-ssh` but is not used locally.
@@ -152,6 +154,9 @@ 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 another restore process is not running
158+
ghe_restore_check
159+
155160
# Grab the host arg
156161
GHE_HOSTNAME="${GHE_RESTORE_HOST_OPT:-$GHE_RESTORE_HOST}"
157162

@@ -170,6 +175,9 @@ 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+
# Check to make sure backup is not running
179+
ghe_backup_check
180+
173181
# Detect if the backup we are restoring has a leaked ssh key
174182
echo "Checking for leaked keys in the backup snapshot that is being restored ..."
175183
ghe-detect-leaked-ssh-keys -s "$GHE_RESTORE_SNAPSHOT_PATH" || true
@@ -252,6 +260,8 @@ START_TIME=$(date +%s)
252260
echo 'Start time:' $START_TIME
253261
echo "Starting restore of $GHE_HOSTNAME with backup-utils v$BACKUP_UTILS_VERSION from snapshot $GHE_RESTORE_SNAPSHOT"
254262
ghe_remote_logger "Starting restore from $(hostname) with backup-utils v$BACKUP_UTILS_VERSION / snapshot $GHE_RESTORE_SNAPSHOT ..."
263+
# Create an in-progress-restore file to prevent simultaneous backup or restore runs
264+
echo "${START_TIME} $$" > ${GHE_DATA_DIR}/in-progress-restore
255265

256266
# Keep other processes on the VM or cluster in the loop about the restore status.
257267
#
@@ -579,6 +589,7 @@ echo 'End time:' $END_TIME
579589
echo 'Runtime:' $(($END_TIME - $START_TIME)) 'seconds'
580590

581591
echo "Restore of $GHE_HOSTNAME from snapshot $GHE_RESTORE_SNAPSHOT finished."
592+
ghe_restore_finished
582593

583594
if ! $instance_configured; then
584595
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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,60 @@ for f in "$GHE_BACKUP_CONFIG" "$GHE_BACKUP_ROOT/backup.config" \
6666
fi
6767
done
6868

69+
GHE_RESTORE_IN_PROGRESS=$(readlink -fm "${GHE_DATA_DIR}/in-progress-restore")
70+
GHE_BACKUP_IN_PROGRESS=$(readlink -fm "${GHE_DATA_DIR}/in-progress-backup")
71+
72+
export GHE_RESTORE_IN_PROGRESS
73+
export GHE_BACKUP_IN_PROGRESS
74+
75+
ghe_restore_check() {
76+
if [ -h $GHE_RESTORE_IN_PROGRESS ]; then
77+
echo " Error: detected a restore already in progress from a previous version of ghe-restore." 1>&2
78+
echo " If there is no restore in progress anymore, please remove" 1>&2
79+
echo " the $GHE_RESTORE_IN_PROGRESS file and try again." 1>&2
80+
exit 1
81+
fi
82+
83+
if [ -f $GHE_RESTORE_IN_PROGRESS ]; then
84+
progress=$(cat $GHE_RESTORE_IN_PROGRESS)
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
89+
exit 1
90+
fi
91+
}
92+
93+
ghe_backup_check() {
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/$GHE_BACKUP_IN_PROGRESS file and try again." 1>&2
98+
exit 1
99+
fi
100+
101+
if [ -f $GHE_BACKUP_IN_PROGRESS ]; then
102+
progress=$(cat $GHE_BACKUP_IN_PROGRESS)
103+
pid=$(echo "$progress" | cut -d ' ' -f 2)
104+
echo " Error: A backup of $GHE_HOSTNAME may still be running on PID $pid." 1>&2
105+
echo " If PID $pid is not a process related to the backup utilities, please remove" 1>&2
106+
echo " the $GHE_BACKUP_IN_PROGRESS file and try again." 1>&2
107+
exit 1
108+
fi
109+
}
110+
111+
ghe_restore_finished() {
112+
if [ -f $GHE_RESTORE_IN_PROGRESS ]; then
113+
rm -f $GHE_RESTORE_IN_PROGRESS
114+
fi
115+
}
116+
117+
ghe_backup_finished() {
118+
if [ -f $GHE_BACKUP_IN_PROGRESS ]; then
119+
rm -f $GHE_BACKUP_IN_PROGRESS
120+
fi
121+
}
122+
69123
ghe_parallel_check() {
70124
if [ "$GHE_PARALLEL_ENABLED" != "yes" ]; then
71125
return 0

0 commit comments

Comments
 (0)