-
Notifications
You must be signed in to change notification settings - Fork 1
/
backup.sh
73 lines (54 loc) · 1.48 KB
/
backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#! /bin/bash
set -e
if [ "${AWS_ACCESS_KEY_ID}" == "**None**" ]; then
echo "Warning: You did not set the AWS_ACCESS_KEY_ID environment variable."
fi
if [ "${AWS_SECRET_ACCESS_KEY}" == "**None**" ]; then
echo "Warning: You did not set the AWS_SECRET_ACCESS_KEY environment variable."
fi
if [ "${S3_BUCKET}" == "**None**" ]; then
echo "You need to set the S3_BUCKET environment variable."
exit 1
fi
if [ "${S3_REGION}" == "**None**" ]; then
echo "You need to set the S3_REGION environment variable."
exit 1
fi
move_to_s3 () {
SRC_FILE=$1
DEST_FILE=$2
if [ "${S3_ENDPOINT}" == "**None**" ]; then
AWS_ARGS=""
else
AWS_ARGS="--endpoint-url ${S3_ENDPOINT}"
fi
if [ "${S3_PREFIX}" == "**None**" ]; then
S3_URI="s3://${S3_BUCKET}/${DEST_FILE}"
else
S3_URI="s3://${S3_BUCKET}/${S3_PREFIX}/${DEST_FILE}"
fi
if [ "${S3_ENCRYPT}" == "yes" ]; then
S3_OPTS="--sse"
else
S3_OPTS=""
fi
echo "Uploading ${DEST_FILE} on S3..."
cat $SRC_FILE | aws $AWS_ARGS s3 cp - $S3_URI $S3_OPTS
if [ $? != 0 ]; then
>&2 echo "Error uploading ${DEST_FILE} on S3"
fi
rm $SRC_FILE
}
export AWS_DEFAULT_REGION=$S3_REGION
BACKUP_START_TIME=$(date +"%Y-%m-%dT%H%M%SZ")
S3_FILE="${BACKUP_START_TIME}.gitea-dump.zip"
cd /backup
echo "Dumping Gitea..."
su -c "/app/gitea/gitea dump" $GITEA_USER
echo "Done"
unset -v DUMP_FILE
for FILE in /backup/*; do
[[ $FILE -nt $DUMP_FILE ]] && DUMP_FILE=$FILE;
done
move_to_s3 $DUMP_FILE $S3_FILE
echo "Gitea backup finished"