User talk:Flominator/Backup MW

From mediawiki.org
Latest comment: 14 years ago by Fuss in topic Adjusted script

Hi i adjusted the script it does the same, but without storing sensitive data like user name and password in files. Also the backup directory name is not guessable. Otherwise one could steal a site, data and files. This script gets the username and password from the LocalSettings.php. Have a look at: (UNIX only)

FNAME="`date +%Y-%m-%d`"
DATABASE="`cat LocalSettings.php | grep DBname | cut -d '"' -f 2`" ; DATABASE="`echo -ne $DATABASE`"
USER="`cat LocalSettings.php | grep DBuser | cut -d '"' -f 2`" ; USER="`echo -ne $USER`"
PASSWORD="`cat LocalSettings.php | grep DBpassword | cut -d '"' -f 2`" ; PASSWORD="`echo -ne $PASSWORD`"
read -p '\:\: press enter to backup wiki'
mysqldump --database ${DATABASE} -u ${USER} -p${PASSWORD} --add-drop-table -B > ${FNAME}.sql
zip -r ./backup38790123407657811340987589023457890673849/${FNAME}.zip images/ ${FNAME}.sql LocalSettings.php extensions/
rm ${FNAME}.sql
  • This is the symbol for the questions.

  • Where do I put the files "backup.sh", "backup.php", and "import.bat"?

--76.65.3.213 05:08, 7 October 2008 (UTC)Reply

Good question. In the root folder of your MediaWiki installation. --Flominator 14:31, 7 October 2008 (UTC)Reply
Thank you! --76.65.3.213 23:11, 7 October 2008 (UTC)Reply
  • My backup.php doesn't create the file properly. I verified that my backup.sh works independently. Here is the code for my backup.php:
 <?php
 exec("./backup.sh");
 $filename = strftime("%y-%m-%d");
 header("Content-Type: application/octet-stream");
 header("Content-Disposition: attachment; filename=WIKINAME_".$filename.'.zip');
 echo readfile("backup/".$filename.".zip");
 ?>

When I execute the above www.mydomain.com/backup.php it prompts me to save a file that is only a few bytes in size. Both my backup.php and backup.sh are located in the root directory of my Mediawiki installation. I also have a "backup" directory in the root directory.


yes, the database is included and the files LocalSettings.php and the ones in extensions and images. --Flominator 06:58, 8 October 2008 (UTC)Reply
Thanks. ^_^ By the way, can anyone access the backup.php can do a backup? --76.69.137.242 03:21, 9 October 2008 (UTC)Reply
Depends on your configuration, but usually - yes. --Flominator 07:51, 9 October 2008 (UTC)Reply
Can they access the zip file also? --76.65.3.32 02:57, 16 October 2008 (UTC)Reply
If it is created below the Document Root (which the script does) - yes. --Flominator 13:56, 16 October 2008 (UTC)Reply
  • Not sure if the no space in the -p switch is a typo. :/

"-u $USER -p$PASSWORD"

No, I think it isn't. --Flominator 11:38, 12 October 2008 (UTC)Reply
  • having problems with the paths in localsettings.php when imported to windows xampp. it does not look like your script takes care of the linux references to files and extensions. am i missing something? Siliconsoul 17:31, 4 January 2010 (UTC)Reply

Adjusted script[edit]

The script didn't work for me and I found the remove if > 5 to be too dangerous. Here is the new one:

#!/bin/bash
DATABASE_NAME=(yourdbname)
USERNAME=(yourusername)
PASSWORD=(yourpassword)
FNAME=wikibackup-`date +%y-%m-%d-%m-%s`
mysqldump --database $DATABASE_NAME -u $USERNAME -p$PASSWORD --add-drop-table -B > ${FNAME}.sql
zip -r ./backup/${FNAME}.zip images/ ${FNAME}.sql LocalSettings.php extensions/ -x  backup/
rm ${FNAME}.sql

# Keep only five backup files

#Count files in directory (hidden files (filename starts with a dot) are ignored)
file_count=`ls backup/*.zip | wc -l`

#Do until there are more than or equal 6 files present
while [ $file_count -ge 6 ]
do
        #you can save deleted filenames in variable (e.g. for deleting files also in backup directory)
        #not recommended for filenames with space(s)
        del_files="${del_files} `ls backup/*.zip | head -n 1`"
        #Delete alphabetically oldest file (ls sort by name is default)
        rm `ls backup/*.zip | head -n 1`
        #Count files again
        file_count=`ls backup/*.zip | wc -l`
done

Fuss 23:16, 28 February 2010 (UTC)Reply