Skip to content

Commit

Permalink
Read credentials from a php file if provided
Browse files Browse the repository at this point in the history
to simplify a cluster setting.

Related to femiwiki/femiwiki#230
  • Loading branch information
lens0021 committed Apr 2, 2021
1 parent afd8500 commit 549fc66
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 23 deletions.
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ RUN apt-get update && apt-get -y install cron
COPY crontab .
RUN crontab crontab && rm crontab

# Install php
RUN apt-get update && apt-get install -y php-cli

# Install python
RUN apt-get update && apt-get install -y python3-pip

Expand All @@ -31,6 +34,6 @@ RUN python3 -m pip install --upgrade pip &&\
python3 -m pip install awscli

# Copy scripts
COPY do-backup docker-cmd ./
COPY do-backup docker-cmd /usr/local/bin/

CMD ["/a/docker-cmd"]
CMD ["/usr/local/bin/docker-cmd"]
52 changes: 33 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,55 @@
backupbot [![Docker Badge]][Docker Hub]
========
주기적으로 [MySQL]을 덤프하여 [AWS S3]에 업로드합니다.
# backupbot [![Docker Badge]][docker hub]

A Docker image for dumping [MySQL] that contains [MediaWiki] data and uploading to [AWS S3] periodically. This image is designed for [FemiWiki].

```bash
# Configuring network is required

# Passing username and password as environment variables
docker run --detach \
--name backupbot \
--restart always \
-e 'DB_USERNAME=xxxxxxxx' \
-e 'DB_PASSWORD=xxxxxxxx' \
femiwiki/backupbot
# 추가적인 네트워크 설정이 필요합니다.

# Alternatively, you can provide LocalSettings.php instead
docker run --detach \
--name backupbot \
--restart always \
-v $PWD/LocalSettings.php:/a/LocalSettings.php \
femiwiki/backupbot
```

백업 파일의 사용 방법
--------
## Environment variables

https://github.com/femiwiki/docker-mediawiki/blob/main/README.md 등의 설명에 따라 미디어위키를 실행한 후 [Restoring a wiki from backup](https://www.mediawiki.org/wiki/Manual:Restoring_a_wiki_from_backup) 메뉴얼을 따릅니다. 예를 들어 mysql 콘테이너에 백업 파일을 복사한 후 다음 커맨드를 실행합니다.
- `DB_USERNAME`: The user name passed to access the database. If `/a/LocalSettings.php` is exist, this will be ignored.
- `DB_PASSWORD`: The password passed to access the database. If `/a/LocalSettings.php` is exist, this will be ignored.

## Restoring a wiki from backup

```sh
mysql -uDB_USERNAME -pDB_PASSWORD < dump_of_wikidb.sql #DB_USERNAME과 DB_PASSWORD
# Replace DB_USERNAME and DB_PASSWORD with actual values
mysql -uDB_USERNAME -pDB_PASSWORD < dump_of_wikidb.sql
```

이후 필요에 따라 [rebuildall.php](https://www.mediawiki.org/wiki/Manual:Rebuildall.php)와 같은 스크립트를 실행합니다.

Run [rebuildall.php](https://www.mediawiki.org/wiki/Manual:Rebuildall.php) script.
See [Restoring a wiki from backup](https://www.mediawiki.org/wiki/Manual:Restoring_a_wiki_from_backup) for details.

&nbsp;

--------
---

The source code of *backupbot* is primarily distributed under the terms of
The source code of _backupbot_ is primarily distributed under the terms of
the [GNU Affero General Public License v3.0] or any later version. See
[COPYRIGHT] for details.

[Docker Badge]: https://badgen.net/badge/icon/docker?icon=docker&label
[Docker Hub]: https://github.com/orgs/femiwiki/packages/container/backupbot
[MySQL]: https://www.mysql.com/
[AWS S3]: https://aws.amazon.com/s3/
[페미위키]: https://femiwiki.com
[GNU Affero General Public License v3.0]: LICENSE
[COPYRIGHT]: COPYRIGHT
[docker badge]: https://badgen.net/badge/icon/docker?icon=docker&label
[docker hub]: https://github.com/orgs/femiwiki/packages/container/backupbot
[mysql]: https://www.mysql.com/
[mediawiki]: https://www.mediawiki.org/
[femiwiki]: https://femiwiki.com
[localsettings.php]: https://www.mediawiki.org/wiki/Manual:LocalSettings.php
[aws s3]: https://aws.amazon.com/s3/
[gnu affero general public license v3.0]: LICENSE
[copyright]: COPYRIGHT
2 changes: 1 addition & 1 deletion crontab
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0 6 * * * /a/do-backup >> /tmp/log 2>&1
0 6 * * * /usr/local/bin/do-backup >> /tmp/log 2>&1
9 changes: 8 additions & 1 deletion docker-cmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#!/bin/bash
set -euo pipefail; IFS=$'\n\t'

cat <<EOF >~/.my.cnf
if [ -f /a/LocalSettings.php ]; then
DB_USERNAME="$(php -r 'require "/a/LocalSettings.php"; echo $wgDBuser;')"
DB_PASSWORD="$(php -r 'require "/a/LocalSettings.php"; echo $wgDBpassword;')"
fi

echo "Use $DB_USERNAME user"

cat <<EOF >/root/.my.cnf
[mysqldump]
protocol=TCP
user=$DB_USERNAME
Expand Down

0 comments on commit 549fc66

Please sign in to comment.