User talk:Flominator/Backup MW

Jump to navigation Jump to search

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.php", and "import.bat"?

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

Good question. In the root folder of your MediaWiki installation. --Flominator 14:31, 7 October 2008 (UTC)
Thank you! -- 23:11, 7 October 2008 (UTC)
  • My backup.php doesn't create the file properly. I verified that my works independently. Here is the code for my backup.php:
 $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 it prompts me to save a file that is only a few bytes in size. Both my backup.php and are located in the root directory of my Mediawiki installation. I also have a "backup" directory in the root directory.

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


No, I think it isn't. --Flominator 11:38, 12 October 2008 (UTC)
  • 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)

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:

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 ]
        #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`

Fuss 23:16, 28 February 2010 (UTC)