Last active
June 5, 2016 20:11
-
-
Save manoj23/ce03628313e3c6afc705378ffca7f69d to your computer and use it in GitHub Desktop.
mediawiki: backup script of LocalSettings.php and DB into a git repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
mw_var() | |
{ | |
local mw_local_settings=$1 | |
local mw_var=$2 | |
sed -n "s/^\$$mw_var = \"\(.*\)\";/\1/p" $mw_local_settings | |
} | |
mw_backup() | |
{ | |
local mw_root=$1 | |
local mw_name=$(basename $mw_root) | |
local mw_local_settings=$mw_root/LocalSettings.php | |
local mw_local_settings_backup=$(tempfile) | |
local mw_db_type=$(mw_var $mw_local_settings "wgDBtype") | |
local mw_db_server=$(mw_var $mw_local_settings "wgDBserver") | |
local mw_db_name=$(mw_var $mw_local_settings "wgDBname") | |
local mw_db_user=$(mw_var $mw_local_settings "wgDBuser") | |
local mw_db_password=$(mw_var $mw_local_settings "wgDBpassword") | |
local mw_backup_output="/opt/mediawiki-backup/$mw_name" | |
[ "$mw_db_type" != "mysql" ] && echo "$mw_db_type is not supported" && exit 1 | |
[ ! -d "$mw_backup_output" ] && echo "$mw_backup_output directory does not exist" && exit 2 | |
[ ! -d "$mw_backup_output/.git" ] && echo "$mw_backup_output directory is not a git repository" && exit 3 | |
cp -p $mw_local_settings $mw_local_settings_backup | |
cp $mw_local_settings $mw_backup_output | |
echo "\$wgReadOnly = 'Dumping Database, Access will be restored shortly';" >> $mw_local_settings | |
if mysqldump -h $mw_db_server -u $mw_db_user $mw_db_name \ | |
--default-character-set=utf8 > $mw_backup_output/mw-db.sql ; then | |
cd $mw_backup_output | |
local mw_commit_message="$(date --iso-8601) - $(tail -n 1 mw-db.sql)" | |
sed -i '$ d' mw-db.sql | |
git add mw-db.sql LocalSettings.php && git commit -m "$mw_commit_message" | |
cd - | |
else | |
echo "mysqldump failed" | |
fi | |
mv $mw_local_settings_backup $mw_local_settings | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment