Manual:Backing up a wiki/Lanthanis backup CMD
How it works
[edit]This batch code will export all pages of specified namespaces in an xml dump file, it will dump ldap users and domains as well as all specified files and folders in the fileList
.
Automatically all obsolete backup files will be deleted after executing this backup script.
It checks if excutables are reachable and therefore existing. Furthermore it dumps (in this example only the ldap domain and user table) your wiki database and creates a xml dump of your wiki.
You can specify the namespaces of pages you want to save in line 54.--filter=namespace:0,2,4,6,8,10,12,14
Afterwards it counts up the sequence number and uses 7-Zip to compress all files and folders specified in the fileList
and saves the zip file to the specified backup path with the specified file name.
You can add all folders and files you want to save and backup to the fileList
.
If there are more backup files than your specified maximum amount of backups, it deletes the obsolete ones.
In order to compress the files you want to backup a work directory is recommended. pathWORK
Since the actual pages are exported by the xml dump, there is no need to dump these form the database.
However to save user accounts and data it is recommended to dump specific wiki database tables - change line 48 for this.
Parameters / Variables
[edit]Parameter / Variable | Description |
---|---|
maxBackups
|
Maximum amount of backups |
backupFileName
|
Name of backup file |
pathPHP
|
Path to PHP executable |
pathZ7
|
Path to 7-Zip executable |
pathMYSQLDUMP
|
Path to mysqldump executable |
pathWIKIROOT
|
Path to root directory of your wiki |
pathBACKUP
|
Path to directory you want to save your compressed backup to |
pathDUMP
|
SQL dump file of your wiki |
pathWORK
|
Path to directory you want to save files to compress and backup them |
fileList
|
File containing all files to compress and backup |
dbUSER
|
Username of database user with exporting privilege |
dbPASSWORD
|
Password of specified database user |
databaseName
|
Name of the wiki database |
Code
[edit]@echo off
CLS
:: VARIABLES
SET /A maxBackups=4
SET backupFileName=WIKIBACKUP
SET pathPHP="C:\Program Files\PHP\v7.1\php.exe"
SET pathZ7="C:\Program Files\7-Zip\7z.exe"
SET pathMYSQLDUMP="C:\Program Files\MySQL\Server 5.7\bin\mysqldump.exe"
SET pathWIKIROOT=C:\inetpub\wwwroot\wiki
SET pathBACKUP=<PATH TO BACKUP DIRECTORY>
SET pathDUMP="%pathWIKIROOT%\maintenance\dumpBackup.php"
SET pathWORK=%pathBACKUP%\WORK
SET fileList=%pathBACKUP%\CMDs\fileList.txt
SET dbUSER=<YOUR DB USER>
SET dbPASSWORD=<YOUR DB USERS PASSWORD>
SET databaseName=<YOUR WIKI DATABASE NAME>
SETLOCAL enabledelayedexpansion
:: CHECK PHP
IF NOT EXIST %pathPHP% (
ECHO PHP can't be located at %pathPHP%
goto :END
)
:: CHECK DUMP PATH
IF NOT EXIST %pathDUMP% (
ECHO [%date% - %time:~0,8%] - %pathDUMP% file does not exist
GOTO :END
)
:: CHECK WORK PATH
IF NOT EXIST %pathWORK% (
ECHO [%date% - %time:~0,8%] - %pathWORK% path does not exist
GOTO :END
)
:: CHECK 7-zip
IF NOT EXIST %pathZ7% (
ECHO [%date% - %time:~0,8%] - 7-zip can't be located at %pathZ7%
GOTO :END
)
:: CHECK mysqldump
IF not exist %pathMYSQLDUMP% (
ECHO [%date% - %time:~0,8%] - mysqldump can't be located at %pathMYSQLDUMP%
GOTO :END
)
%pathMYSQLDUMP% --verbose --quick --opt -C -e -u %dbUSER% -p %dbPASSWORD% %databaseName% ldap_domains user > "%pathWORK%\LDAPandUSER_WIKI.sql"
IF %errorlevel% neq 0 GOTO :END
ECHO.
:: CREATING XML DUMP FILE (WIKI)
ECHO [%date% - %time:~0,8%] - Creating XML Dump file...
%pathPHP% -d error_reporting=E_ERROR %pathDUMP% --current --filter=namespace:0,2,4,6,8,10,12,14 > "%pathWORK%\currentBackUp.xml"
IF %errorlevel% neq 0 GOTO :END
ECHO [%date% - %time:~0,8%] - XML Dump file done! [%pathWORK%\currentBackUp.xml]
:: ADD LAST SEQUENCE NUMBER TO ZIP
SET /A lastSequenceNumber=0
FOR /F "tokens=2 delims=-." %%A IN ('DIR /B "%pathBACKUP%\%backupFileName%-*.zip"') DO IF %%A gtr !lastSequenceNumber! SET /A lastSequenceNumber=%%A
SET /A lastSequenceNumber=%lastSequenceNumber%+1
:: COMPRESS BACKUP (ZIP)
ECHO [%date% - %time:~0,8%] - Creating zip file...
ECHO.
CALL %pathZ7% a -tzip "%pathBACKUP%\%backupFileName%-%lastSequenceNumber%.zip" @%fileList%
IF %errorlevel% neq 0 IF %errorlevel% neq 1 GOTO :END
ECHO.
ECHO [%date% - %time:~0,8%] - Zip file done! ["%pathBACKUP%\%backupFileName%-%lastSequenceNumber%.zip"]
ECHO.
:: DELETE OBSOLETE ZIP FILES
IF %maxBackups% gtr 0 (
ECHO [%date% - %time:~0,8%] - Deleting obsolete files...
SET /A max=%lastSequenceNumber%-%maxBackups%
FOR /L %%B IN (!max!,-1,1) DO (
IF EXIST "%pathBACKUP%\%backupFileName%-%%B.zip" (
ECHO [%date% - %time:~0,8%] - Deleting %pathBACKUP%\%backupFileName%-%%B.zip.
DEL /Q /F "%pathBACKUP%\%backupFileName%-%%B.zip"
)
)
ECHO [%date% - %time:~0,8%] - Deletion done
)
GOTO :END
:END
ECHO.
ECHO [%date% - %time:~0,8%] - END BACKING UP WIKI
Further folders or files to be saved - fileList
[edit]All files and folders to add to the backup zip file are specified here.
It needs to contain at least the xml dump file. If you dump something from the database you need to specify the database dump file too.
7-Zip uses this list to aggregate all files and folders to compress and therefore to backup. The following is an example and the first specified path is a necessity.
"<WORK DIRECTORY PATH>\currentBackUp.xml"
"<WORK DIRECTORY PATH>\LDAPandUSER_WIKI.sql"
"<ROOT DIRECTORY MEDIAWIKI>\LocalSettings.php"
"<ROOT DIRECTORY MEDIAWIKI>\images"
"<ROOT DIRECTORY MEDIAWIKI>\extensions"
Disclaimer
[edit]This batch code should be used for Windows only. It is based on Darizotas Windows backup script but was strongly modified.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Therefore use this software on your own risk.