LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Backing up MediaWiki 1.16.0 (https://www.linuxquestions.org/questions/linux-software-2/backing-up-mediawiki-1-16-0-a-834296/)

dazdaz 09-24-2010 12:11 PM

Backing up MediaWiki 1.16.0
 
I had a script, see below, which used to work to make a html backup my mediawiki. I just upgraded to 1.16.0 and now it's broke as it won't authenticate, this part must of changed.

Of course I also use mysqldump, but I also like to make a html snapshot of the wiki.

Does anyone know how it's changed to allow authentication once more.

Code:

WIKI_USERNAME=WikiSysop
WIKI_PASSWORD=abcdefgh
TARGETHOST=http://www.myhost.org/wiki

# Save cookie
wget --save-cookies cookies.txt --post-data 'wpName='$WIKI_USERNAME'&wpPassword='$WIKI_PASSWORD'&wpRemember=1&wpLoginattempt=Log%20in' ${TARGETHOST}/index.php\?title=Special:Userlogin\&action=submitlogin\&type=login

# Load cookie
wget --mirror --no-parent --page-requisites --convert-links --no-host-directories --html-extension --cut-dirs=2 --load-cookies cookies.txt --directory-prefix=. ${TARGETHOST}/index.php/Main_Page -P /var/backup-web/html/


alunduil 09-24-2010 02:44 PM

Is it possible for you to provide the error you get while running this script as well?

Regards,

Alunduil

dazdaz 09-25-2010 02:13 PM

I made a typo in the script above which has been corrected.

It's not saving the cookie into the cookies.txt which makes me wonder if the authentication URL has changed with 1.16.0

Here is the first wget with debug (-d). Certain values have been changed for obvious reasons.

Code:

DEBUG output created by Wget 1.10.2 (Red Hat modified) on linux-gnu.

--19:53:03--  http://www.myhost.org/wiki/index.php?title=Special:Userlogin&action=submitlogin&type=login
Resolving www.myhost.org... 102.196.111.15
Caching www.myhost.org => 102.196.111.15
Connecting to www.myhost.org|102.196.111.15|:80... connected.
Created socket 4.
Releasing 0x0808c1b0 (new refcount 1).

---request begin---
POST /wiki/index.php?title=Special:Userlogin&action=submitlogin&type=login HTTP/1.0
User-Agent: Wget/1.10.2 (Red Hat modified)
Accept: */*
Host: www.myhost.org
Connection: Keep-Alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 73

---request end---
[POST data: wpName=WikiSysop&wpPassword=abcdefgh&wpRemember=1&wpLoginattempt=Log%20in]
HTTP request sent, awaiting response...
---response begin---
HTTP/1.0 200 OK
Date: Sat, 25 Sep 2010 18:53:03 GMT
Server: Apache
X-Powered-By: PHP/5.x.x
Set-Cookie: wikidb_mw_bd_session=ak501c3bcjssuh5fbnsae245v8; path=/
Content-Language: en
Vary: Accept-Encoding,Cookie
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Cache-Control: private, must-revalidate, max-age=0
Content-Type: text/html; charset=UTF-8
X-Cache: MISS from www.myhost.org
X-Cache-Lookup: MISS from www.myhost.org:80
Via: 1.0 www.myhost.org:80 (squid/2.x.STABLExx)
Connection: close

---response end---
200 OK
hs->local_file is: index.php?title=Special:Userlogin&action=submitlogin&type=login.3 (not existing)

Stored cookie www.myhost.org -1 (ANY) / <session> <insecure> [expiry none] wikidb_mw_bd_session ak501c3bcjssuh5fbnsae245v8
TEXTHTML is on.
Length: unspecified [text/html]
Saving to: `index.php?title=Special:Userlogin&action=submitlogin&type=login.3'

    0K ..........                                              262M=0s

Closed fd 4
19:53:03 (262 MB/s) - `index.php?title=Special:Userlogin&action=submitlogin&type=login.3' saved [10488]

Saving cookies to cookies.txt.
Done saving cookies.


# cat cookies.txt
# HTTP cookie file.
# Generated by Wget on 2010-09-25 19:53:03.
# Edit at your own risk.


choogendyk 09-26-2010 07:44 PM

This seems like kind of an indirect method of backing up your wiki. How would you picture the recovery process if you needed to use this backup?

Why not use mysqldump or mysqlhotcopy -- http://dev.mysql.com/doc/refman/5.1/...p-methods.html -- and then use gtar, rsync, rdiff-backup or something else to maintain a backup of your webtree and mysqldumps on another server or drive? Although it seems slightly more complex, recovery would be more straightforward.

dazdaz 09-27-2010 11:14 AM

For backup and recovery I use mysqldump. I realised that I had used the wrong wording above which may of misled (sorry)

Using wget in the past has allowed me to view the wiki offline, i.e. on my mobile I can carry the content and view it offline. For me that is extremely useful, especially if you have no data plan or no access to wifi.

You now have to use the wpLoginToken to authenticate via MediaWiki 1.16.0 so that you can download a MediaWiki page using wget inside of a script.

http://labs.creativecommons.org/2011...-to-mediawiki/

I've made some small modification's to the script on the URL above to make it easier to use. This is very handy script....

Code:

#!/bin/bash

PAGE_TITLE="Pad_Thai"

RCPT_TO="carl@gmail.com"
MAIL_FROM="'John Q. Public' <management@somesite.com>"
MAIL_SUBJECT="Contents of ${PAGE_TITLE}"

MW_LOGIN="carl"
MW_PASSWD="XXXXXX"

URL="https://www.chiangmai.com/wiki/index.php"

# Mediawiki uses a login token, and we must have it for this to work.
WP_LOGIN_TOKEN=$(wget -q -O - --save-cookies cookies.txt --keep-session-cookies --no-check-certificate \
                                    ${URL}/Special:UserLogin \
                                    | grep wpLoginToken | grep -o '[a-z0-9]\{32\}')

wget -q --load-cookies cookies.txt --save-cookies cookies.txt --keep-session-cookies --no-check-certificate \
        --post-data "wpName=${MW_LOGIN}&wpPassword=${MW_PASSWD}\
&wpRemember=1&wpLoginattempt=Log%20in&wpLoginToken=${WP_LOGIN_TOKEN}" \
        "${URL}?title=Special:UserLogin&action=submitlogin&type=login"

wget -q -O email_body.txt --no-check-certificate --load-cookies cookies.txt \
        "${URL}/${PAGE_TITLE}?action=raw"

cat email_body.txt | mail -s "${MAIL_SUBJECT}" ${RCPT_TO}



All times are GMT -5. The time now is 09:30 PM.