Skip to content

Commit 8ca4516

Browse files
authored
Merge pull request #1086 from github/3.7-main
Sync 3.7 main with stable
2 parents 8683e1c + a7767f3 commit 8ca4516

File tree

12 files changed

+559
-35
lines changed

12 files changed

+559
-35
lines changed

bin/ghe-backup

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,30 @@ if [ -n "$GHE_ALLOW_REPLICA_BACKUP" ]; then
151151
echo "Warning: backing up a high availability replica may result in inconsistent or unreliable backups."
152152
fi
153153

154+
# Output system information of the backup host
155+
156+
# If /etc/issue.net exists, use it to get the OS version
157+
if [ -f /etc/issue.net ]; then
158+
echo "Running on: $(cat /etc/issue.net)"
159+
else
160+
echo "Running on: Unknown OS"
161+
fi
162+
163+
# If nproc command exists, use it to get the number of CPUs
164+
if command -v nproc >/dev/null 2>&1; then
165+
echo "CPUs: $(nproc)"
166+
else
167+
echo "CPUs: Unknown"
168+
fi
169+
170+
# If the free command exists, use it to get the memory details
171+
if command -v free >/dev/null 2>&1; then
172+
echo "Memory $(free -m | grep '^Mem:' | awk '{print "total/used/free+share/buff/cache: " $2 "/" $3 "/" $4 "+" $5 "/" $6 "/" $7}')"
173+
else
174+
echo "Memory: Unknown"
175+
fi
176+
177+
154178
# Log backup start message in /var/log/syslog on remote instance
155179
ghe_remote_logger "Starting backup from $(hostname) with backup-utils v$BACKUP_UTILS_VERSION in snapshot $GHE_SNAPSHOT_TIMESTAMP ..."
156180

bin/ghe-restore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,12 @@ if $RESTORE_SETTINGS; then
367367
ghe-restore-settings "$GHE_HOSTNAME"
368368
fi
369369

370+
# Always restore column encryption keys
371+
if [ "$(version $GHE_REMOTE_VERSION)" -ge "$(version 3.7.0)" ]; then
372+
echo "Always restore encrypted column encryption keys on GHES verions 3.7.0+"
373+
ghe-restore-column-encryption-keys "$GHE_HOSTNAME"
374+
fi
375+
370376
# Make sure mysql and elasticsearch are prep'd and running before restoring.
371377
# These services will not have been started on appliances that have not been
372378
# configured yet.

debian/changelog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
github-backup-utils (3.7.1) UNRELEASED; urgency=medium
2+
3+
* Don't fail a backup if the Management Console password isn't set #416
4+
* Prevent restoring snapshots to older releases #420
5+
* Use old rsync restore method for pages prior to 2.13 #426
6+
7+
-- Devin Dooley <[email protected]> Fri, 21 Jul 2023 02:08:41 +0000
8+
19
github-backup-utils (3.7.0) UNRELEASED; urgency=medium
210

311

script/release

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ GH_REPO = ENV['GH_REPO'] || 'backup-utils'
3131
GH_OWNER = ENV['GH_OWNER'] || 'github'
3232
GH_AUTHOR = ENV['GH_AUTHOR']
3333
DEB_PKG_NAME = 'github-backup-utils'
34-
GH_BASE_BRANCH = ENV['GH_BASE_BRANCH'] || 'master'
34+
GH_BASE_BRANCH = ENV['GH_BASE_BRANCH'] || 'master' # TODO: should we even allow a default or require all params get set explicitly?
35+
GH_STABLE_BRANCH = ""
3536

