MindTouch Developer Center > Deki > User Manual > Backing up your MindTouch Deki

Backing up your MindTouch Deki involves three steps: backing up your database, your file attachments, and your config files.

During the evolution of MindTouch Deki certain directory names, file names and locations may have changed.  For instance, versions earlier than 1.9.0 used the default path of/var/www/deki-hayes for the Deki installation while versions from and after 1.9.0 use the default path of /var/www/dekiwiki.  Note which version of Deki you are using and understand that you may need to modify the instructions given on this page accordingly.

Backing up your database

You can do this from command line by issuing the following command:

mysqldump -udbusername -p db_name > db_name.sql 

Note:  If you have a multi-tenant installation of Deki you have multiple databases and need to backup each database separately.

Backing up your attachments

cd /path/to/wiki/;
tar cvzpf attachments.tar.gz attachments

Backup config files

Copy the following files: 

  • /var/www/deki-hayes/LocalSettings.php
  • /var/www/deki-hayes/AdminSettings.php (if it exists - typically on older Deki Wikis)
  • /etc/dekiwiki/mindtouch.deki.startup.xml

Restoring your database

mysql -udbusername -p db_name < db_name.sql

Note:  If you have a multi-tenant installation of Deki you have multiple databases and need to restore each database separately.

Restoring your attachments

cd /path/to/wiki/;
tar xvzpf attachments.tar.gz

Using Crontab for automated backups

