Skip to content

Commit d7d39a7

Browse files
authored
Merge branch 'master' into separate-pruning-snapshots
2 parents c500539 + de192ea commit d7d39a7

34 files changed

+877
-63
lines changed

.github/workflows/docker-image.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ jobs:
1414

1515
steps:
1616
- uses: actions/checkout@v3
17-
- name: Build the Debian Docker image
17+
- name: Build the Ubuntu Docker image
1818
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}
21-
- name: Run tests in Debian Docker image
22-
run: docker run backup-utils:${GITHUB_RUN_ID} ghe-backup --version
21+
- name: Run tests in Ubuntu Docker image
22+
run: |
23+
docker run backup-utils:${GITHUB_RUN_ID} ghe-backup --version
24+
docker run backup-utils:${GITHUB_RUN_ID} rsync --version
2325
- name: Run tests in Alpine Docker image
24-
run: docker run backup-utils-alpine:${GITHUB_RUN_ID} ghe-backup --version
25-
26+
run: |
27+
docker run backup-utils-alpine:${GITHUB_RUN_ID} ghe-backup --version
28+
docker run backup-utils-alpine:${GITHUB_RUN_ID} rsync --version

.github/workflows/lint.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: Lint Code Base
22

33
on:
4-
push:
5-
branches-ignore: [master]
64
pull_request:
75
branches: [master]
86

.github/workflows/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ name: Test and build
22

33
on: [pull_request]
44

5-
65
jobs:
76
build:
87
strategy:
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Update Rsync Tag in Dockerfile
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *' # Runs daily at 00:00
6+
7+
jobs:
8+
update-rsync-tag:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v3
14+
15+
- name: Get latest rsync tag
16+
id: latest_tag
17+
run: |
18+
curl --silent "https://api.github.com/repos/WayneD/rsync/tags" | jq -r '.[0].name' | xargs -I {} echo "::set-output name=latest_tag::{}"
19+
20+
- name: Update Dockerfile with latest tag
21+
run: |
22+
sed -i -E "s/RSYNC_TAG=[0-9\.]+/RSYNC_TAG=${{ steps.latest_tag.outputs.latest_tag }}/g" Dockerfile
23+
24+
- name: Create Pull Request for tag update
25+
uses: peter-evans/create-pull-request@v3
26+
with:
27+
token: ${{ secrets.GITHUB_TOKEN }}
28+
commit-message: "Update rsync tag in Dockerfile"
29+
title: "Update rsync tag in Dockerfile"
30+
body: "This PR updates the rsync tag in the Dockerfile to the latest tagged version."
31+
branch: "update-rsync-tag"
32+
base: "master"
33+
path: "."
34+
labels: "automated-update,rsync"

Dockerfile

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,73 @@
1-
FROM ubuntu:focal
1+
# Multi stage build for backup-utils
2+
# Build layer is for compiling rsync from source
3+
# Runtime layer is for running backup-utils
4+
# https://docs.docker.com/develop/develop-images/multistage-build/
5+
# https://docs.docker.com/engine/userguide/eng-image/multistage-build/
26