3637
CHANGELOG_TMPL = '''<%= package_name %> (<%= package_version %>) UNRELEASED; urgency=medium
3738
@@ -137,7 +138,8 @@ def beautify_changes(changes)
137138
end
138139

139140
def changelog
140-
changes = `git log --pretty=oneline origin/stable...origin/#{GH_BASE_BRANCH} --reverse --grep "Merge pull request" | sort -t\# -k2`.lines.map(&:strip)
141+
puts "building changelog by comparing origin/#{GH_STABLE_BRANCH}...origin/#{GH_BASE_BRANCH}"
142+
changes = `git log --pretty=oneline origin/#{GH_STABLE_BRANCH}...origin/#{GH_BASE_BRANCH} --reverse --grep "Merge pull request" | sort -t\# -k2`.lines.map(&:strip)
141143
raise 'Building the changelog failed' if $CHILD_STATUS != 0
142144

143145
changes
@@ -228,12 +230,12 @@ def push_release_branch(version)
228230
end
229231

230232
def update_stable_branch
231-
`git checkout --quiet stable`
233+
`git checkout --quiet #{GH_STABLE_BRANCH}`
232234
unless (out = `git merge --quiet --ff-only origin/#{GH_BASE_BRANCH}`)
233-
warn "Merging #{GH_BASE_BRANCH} into stable failed:\n\n#{out}"
235+
warn "Merging #{GH_BASE_BRANCH} into #{GH_STABLE_BRANCH} failed:\n\n#{out}"
234236
end
235-
unless (out = `git push --quiet origin stable`)
236-
warn "Failed pushing the stable branch:\n\n#{out}"
237+
unless (out = `git push --quiet origin #{GH_STABLE_BRANCH}`)
238+
warn "Failed pushing the #{GH_STABLE_BRANCH} branch:\n\n#{out}"
237239
end
238240
end
239241

@@ -333,9 +335,38 @@ def clean_up(version)
333335
`git branch --quiet -D tmp-packging >/dev/null 2>&1`
334336
end
335337

338+
def is_base_branch_valid?(branch)
339+
if branch == "master" || branch.match(/^\d+\.\d+-main$/)
340+
return true
341+
else
342+
return false
343+
end
344+
end
345+
346+
def get_stable_branch_name(branch)
347+
## derive the proper stable branch. if the base branch is "master" the stable branch is just "stable"
348+
## if the base branch is a release branch, the stable branch will be "x.y-stable"
349+
result = ""
350+
if branch == "master"
351+
result = "stable"
352+
else
353+
result = branch.gsub(/-main$/, "-stable")
354+
end
355+
356+
result
357+
end
358+
336359
#### All the action starts ####
337360
if $PROGRAM_NAME == __FILE__
338361
begin
362+
## validate base branch. this must either be "master" or a release branch which will match the pattern "x.y-main"
363+
raise "The branch #{GH_BASE_BRANCH} is not valid for releasing backup-utils. branch name must be master or match x.y-main" if !is_base_branch_valid?(GH_BASE_BRANCH)
364+
365+
GH_STABLE_BRANCH = get_stable_branch_name(GH_BASE_BRANCH)
366+
367+
puts "base branch = " + GH_BASE_BRANCH
368+
puts "stable branch = " + GH_STABLE_BRANCH
369+
339370
args = ARGV.dup
340371
dry_run = false
341372
skip_version_bump_check = false
@@ -455,7 +486,7 @@ if $PROGRAM_NAME == __FILE__
455486
puts 'Cleaning up...'
456487
clean_up version
457488

458-
puts 'Updating stable branch...'
489+
puts "Updating #{GH_STABLE_BRANCH} branch..."
459490
update_stable_branch
460491

461492
puts 'Released!'

share/github-backup-utils/ghe-backup-mssql

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,18 @@ add_minute() {
3838
# Expect date string in the format of yyyymmddTHHMMSS
3939
# Here parse date differently depending on GNU Linux vs BSD MacOS
4040
if date -v -1d > /dev/null 2>&1; then
41-
echo "$(date -v +$2M -ujf'%Y%m%dT%H%M%S' $1 +%Y%m%dT%H%M%S)"
41+
date -v +"$2"M -ujf'%Y%m%dT%H%M%S' "$1" +%Y%m%dT%H%M%S
4242
else
4343
dt=$1
44-
echo "$(date -u '+%Y%m%dT%H%M%S' -d "${dt:0:8} ${dt:9:2}:${dt:11:2}:${dt:13:2} $2 minutes")"
44+
date -u '+%Y%m%dT%H%M%S' -d "${dt:0:8} ${dt:9:2}:${dt:11:2}:${dt:13:2} $2 minutes"
4545
fi
4646
}
4747

4848
find_timestamp() {
4949
filename="${1##*/}"
5050
IFS='@' read -ra parts <<< "$filename"
5151
datetime_part=${parts[1]:0:15}
52-
echo $datetime_part
52+
echo "$datetime_part"
5353
}
5454

5555
actions_dbs() {
@@ -98,7 +98,7 @@ get_latest_backup_file() {
9898
db=$2
9999
ext=$3
100100

101-
latest_full_backup=$(find "$backups_dir" -type f -name "$db*.$ext" | egrep '[0-9]{8}T[0-9]{6}' | sort | tail -n 1)
101+
latest_full_backup=$(find "$backups_dir" -type f -name "$db*.$ext" | grep -E '[0-9]{8}T[0-9]{6}' | sort | tail -n 1)
102102
latest_full_backup_file="${latest_full_backup##*/}"
103103
echo "$latest_full_backup_file"
104104
}
@@ -146,8 +146,8 @@ get_next_diff_backup_base_lsn() {
146146

147147
last_mssql=$GHE_DATA_DIR/current/mssql
148148

149-
if [ ! -d $last_mssql ] \
150-
|| [ -z "$(find $last_mssql -type f -name '*.bak' | head -n 1)" ]; then
149+
if [ ! -d "$last_mssql" ] \
150+
|| [ -z "$(find "$last_mssql" -type f -name '*.bak' | head -n 1)" ]; then
151151
ghe_verbose "Taking first full backup"
152152
backup_type="full"
153153
else
@@ -159,34 +159,34 @@ else
159159
current=$(date -u +%Y%m%d%H%M%S)
160160

161161
full=$(find "$last_mssql" -type f -name "*.bak" | head -n 1)
162-
full=$(find_timestamp $full)
163-
full_expire=$(add_minute $full ${cadence[0]})
162+
full=$(find_timestamp "$full")
163+
full_expire=$(add_minute "$full" "${cadence[0]}")
164164
full_expire="${full_expire//T}"
165165

166166
diff=$(find "$last_mssql" -type f -name "*.diff" | head -n 1)
167167
if [ -f "$diff" ]; then
168-
diff=$(find_timestamp $diff)
169-
diff_expire=$(add_minute $diff ${cadence[1]})
168+
diff=$(find_timestamp "$diff")
169+
diff_expire=$(add_minute "$diff" "${cadence[1]}")
170170
diff_expire="${diff_expire//T}"
171171
else
172-
diff_expire=$(add_minute $full ${cadence[1]})
172+
diff_expire=$(add_minute "$full" "${cadence[1]}")
173173
diff_expire="${diff_expire//T}"
174174
fi
175175

176-
tran=$(find "$last_mssql" -type f -name "*.log" | egrep '[0-9]{8}T[0-9]{6}' | sort | tail -1)
177-
tran=$(find_timestamp $tran)
178-
tran_expire=$(add_minute $tran ${cadence[2]})
176+
tran=$(find "$last_mssql" -type f -name "*.log" | grep -E '[0-9]{8}T[0-9]{6}' | sort | tail -1)
177+
tran=$(find_timestamp "$tran")
178+
tran_expire=$(add_minute "$tran" "${cadence[2]}")
179179
tran_expire="${tran_expire//T}"
180180

181181
ghe_verbose "current $current, full expire $full_expire, \
182182
diff expire $diff_expire, tran expire $tran_expire"
183183

184184
# Determine the type of backup to take based on expiry time
185-
if [ $current -gt $full_expire ]; then
185+
if [ "$current" -gt "$full_expire" ]; then
186186
backup_type='full'
187-
elif [ $current -gt $diff_expire ]; then
187+
elif [ "$current" -gt "$diff_expire" ]; then
188188
backup_type='diff'
189-
elif [ $current -gt $tran_expire ]; then
189+
elif [ "$current" -gt "$tran_expire" ]; then
190190
backup_type='transaction'
191191
fi
192192

@@ -264,8 +264,8 @@ fi
264264
mkdir -p "$backup_dir"
265265

266266
# Use hard links to "copy" over previous applicable backups to the new snapshot folder to save disk space and time
267-
if [ -d $last_mssql ]; then
268-
for p in $last_mssql/*
267+
if [ -d "$last_mssql" ]; then
268+
for p in "$last_mssql"/*
269269
do
270270
[[ -e "$p" ]] || break
271271

@@ -274,23 +274,23 @@ if [ -d $last_mssql ]; then
274274
transfer=
275275

276276
# Copy full backups unless we're taking a new full backup
277-
if [ $extension = "bak" ] && [ "$backup_type" != 'full' ]; then
277+
if [ "$extension" = "bak" ] && [ "$backup_type" != 'full' ]; then
278278
transfer=1
279279
fi
280280

281281
# Copy diff backups unless we're taking a new full or diff backup
282-
if [ $extension = "diff" ] && [ "$backup_type" != 'full' ] && [ "$backup_type" != 'diff' ]; then
282+
if [ "$extension" = "diff" ] && [ "$backup_type" != 'full' ] && [ "$backup_type" != 'diff' ]; then
283283
transfer=1
284284
fi
285285

286286
# Copy transaction log backups unless we're taking a new full or diff backup
287-
if [ $extension = "log" ] && [ "$backup_type" != 'full' ] && [ "$backup_type" != 'diff' ]; then
287+
if [ "$extension" = "log" ] && [ "$backup_type" != 'full' ] && [ "$backup_type" != 'diff' ]; then
288288
transfer=1
289289
fi
290290

291291
if [ -n "$transfer" ]; then
292292
ghe_verbose "Creating hard link to $filename"
293-
ln $last_mssql/$filename $backup_dir/$filename
293+
ln "$last_mssql"/"$filename" "$backup_dir"/"$filename"
294294
fi
295295
done
296296
fi
@@ -305,9 +305,9 @@ if [ -n "$backup_type" ]; then
305305
backup_command='ghe-export-mssql -t'
306306
fi
307307

308-
bm_start "$(basename $0)"
309-
ghe-ssh "$GHE_HOSTNAME" -- "$backup_command" || failures="$failures mssql"
310-
bm_end "$(basename $0)"
308+
bm_start "$(basename "$0")"
309+
ghe-ssh "$GHE_HOSTNAME" -- "$backup_command"
310+
bm_end "$(basename "$0")"
311311

312312
# Configure the backup cadence on the appliance, which is used for diagnostics
313313
ghe-ssh "$GHE_HOSTNAME" "ghe-config mssql.backup.cadence $GHE_MSSQL_BACKUP_CADENCE"
@@ -319,6 +319,6 @@ if [ -n "$backup_type" ]; then
319319
for b in $backups
320320
do
321321
ghe_verbose "Transferring to backup host $b"
322-
ghe-ssh "$GHE_HOSTNAME" "sudo cat $appliance_dir/$b" > $backup_dir/$b
322+
ghe-ssh "$GHE_HOSTNAME" "sudo cat $appliance_dir/$b" > "$backup_dir"/"$b"
323323
done
324324
fi

share/github-backup-utils/ghe-backup-settings

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,24 @@ backup-secret() {
7676

7777
backup-secret "management console password" "manage-password" "secrets.manage"
7878
backup-secret "password pepper" "password-pepper" "secrets.github.user-password-secrets"
79+
backup-secret "encrypted column encryption keying material" "encrypted-column-encryption-keying-material" "secrets.github.encrypted-column-keying-material"
80+
backup-secret "kredz.credz HMAC key" "kredz-credz-hmac" "secrets.kredz.credz-hmac-secret"
81+
backup-secret "kredz.varz HMAC key" "kredz-varz-hmac" "secrets.kredz.varz-hmac-secret"
82+
83+
# backup encryption keying material for GHES 3.7.0 onwards
84+
if [ "$(version $GHE_REMOTE_VERSION)" -ge "$(version 3.7.0)" ]; then
85+
backup-secret "encrypted column encryption keying material" "encrypted-column-encryption-keying-material" "secrets.github.encrypted-column-keying-material"
86+
fi
87+
88+
# backup current encryption key for GHES 3.8.0 onwards
89+
if [ "$(version $GHE_REMOTE_VERSION)" -ge "$(version 3.8.0)" ]; then
90+
backup-secret "encrypted column current encryption key" "encrypted-column-current-encryption-key" "secrets.github.encrypted-column-current-encryption-key"
91+
fi
92+
93+
# Backup argon secrets for multiuser from ghes version 3.8 onwards
94+
if [[ "$(version $GHE_REMOTE_VERSION)" -ge "$(version 3.8.0)" && "$(version $GHE_REMOTE_VERSION)" -lt "$(version 3.8.2)" ]]; then
95+
backup-secret "management console argon2 secret" "manage-argon-secret" "secrets.manage-auth.argon-secret"
96+
fi
7997

8098
# Backup external MySQL password if running external MySQL DB.
8199
if is_service_external 'mysql'; then
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
#/ Usage: ghe-restore-column-encryption-keys <host>
3+
#/ Restore the column encryption keys from a snapshot to the given <host>.
4+
#/ This script will be run automatically by `ghe-restore
5+
set -e
6+
7+
# Bring in the backup configuration
8+
# shellcheck source=share/github-backup-utils/ghe-backup-config
9+
. "$( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config"
10+
11+
# Show usage and bail with no arguments
12+
[ -z "$*" ] && print_usage
13+
14+
bm_start "$(basename "$0")"
15+
16+
# Grab host arg
17+
GHE_HOSTNAME="$1"
18+
19+
# Perform a host-check and establish GHE_REMOTE_XXX variables.
20+
ghe_remote_version_required "$GHE_HOSTNAME"
21+
22+
# The snapshot to restore should be set by the ghe-restore command but this lets
23+
# us run this script directly.
24+
: "${GHE_RESTORE_SNAPSHOT:=current}"
25+
26+
# Path to snapshot dir we're restoring from
27+
: "${GHE_RESTORE_SNAPSHOT_PATH:="$GHE_DATA_DIR/current"}"
28+
29+
# Restore encrypted column encryption keying material for GHES 3.7.0 onward
30+
if [ "$(version "$GHE_REMOTE_VERSION")" -ge "$(version 3.7.0)" ]; then
31+
echo "Restoring encrypted column encryption keying material"
32+
restore-secret "encrypted column encryption keying material" "encrypted-column-encryption-keying-material" "secrets.github.encrypted-column-keying-material"
33+
fi
34+
35+
# Restore encrypted column current encryption key for GHES 3.8.0 onwards
36+
if [ "$(version "$GHE_REMOTE_VERSION")" -ge "$(version 3.8.0)" ]; then
37+
echo "Restoring encrypted column current encryption key"
38+
restore-secret "encrypted column current encryption key" "encrypted-column-current-encryption-key" "secrets.github.encrypted-column-current-encryption-key"
39+
fi
40+
41+
42+
bm_end "$(basename "$0")"

share/github-backup-utils/ghe-restore-settings

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ ghe-restore-packages "$GHE_HOSTNAME" 1>&3
4444
# Restore management console password hash if present.
4545
restore-secret "management console password" "manage-password" "secrets.manage"
4646

47+
# Restore management console argon2 secret if present.
48+
restore-secret "management console argon2 secret" "manage-argon-secret" "secrets.manage-auth.argon-secret"
49+
50+
# Restore encrypted column encryption keying material if present
51+
restore-secret "encrypted column encryption keying material" "encrypted-column-encryption-keying-material" "secrets.github.encrypted-column-keying-material"
52+
53+
# Restore kredz.credz HMAC key if present.
54+
restore-secret "kredz.credz HMAC key" "kredz-credz-hmac" "secrets.kredz.credz-hmac-secret"
55+
56+
# Restore kredz.varz HMAC key if present.
57+
restore-secret "kredz.varz HMAC key" "kredz-varz-hmac" "secrets.kredz.varz-hmac-secret"
58+
4759
# Restore SAML keys if present.
4860
if [ -f "$GHE_RESTORE_SNAPSHOT_PATH/saml-keys.tar" ]; then
4961
echo "Restoring SAML keys ..."

share/github-backup-utils/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.7.0
1+
3.7.1

0 commit comments

Comments
 (0)