User:Flominator/Backup MW

The following combination of scripts I used in order to backup a MediaWiki from a linux machine and to copy it to a windows machine running XAMPP.

backup.sh
This file packs a database dump, the contents of the folders images and extensions and LocalSettings.php into a zip file name with todays date.

mysqldump --database DATABASE_NAME -u USERNAME -pPASSWORD --add-drop-table -B > `date +%y-%m-%d`.sql zip -r ./backup/`date +%y-%m-%d`.zip images/ `date +%y-%m-%d`.sql LocalSettings.php extensions/ -x ackup/ rm `date +%y-%m-%d`.sql
 * 1) !/bin/bash

Bonus (not required): Keep only five backup files file_count=`ls -1A | wc -l` while [ $file_count -ge 6 ] do 	#Delete alphabetically oldest file rm `ls -1Ar | tail -1` #Count files again file_count=`ls -1A | wc -l` done
 * 1) Count files in directory
 * 1) Do until there are less than 6 files present

backup.php
This file creates a backup using backup.sh and enables the user to download the backup via http.sh.



import.bat
This file is used to import the wiki at the windows machine. Just drag the file downloaded from backup.php on a link to import.bat or start it with import FILENAME.

@echo off echo Copy %1 to C:\xampp\htdocs\wikifolder\temp\ copy %1 C:\xampp\htdocs\wikifolder\temp\ c: cd C:\xampp\htdocs\wikifolder\ echo Delete old folder images rd /s /q images echo Delete old folder extensions rd /s /q extensions echo Unzipping file by using unzip cd temp FOR /F "delims=!" %%n in ('dir *.zip /b') DO (unzip -o %%n -d "C:\xampp\htdocs\wikifolder" del %%n ) cd.. echo Delete old database C:\xampp\mysql\bin\mysql -u USERNAME -pPASSWORD -e "drop database DATABASE_NAME;" echo Create databse C:\xampp\mysql\bin\mysql -u USERNAME -pPASSWORD -e "create database DATABASE_NAME;" FOR /F "delims=!" %%m in ('dir *.sql /b') DO (echo Importing from %%m C:\xampp\mysql\bin\mysql -u USERNAME -pPASSWORD -D DATABASE_NAME < %%m del %%m ) pause

Warning: Make sure that there are no other ZIP or SQL files withing the root directory of the wiki

If you have broken imagelinks and are not able to create thumbnails afterwards, simply edit LocalSettings.php and set: $wgHashedUploadDirectory = true;