-
Notifications
You must be signed in to change notification settings - Fork 0
/
restore
45 lines (37 loc) · 1.34 KB
/
restore
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
#!/bin/bash
set -eu
if [ "${1:-}" = "gh-asset" ]; then
echo downloading github release asset...
REPO=${2:-}
PATTERN=${3:-}
VERSION=${4:-}
if [ "$REPO" = "" -o "$PATTERN" = "" ]; then
echo "usage: restore gh-asset <REPOSITORY> <ASSET-NAME> [<VERSION>]"
exit 1
fi
echo $GH_API_TOKEN | gh auth login --with-token
gh release download $VERSION --repo $REPO --pattern $PATTERN --dir /tmp
BACKUP_FILE=/tmp/$PATTERN
else
BACKUP_FILE=${BACKUP_FILE:-"/backup/mediawiki-backup.tar"}
fi
TMP_FOLDER=`mktemp -d`
cd $TMP_FOLDER
## show version
tar xf $BACKUP_FILE mediawiki-backup.version
echo backup This backup has been made by mediawiki-backup version `cat mediawiki-backup.version`
## restoring db
echo restoring mysql db
tar xf $BACKUP_FILE mysqldump.sql.bz2
bzip2 -d mysqldump.sql.bz2
echo restoring from dump
MYSQL_PWD=$MYSQL_ROOT_PASSWORD mysql --default-character-set=utf8 wiki < mysqldump.sql
echo mysqlcheck
MYSQL_PWD=$MYSQL_ROOT_PASSWORD mysqlcheck -h $MYSQL_HOST --repair --databases wiki
## restoring images
echo restoring images
rm -rf /var/www/html/images/* /var/www/html/images/.??*
tar -C /var/www/html -xf $BACKUP_FILE images
# setting owner if requested
test "${RESTORE_OWNER:-}" != "" && { echo set owner="$RESTORE_OWNER"; chown -R $RESTORE_OWNER /var/www/html/images; }
echo restored $BACKUP_FILE