Snapshot Module

The snapshot module is a tool for Sahana administrators to use in managing their Sahana database. The reason it is named snapshot is for it's ability to quickly and painlessly make complete database backups and to also restore the database from a previous point in time (from another snapshot). The module itself is by far the most simplistic in terms of its user interface in comparison to other Sahana modules, and it should be fairly straightforward and easy to understand.

UPDATE: 2009:0708 ~ The paths in the documentation here may be a bit confusing. The module will now save backups to /backups and not anymore into /mod/snapshot/backups. The screenshots will “eventually” be updated to reflect this change ;)

1) Snapshot UI

To access the Snapshot module, simply login as an administrator to Sahana and go to the administration section. There you will see a menu item ~ Snapshot, and click in this menu item will bring up the screen above. Let's first talk about what this information is. The screen is broken down into 3 horizontal sections, the first being a Log Window, the second being a table of information about what backups we have in our system (this table will be empty if you have not made any backups yet), and the final horizontal section presents a single button.

2) Creating a new Snapshot (Database Backup)

To create a new Snapshot (backup of the database), click on the button in the 3rd section “Create a new Snapshot”. This operation may take a few seconds to minutes depending on the size of your database. If your database is small ~ 2-10MB, then the backup should complete in a few seconds. You will notice that as soon as you press the button, it greays itself out, and a note is added to the log “Creating a new Snapshot…” and will then be followedd by “Snapshot created: databaseName@date_time.sql. At this point, you have successfully backed up your database.

3) Renaming a Snapshot

Initially, when a new Snapshot is created, it will be named in the form ~ databaseName@date_time.sql. This may be to your liking our it may not. If you would like to rename the snapshot to something else, you simply click on the rename button on the row of the Snapshot you wish to rename. At this point, a dialog box will appear asking you to enter a new filename for the Snapshot. Fear not if you remove the .sql from the filename, the backend script will notice this, and re-append it for you.

4) Restoring a Snapshot (Database Restore)

Restoring a Snapshot it the process of truncating the current database and essentially replacing it completely with a Snapshot. This can be useful if your database has become corrupted, if you would like to roll back to a previous set of data, or for any other number of reasons. Luckily, this process is trivially easy to accomplish, you simply click on the Restore link for the Snapshot you would liek to restore from. The Log window will be updated with some text “Restoring Snapshot…” and the snapshot window will dim. Here again, if you have a rather large database, this step will take some time to process. After the database has been restored, the log will be again appending letting you know the Restore process is complete.

5) Deleting a Snapshot

Deleting an old Snapshot may become necessary if you have a lot of old Snapshots stored to reclaim some drive space. Here, you simply click on the Delete link next to the Snapshot you wish to delete and then you are prompted with a confirmation dialog so that you don't accidentally Delete a Snapshot. Confirm Yes, and your Snapshot will disappear, gone forever…

6) The Snapshot Storage Folder

The Snapshot storage folder is the location where the Snapshot module will store the .sql files from the backups it creates. The location of this folder is /mod/snapshot/backups, relative to the Sahana root. However, if the backups folder is not present, you will see the error message below and will be prompted to fix the situation. You can then click on “Check Again” to reload the page and proceed.

7) The Snapshot Storage Folder II

As with the previous step point above, if the backups/ folder has the incorrect permissions and is not writeable buy the Webserver user, then the following error message will occur. If the Snapshot module cannot write to this location, it cannot create Snapshots. So set the folder to have the correct write permissions and then proceed to use Snapshot for all your Sahana database backup needs!

8) Setting up a cron job to automate database backups

1) Edit the crontab on your system with the command crontab -e
2) Add a line like this:
0 0 * * * cd ~/public_html/sahana-phase2/mod/snap/ ; /usr/local/bin/php crontask.php » stdout.log 2» stderr.log ;
3) Sit back, relax and enjoy your automated Sahana database backups :)

QR Code
QR Code doc:snapshot:english (generated for current page)