Last active
August 18, 2017 10:20
-
-
Save marcus-crane/0bb9885e30a986156c7004f08884f5ed to your computer and use it in GitHub Desktop.
A mediawiki backup script
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/bash | |
# Slight modification of https://www.mediawiki.org/wiki/Fullsitebackup | |
# Configuration | |
dbname="yourdb" | |
dbhost="localhost" | |
dbuser="username" | |
dbpw="password" | |
# Wiki location | |
wikidir="/var/www/wiki" | |
# Variables | |
tarnamebase=wikibackup- | |
datestamp=`date +'%d-%m-%Y'` | |
# Script starting directory | |
startdir=`pwd` | |
logfile=$HOME/scripts/backups/$datestamp".log" | |
# TMP dir | |
tempdir=$datestamp | |
# Check for inputs | |
if test "$1" = "" | |
then | |
tarname=$tarnamebase$datestamp.tgz | |
else | |
tarname=$1 | |
fi | |
# Begin logging | |
echo "Starting the wiki backup" > $logfile | |
# Create a TMP working directory | |
echo "Creating TMP working directory..." >> $logfile | |
mkdir $tempdir | |
# TAR wiki files | |
echo "TARing wiki into $webrootdir ..." >> $logfile | |
cd $wikidir | |
echo "Dumping XML content while we're here..." >> $logfile | |
php maintenance/dumpBackup.php --full --quiet > dump.xml | |
echo "Generated wiki XML backup..." | |
tar cf $startdir/$tempdir/filecontent.tar . | |
echo "Backed up wiki content..." | |
# sqldump db info | |
echo "Dumping wiki database, using ..." >> $logfile | |
echo "user:$dbuser; database:$dbname host:$dbhost " >> $logfile | |
cd $startdir/$tempdir | |
mysqldump --user=$dbuser --password=$dbpw --add-drop-table $dbname > dbcontent.sql | |
echo "Backed up mysql content.." | |
# Create final backup file | |
echo "Compressing it all into one neat package..." | |
echo "Creating final compressed (tgz) TAR file: $tarname ..." >> $logfile | |
tar czf $startdir/$tarname filecontent.tar dbcontent.sql | |
# Cleanup | |
echo "Removing temp dir $tempdir ..." >> $logfile | |
cd $startdir | |
rm -r $tempdir | |
mv $tarname $HOME/scripts/backups/$tarname | |
# Exit banner | |
endtime=`date` | |
echo "See ya!" | |
echo "Backup completed $endtime, TAR file at $tarname. " >> $logfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script is based on a Mediawiki install backed by MariaDB for reference.
MySQL is identical as they use the same tools but all you should really need to do for Postgres is swap out
mysqldump --user=$dbuser --password=$dbpw --add-drop-table $dbname > dbcontent.sql
for something along the lines ofpgdump $dbname -U $dbuser > dbcontent.sql
I believe it is.Check here for further info on securely storing the password for use with pgdump.