3-
RUN apt-get -q -y update && \
4-
apt-get install -y --no-install-recommends \
5-
tar \
7+
# Build layer
8+
FROM ubuntu:focal AS build
9+
10+
# Install build dependencies
11+
RUN apt-get update && apt-get install --no-install-recommends -y \
12+
gcc \
13+
g++ \
14+
gawk \
15+
autoconf \
16+
make \
17+
automake \
18+
python3-cmarkgfm \
19+
acl \
20+
libacl1-dev \
21+
attr \
22+
libattr1-dev \
23+
libxxhash-dev \
24+
libzstd-dev \
25+
liblz4-dev \
26+
libssl-dev \
27+
git \
628
jq \
7-
rsync \
29+
bc \
30+
curl \
31+
tar \
32+
gzip \
833
ca-certificates \
9-
ssh \
34+
&& rm -rf /var/lib/apt/lists/*
35+
36+
# Download rsync source from https://github.com/WayneD/rsync/archive/refs/tags/[TAG].tar.gz pinned to specified tag
37+
ARG RSYNC_TAG=v3.2.7
38+
RUN curl https://github.com/WayneD/rsync/archive/refs/tags/${RSYNC_TAG}.tar.gz -L -o ${RSYNC_TAG}.tar.gz
39+
RUN mkdir -p /rsync-${RSYNC_TAG}&& tar -xzf ${RSYNC_TAG}.tar.gz -C /rsync-${RSYNC_TAG} --strip-components=1 && ls -la
40+
# Change to the working directory of the rsync source
41+
WORKDIR /rsync-${RSYNC_TAG}
42+
RUN ls -la && ./configure
43+
RUN make
44+
RUN make install
45+
46+
# Reset working directory
47+
WORKDIR /
48+
49+
# Runtime layer
50+
FROM ubuntu:focal AS runtime
51+
52+
# Install runtime dependencies - bash, git, OpenSSH 5.6 or newer, and jq v1.5 or newer.
53+
RUN apt-get update && apt-get install --no-install-recommends -y \
54+
bash \
1055
git \
56+
openssh-client \
57+
jq \
58+
bc \
1159
moreutils \
1260
gawk \
61+
ca-certificates \
62+
xxhash \
1363
&& rm -rf /var/lib/apt/lists/*
1464

65+
# Copy rsync from build layer
66+
COPY --from=build /usr/local/bin/rsync /usr/local/bin/rsync
67+
68+
# Copy backup-utils from repository into /backup-utils
1569
COPY ./ /backup-utils/
70+
1671
WORKDIR /backup-utils
1772

1873
RUN chmod +x /backup-utils/share/github-backup-utils/ghe-docker-init

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
SHELL = /bin/sh
22

33
test: info
4+
@echo Running tests
45
@script/cibuild --no-package
56

67
info:

backup.config-example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ GHE_NUM_SNAPSHOTS=10
4646
#
4747
#GHE_EXTRA_RSYNC_OPTS=""
4848

49+
# If enabled and set to 'no', rsync warning message during backups will be suppressed.
50+
#RSYNC_WARNING=no
51+
4952

5053
# If set to 'yes', logging output will be colorized.
5154
#

bin/ghe-backup

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,45 @@ while true; do
3737
esac
3838
done
3939

40+
4041
export CALLING_SCRIPT="ghe-backup"
42+
4143
# Bring in the backup configuration
4244
# shellcheck source=share/github-backup-utils/ghe-backup-config
4345
. "$( dirname "${BASH_SOURCE[0]}" )/../share/github-backup-utils/ghe-backup-config"
4446

47+
# Setup progress tracking
48+
init-progress
49+
export PROGRESS_TOTAL=14 # Minimum number of steps in backup is 14
50+
echo "$PROGRESS_TOTAL" > /tmp/backup-utils-progress-total
51+
export PROGRESS_TYPE="Backup"
52+
echo "$PROGRESS_TYPE" > /tmp/backup-utils-progress-type
53+
export PROGRESS=0 # Used to track progress of backup
54+
echo "$PROGRESS" > /tmp/backup-utils-progress
55+
56+
OPTIONAL_STEPS=0
57+
# Backup actions+mssql
58+
if ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.actions.enabled'; then
59+
OPTIONAL_STEPS=$((OPTIONAL_STEPS + 2))
60+
fi
61+
62+
# Backup fsck
63+
if [ "$GHE_BACKUP_FSCK" = "yes" ]; then
64+
OPTIONAL_STEPS=$((OPTIONAL_STEPS + 1))
65+
fi
66+
67+
# Backup minio
68+
if ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.minio.enabled'; then
69+
OPTIONAL_STEPS=$((OPTIONAL_STEPS + 1))
70+
fi
71+
72+
# Backup pages
73+
if [ "$GHE_BACKUP_PAGES" != "no" ]; then
74+
OPTIONAL_STEPS=$((OPTIONAL_STEPS + 1))
75+
fi
76+
77+
PROGRESS_TOTAL=$((OPTIONAL_STEPS + PROGRESS_TOTAL)) # Minimum number of steps in backup is 14
78+
echo "$PROGRESS_TOTAL" > /tmp/backup-utils-progress-total
4579
# Check to make sure moreutils parallel is installed and working properly
4680
ghe_parallel_check
4781

@@ -121,7 +155,7 @@ ghe_restore_check
121155
# Check to see if there is a running backup
122156
if [ -h ../in-progress ]; then
123157

124-
log_error "Error: detected a backup already in progress from a previous version of ghe-backup. \nIf there is no backup in progress anymore, please remove \nthe $GHE_DATA_DIR/in-progress file." 1>&2
158+
log_error "Detected a backup already in progress from a previous version of ghe-backup. \nIf there is no backup in progress anymore, please remove \nthe $GHE_DATA_DIR/in-progress file." >&2
125159
exit 1
126160
fi
127161

@@ -259,6 +293,7 @@ echo \"$cmd_title\"
259293
ghe-backup-git-hooks || printf %s \"git-hooks \" >> \"$failures_file\"")
260294

261295
if [ "$GHE_BACKUP_STRATEGY" = "rsync" ]; then
296+
increment-progress-total-count 1
262297
cmd_title=$(log_info "Backing up Elasticsearch indices ...")
263298
commands+=("
264299
echo \"$cmd_title\"
@@ -295,8 +330,10 @@ if [ -z "$failures" ]; then
295330
if [[ $GHE_PRUNING_SCHEDULED != "yes" ]]; then
296331
ghe-prune-snapshots
297332
else
298-
echo "Expired and incomplete snapshots to be pruned separately"
333+
log_info "Expired and incomplete snapshots to be pruned separately"
299334
fi
335+
else
336+
log_info "Skipping pruning snapshots, since some backups failed..."
300337
fi
301338

302339
END_TIME=$(date +%s)
@@ -310,6 +347,7 @@ else
310347
steps="${failures// /, }"
311348
ghe_remote_logger "Completed backup from $(hostname) / snapshot $GHE_SNAPSHOT_TIMESTAMP with failures: ${steps}."
312349
log_error "Error: Snapshot incomplete. Some steps failed: ${steps}. "
350+
ghe_backup_finished
313351
exit 1
314352
fi
315353

bin/ghe-backup-progress

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env bash
2+
#/ Usage: ghe-backup-progress [--once]
3+
#/ Tracks the completed steps of a backup or restore operation.
4+
#/
5+
#/ By default the progress is printed every continuously or until a key is pressed.
6+
#/ Use the --once option to print the current progress once and exit.
7+
#/
8+
#/ Options:
9+
#/ --once Don't loop, just print the current progress once.
10+
#
11+
set -e
12+
13+
while true; do
14+
case "$1" in
15+
-o|--once)
16+
ONCE=1
17+
shift
18+
;;
19+
-h|--help)
20+
export GHE_SHOW_HELP=true
21+
shift
22+
;;
23+
-*)
24+
echo "Unknown option: $1" >&2
25+
exit 1
26+
;;
27+
*)
28+
break
29+
;;
30+
esac
31+
done
32+
33+
check_for_progress_file() {
34+
if [ ! -f /tmp/backup-utils-progress-info ]; then
35+
echo "No progress file found. Has a backup or restore been started?"
36+
exit 1
37+
fi
38+
}
39+
40+
if [ -n "$ONCE" ]; then
41+
check_for_progress_file
42+
cat /tmp/backup-utils-progress-info
43+
else
44+
check_for_progress_file
45+
clear
46+
cat /tmp/backup-utils-progress-info
47+
while true; do
48+
if read -r -t 1 -n 1; then
49+
clear
50+
exit ;
51+
else
52+
clear
53+
cat /tmp/backup-utils-progress-info
54+
fi
55+
done
56+
fi

bin/ghe-host-check

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fi
131131

132132
# backup-utils 2.13 onwards limits support to the current and previous two releases
133133
# of GitHub Enterprise Server.
134-
supported_minimum_version="3.6.0"
134+
supported_minimum_version="3.7.0"
135135

136136
if [ "$(version $version)" -ge "$(version $supported_minimum_version)" ]; then
137137
supported=1
@@ -186,7 +186,7 @@ actions: $actions_disk_size MB
186186
mssql: $mssql_disk_size MB
187187
DATA_TRANSFER_SIZE
188188

189-
if [[ $available_space -lt $min_disk_req ]]; then
189+
if [[ $((available_space / (1024 * 1024))) -lt $min_disk_req ]]; then
190190
echo "There is not enough disk space for the backup. Please allocate more space and continue." 1>&2
191191
exit 1
192192
fi
@@ -213,9 +213,17 @@ DATA_TRANSFER_SIZE
213213
echo "rsync version $rsync_version in backup-host does not meet minimum requirements." 1>&2
214214
echo "Please make sure you have the minimum required version of rsync: $min_rsync installed" 1>&2
215215
exit 1
216-
else
217-
echo "rsync ${rsync_version} >= required ($min_rsync)" 1>&2
216+
elif [[ $rsync_version < 3.2.5 ]] && [[ $RSYNC_WARNING != "no" ]]; then
217+
cat << WARN_MSG 1>&2
218+
**WARNING:** rsync version $rsync_version on backup host is less than 3.2.5, which could result in performance degradation.
219+
220+
For more details, please read documentation at https://github.com/github/backup-utils/blob/master/docs/requirements.md#april-2023-update-of-rsync-requirements
221+
222+
You can disable this warning by changing RSYNC_WARNING to 'no' in your backup.config file.
223+
224+
WARN_MSG
218225
fi
226+
echo "rsync ${rsync_version} >= required ($min_rsync)" 1>&2
219227

220228
ssh_version=$(ssh -V 2>&1 | awk '{print $1}'|grep -oPm 1 '[\d\.]+' |head -1 | tr -cd '[:digit:].\n')
221229
if awk "BEGIN {exit !($ssh_version < $min_openssh)}" &> /dev/null; then

0 commit comments

Comments
 (0)