The following is an example of automated backups. This assumes that /mnt/hgfs/BackupWiki is available to dump backups to outside the VM image (e.g. a directory on another disk) and the result is 7 daily backups a week tagged by day (e.g. Thu.attachments-backup.tar.gz and Thu.wikidb-backup.sql). (Note: it would be nice for someone to document how to do this via SCP,FTP or rsync for those that don't have mnt/hgfs/BackupWiki configured).

The backup_script

#!/bin/bash
today="$(date +%a)"
#dump today's database
mysqldump -u root -ppassword wikidb  > /mnt/hgfs/BackupWiki/$today.wikidb-backup.sql

#dump today's attachments
cd /var/www/deki-hayes/
tar czf /mnt/hgfs/BackupWiki/$today.attachments-backup.tar.gz attachments

The script above creates files with a name like "Sun.wikidb-backup.sql". i,.e. only the day of the week is prepended to the backup name. You can format the date any way you like. Type man date at the command prompt to see all formatting possibilities (begin with %).

A useful one is

today="$(date + %Y-%m-%d)"

whch results in files like "2008-01-25.wikidb-backup.sql"

Make a cron job ("crontab -e" to create and edit) to run the script automatically.

 The script below runs the backup_script  daily at 4 am.

# m h  dom mon dow   command
0 04 * * *      sh $PATH_TO_YOUR_SCRIPT/backup_script > /var/tmp/dekiwiki.backup.log 2>&1

 NOTE:  Alternatives to the sh in the above command are bash, ksh or csh depending upon the shell that you are using. You may also precede the backup_script with a simple ". " (dot) to execute the shell script. In order to execute the backup command without the above sh or equivalent you give backup_script execute permission with the command "chmod 700 backup_script".

The 2>&1 in the above crontab command redirects errors in executing the command to the /var/tmp/dekiwiki.backup.log which you should review for errors which may keep you backup from completing successfully. Always verify that that the crontab backup has run as specified to ensure that you have valid backups of your database and attachments. 

Tag page
Viewing 15 of 19 comments: view all
Here are a couple of tips that might help others:

1. I had to make backup_script executable before the cron job would run. You may also want to prevent other users from having read access the file since it stores a password. The following command will accomplish both:
chmod 700 backup_script

2. If you want the database backup to be compressed, you can use the following command (or the bzip equivalent):
mysqldump -u dbusername -pdbpassword db_name | gzip -c > db_name.sql.gz
Posted 02:44, 7 Nov 2007
Ok this is great for creating back-ups but now restoring them on a new Deki-Hayes VM.

Can we add steps on how to do this, since it is different from upgrading from gooseberry to hayes.

Thanks Intnenet Scooter and mhenry07 for the extra pointers! (-:
edited 04:33, 7 Nov 2007
Posted 04:32, 7 Nov 2007
internetscooter.. I use the vm deki-hayes but $HOME did not work.
Posted 04:34, 7 Nov 2007
Petrus4, another way to check $HOME is by typing "echo $HOME". Ours is set to /root rather than /home.
Posted 04:26, 8 Nov 2007
darace on the DekiWiki forums provided this list of steps that he had to use to restore his wiki:

* download and start a new virtual machine
* go through the initial setup in your browser
* make sure you have a way of accessing the file system of the virtual machine (howto here (http://wiki.opengarden.org/Deki_Wiki/FAQ/Configuration/How_do_I...Access_Deki_Wiki_through_windows_Explorer%3f))
* go to the directory /var/www/deki-hayes and copy the file LocalSettings.php to your workstation
* open the mysql dump file with an editor and look for the phrase *'security/api-key'*. Replace the key found here (from the previous wiki installation) with the one you can find in the current */var/www/LocalSettings.php* file (listed as *$wgDekiApiKey*)
* log on as root to the console (default password = 'password')
* delete the current (empty) wiki database which is called wikidb with the following command: *mysql -uroot -ppassword -e "drop database wikidb"*
* create a new empty database: *mysql -uroot -ppassword -e "create database wikidb"*
* import the dump into the new database: *mysql -uroot -ppassword wikidb < wikidb.sql*
* change directory by typing the command: *cd /var/www/deki-hayes/maintenance*
* run *php update-db.php* in order to restore the stored procedures needed by deki wiki

R0yk3 provided another backup method that uses a backup agent running on the VMware Server host. You
back up a virtual machine by suspending and resuming it with batch files containing
vmware-cmd commands. Suspending a virtual machine puts it in a state in which the
host backup software can gain exclusive access to the virtual machine files to complete
its task.
To backup a virtual machine directory using a backup agent
1 Add the following line to your suspend batch file:
vmware-cmd <path_to_config>\<config>.vmx suspend
2 Once the virtual machine is suspended, you can safely back up this virtual
machineʹs directory using the backup agent installed on the VMware Server host.
3 After the backup job completes, run a resume batch job to restart the virtual
machine.
The batch file should contain the following line:
vmware-cmd <path_to_config>\<config>.vmx start
This command resumes the virtual machine into an active, running state.
! If you want to restore a virtual machine to a server other than the VMware Server
host where it was originally located, shut down the virtual machine. Instead of
using the suspend batch file, use one that powers off the virtual machine.
vmware-cmd <path_to_config>\<config>.vmx stop
! The suspend, stop, and resume commands can be used in pre‐ and post‐job scripts
that are normally available via the backup software being used. Backup software
such as Veritas Backup Exec has the capability to run pre‐ and post‐batch jobs with
scheduled backups. edited 20:33, 14 Nov 2007
Posted 18:29, 14 Nov 2007
Instead of full backup the MySQL data and attachment data, is there any easy way to incremental backup them? A cron job would be even better. Thanks.
Posted 15:34, 16 Nov 2007
When attempting to make a backup of the MySQL db (In the VM distribution), I get the following error:

mysqldump: Got error: 1044: Access denied for user 'wikiuser'@'localhost' to database 'wikidb' when using LOCK TABLES

Apparently the generic 'wikiuser' in the VM-provided doesn't have permission to lock the tables for dumping. I also don't know the 'root' password to the MySQL instance in the VM, and 'wikiuser' doesn't have GRANT permission, so I can't fix the permissions.

Any suggestions would be welcome.
Posted 01:51, 5 Jan 2008
I have followed the above instructions for a crontab to backup my database and attachments to: /mnt/hgfs/BackupWiki . I'm trying to understand, is that a folder that exists outside of my vmware machine so that when I write my backups to that location, I'm actually storing them on a different machine (which is what I want). Or do I have to physically move/copy them from /mnt/hgfs/BackupWiki to another machine to have them stored on a different box?
Posted 23:55, 16 Jan 2008
@bighorton: on the VM, the root passwords can be located in /var/www/deki-hayes/AdminSettings.php
Posted 00:21, 17 Jan 2008
In regards to the size of a backup. Has anyone tried this on a large scale? Like say there are a couple million attachments. That's going to take forever and a lot of space. Is there another method for doing this? Can the Wiki handle this type of environment?
Posted 21:14, 25 Jan 2008
#!/bin/bash
# helperscript :)
DB_CATALOG=`cat /etc/dekiwiki/mindtouch.deki.startup.xml |grep '<db-catalog>'|sed 's/.*>\(.*\)<.*/\1/'`
mysqldump -u root -p $DB_CATALOG >$DB_CATALOG.$(date +'%Y%m%d').sql
Posted 13:01, 14 Mar 2008
hi everyone, i am learning how to use deki-wiki and i need some help, i did a back up of my database using mysqldump -u root -p wikidb >res.sql, but when i tried to restore it i had a sintax error in mysql, i did this: mysql -u root -p wikidb < res.sql; you have a error with sql sintax, check your manual that correspond to the version of your mysql....

if any body can help me a really apreciate it.

thanks
Posted 16:11, 18 Mar 2008
Hi everyone, Iam also just learning how to use deki-wiki. Can someone give me instruction on how to back up the deki wiki. Do i need a extrenal drive or can I back up on the same computer where i have instaulled the deki wiki.

Thanks
Posted 20:37, 27 Mar 2008
hi,garbrie184. when restore backup database, you first go into "mysql command line" mode and write "use 'wiki';source 'your path\res.sql'".
Posted 02:49, 17 Apr 2008
I was using the "How do I...Access Deki Wiki through windows Explorer?" method to enable me to edit files in windows using a standard windows text editor. This works fine with php files but as a linux newbie I didn't realise that scripts have to be in UNIX format. Fortunately I was using "NoteTab Light" which gave me the option of saving the file in UNIX format. The script then worked correctly.
Posted 14:40, 29 Sep 2008
Viewing 15 of 19 comments: view all
You must login to post a comment.
Powered by MindTouch Deki v.8.08.1a