From 549fc66563b04e8eb0e8d6cb3640997c0300f5c0 Mon Sep 17 00:00:00 2001 From: lens0021 Date: Fri, 2 Apr 2021 09:43:33 +0900 Subject: [PATCH] Read credentials from a php file if provided to simplify a cluster setting. Related to https://github.com/femiwiki/femiwiki/issues/230 --- Dockerfile | 7 +++++-- README.md | 52 +++++++++++++++++++++++++++++++++------------------- crontab | 2 +- docker-cmd | 9 ++++++++- 4 files changed, 47 insertions(+), 23 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6b86f53..2f65039 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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"] diff --git a/README.md b/README.md index 75e5613..ab1e1d3 100644 --- a/README.md +++ b/README.md @@ -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.   --------- +--- -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 diff --git a/crontab b/crontab index 941dfa4..c393fa5 100644 --- a/crontab +++ b/crontab @@ -1 +1 @@ -0 6 * * * /a/do-backup >> /tmp/log 2>&1 +0 6 * * * /usr/local/bin/do-backup >> /tmp/log 2>&1 diff --git a/docker-cmd b/docker-cmd index 0c5061b..a9cbaa8 100755 --- a/docker-cmd +++ b/docker-cmd @@ -1,7 +1,14 @@ #!/bin/bash set -euo pipefail; IFS=$'\n\t' -cat <~/.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 </root/.my.cnf [mysqldump] protocol=TCP user=$DB_USERNAME