Manual:Backing up a wiki/Lanthanis backup CMD

From MediaWiki.org
Jump to navigation Jump to search
Other languages:
Deutsch • ‎English • ‎日本語

How it works

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.

This batch needs administrator privileges in order to fulfill it's task!

Parameters / Variables

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

 1 @echo off
 2 CLS
 3 :: VARIABLES
 4 SET /A maxBackups=4
 5 SET backupFileName=WIKIBACKUP
 6 SET pathPHP="C:\Program Files\PHP\v7.1\php.exe"
 7 SET pathZ7="C:\Program Files\7-Zip\7z.exe"
 8 SET pathMYSQLDUMP="C:\Program Files\MySQL\Server 5.7\bin\mysqldump.exe"
 9 SET pathWIKIROOT=C:\inetpub\wwwroot\wiki
10 SET pathBACKUP=<PATH TO BACKUP DIRECTORY>
11 SET pathDUMP="%pathWIKIROOT%\maintenance\dumpBackup.php"
12 SET pathWORK=%pathBACKUP%\WORK
13 SET fileList=%pathBACKUP%\CMDs\fileList.txt
14 SET dbUSER=<YOUR DB USER>
15 SET dbPASSWORD=<YOUR DB USERS PASSWORD>
16 SET databaseName=<YOUR WIKI DATABASE NAME>
17 SETLOCAL enabledelayedexpansion
18 
19 :: CHECK PHP
20 IF NOT EXIST %pathPHP% (
21   ECHO PHP can't be located at %pathPHP%
22   goto :END
23 )
24 
25 :: CHECK DUMP PATH
26 IF NOT EXIST %pathDUMP% (
27   ECHO [%date% - %time:~0,8%] - %pathDUMP% file does not exist
28   GOTO :END
29 )
30 
31 :: CHECK WORK PATH
32 IF NOT EXIST %pathWORK% (
33   ECHO [%date% - %time:~0,8%] - %pathWORK% path does not exist
34   GOTO :END
35 )
36 
37 :: CHECK 7-zip
38 IF NOT EXIST %pathZ7% (
39   ECHO [%date% - %time:~0,8%] - 7-zip can't be located at %pathZ7%
40   GOTO :END
41 )
42 
43 :: CHECK mysqldump
44 IF not exist %pathMYSQLDUMP% (
45   ECHO [%date% - %time:~0,8%] - mysqldump can't be located at %pathMYSQLDUMP%
46   GOTO :END
47 )
48 
49 %pathMYSQLDUMP% --verbose --quick --opt -C -e -u %dbUSER% -p %dbPASSWORD% %databaseName% ldap_domains user > "%pathWORK%\LDAPandUSER_WIKI.sql"
50 IF %errorlevel% neq 0 GOTO :END
51 ECHO.
52 
53 :: CREATING XML DUMP FILE (WIKI)
54 ECHO [%date% - %time:~0,8%] - Creating XML Dump file...
55 %pathPHP% -d error_reporting=E_ERROR %pathDUMP% --current --filter=namespace:0,2,4,6,8,10,12,14 > "%pathWORK%\currentBackUp.xml"
56 IF %errorlevel% neq 0 GOTO :END
57 ECHO [%date% - %time:~0,8%] - XML Dump file done! [%pathWORK%\currentBackUp.xml]
58 
59 :: ADD LAST SEQUENCE NUMBER TO ZIP
60 SET /A lastSequenceNumber=0
61 FOR /F "tokens=2 delims=-." %%A IN ('DIR /B "%pathBACKUP%\%backupFileName%-*.zip"') DO IF %%A gtr !lastSequenceNumber! SET /A lastSequenceNumber=%%A
62 SET /A lastSequenceNumber=%lastSequenceNumber%+1
63 
64 :: COMPRESS BACKUP (ZIP)
65 ECHO [%date% - %time:~0,8%] - Creating zip file...
66 ECHO.
67 CALL %pathZ7% a -tzip "%pathBACKUP%\%backupFileName%-%lastSequenceNumber%.zip" @%fileList%
68 IF %errorlevel% neq 0 IF %errorlevel% neq 1 GOTO :END
69 ECHO.
70 ECHO [%date% - %time:~0,8%] - Zip file done! ["%pathBACKUP%\%backupFileName%-%lastSequenceNumber%.zip"]
71 ECHO.
72 
73 :: DELETE OBSOLETE ZIP FILES
74 
75 IF %maxBackups% gtr 0 (
76   ECHO [%date% - %time:~0,8%] - Deleting obsolete files...
77   SET /A max=%lastSequenceNumber%-%maxBackups%
78   FOR /L %%B IN (!max!,-1,1) DO (
79     IF EXIST "%pathBACKUP%\%backupFileName%-%%B.zip" (
80       ECHO [%date% - %time:~0,8%] - Deleting %pathBACKUP%\%backupFileName%-%%B.zip.
81       DEL /Q /F "%pathBACKUP%\%backupFileName%-%%B.zip"
82     )
83   )
84   ECHO [%date% - %time:~0,8%] - Deletion done
85 )
86 
87 GOTO :END
88 
89 :END
90 ECHO.
91 ECHO [%date% - %time:~0,8%] - END BACKING UP WIKI

Further folders or files to be saved - fileList

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.

1 "<WORK DIRECTORY PATH>\currentBackUp.xml"
2 "<WORK DIRECTORY PATH>\LDAPandUSER_WIKI.sql"
3 "<ROOT DIRECTORY MEDIAWIKI>\LocalSettings.php"
4 "<ROOT DIRECTORY MEDIAWIKI>\images"
5 "<ROOT DIRECTORY MEDIAWIKI>\extensions"

Disclaimer

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.