~u5218464/schooltool-book/schooltool-book

« back to all changes in this revision

Viewing changes to i18n/hi/source/database.rst

  • Committer: Karun Agarwal
  • Date: 2014-05-22 10:02:44 UTC
  • Revision ID: u5218464@anu.edu.au-20140522100244-0lv39nttpudy41cp
added new branch to make translations for schooltool-book to hindi

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Basic Database Administration
 
2
=============================
 
3
 
 
4
Unlike most web applications, SchoolTool does not use a relational database such as MySQL or PostgreSQL.  Instead, it uses ZODB -- the Zope Object Database.  ZODB has some specific characteristics a SchoolTool site manager should be aware of.
 
5
 
 
6
The main drawback to this, from the point of view of a school's systems administrator or programmer, is that you cannot simply directly access data in the form of raw tables.  It has to be done programmatically in Python, either from a module in the main server application, or an external Python script that imports much of SchoolTool's object model.  
 
7
 
 
8
If you have specific needs for data reporting, don't hesitate to contact us. 
 
9
 
 
10
Where is the data?
 
11
------------------
 
12
 
 
13
All the data in a given SchoolTool instance is stored in a file named ``Data.fs``.  On an Ubuntu system this file can be found in the ``/var/lib/schooltool/`` directory.  The additional files in that directory ending with ``.index``, ``.lock``, and ``.tmp`` are all used by the application in various ways, but they `do not` contain any data about your school which is not also included in the main ``Data.fs`` file.  
 
14
 
 
15
Photos, reports, and other binary files are stored outside the ``Data.fs`` database in a ``blobs`` directory.
 
16
 
 
17
Automatic backups
 
18
-----------------
 
19
 
 
20
Whenever SchoolTool is updated to a new version via Ubuntu's update mechanisms, it creates a backup of the current database.  It also compresses and retains previous backups.  The most recent back up in ``/var/lib/schooltool/`` has a ``.0`` appended, like ``schooltool/Data.fs.0``.  Older backups are also gzipped, with increasing numbers as suffixes.  ``schooltool/Data.fs.2.gz`` is older than ``schooltool/Data.fs.1.gz``, for example.
 
21
 
 
22
How do I do a manual backup?
 
23
----------------------------
 
24
 
 
25
While it is possible to do a "hot" backup of SchoolTool's database while the application is running, for the sake of simplicity this document will just cover an offline "cold" backup.
 
26
 
 
27
Basically, just stop the SchoolTool server, copy ``Data.fs`` and the ``blobs`` directory, and restart the server::
 
28
 
 
29
    sudo /etc/init.d/schooltool stop
 
30
    sudo cp /var/lib/schooltool/Data.fs /media/backups/schooltool/Data.fs-$(date +%Y%m%d-%H%M)
 
31
    sudo cp -r /var/lib/schooltool/blobs /media/backups/schooltool/blobs-$(date +%Y%m%d-%H%M)
 
32
    sudo /etc/init.d/schooltool start
 
33
 
 
34
Substitute the actual location of your backup in the place of ``/media/backups``.  The ``date +%Y%m%d-%H%M`` command embedded into the ``cp`` command is a bash command to embed the current date and time into the filename.  That will allow you to keep a bunch of backups by date easily.  Of course, if you've got a more sophisticated backup system than ``cp``, by all means use that!
 
35
 
 
36
Restoring from a backup
 
37
------------------------
 
38
 
 
39
In most cases, if you need to return to a previous automatic database backup, you should stop SchoolTool, rename the current ``Data.fs`` just in case you *do* need it later, remove the ``.0`` from the most recent backup, and restart the server::
 
40
 
 
41
    sudo /etc/init.d/schooltool stop
 
42
    sudo mv /var/lib/schooltool/Data.fs /var/lib/schooltool/Data.fs.bad
 
43
    sudo mv /var/lib/schooltool/Data.fs.0 /var/lib/schooltool/Data.fs
 
44
    sudo /etc/init.d/schooltool start
 
45
 
 
46
If you need to try an even older backup, ungzip it::
 
47
 
 
48
    sudo gunzip /var/lib/schooltool/Data.fs.1.gz 
 
49
 
 
50
The procedure for restoring from a previous manual backup is the same, that is, copy the file to the ``Data.fs`` position, except only you know where it is coming from.
 
51
 
 
52
You will also need to backup and restore the files in the blobs directory using standard archiving tools (zip, tar, etc.).
 
53
 
 
54
What if My Database is Empty After an Upgrade?
 
55
----------------------------------------------
 
56
 
 
57
If something goes awry during the backup process, it is possible that your current database will be moved into the first backup position (ending with ``.0``), but a blank database will be in the "current" ``Data.fs`` position::
 
58
 
 
59
    sudo mv /var/lib/schooltool/Data.fs.0 /var/lib/schooltool/Data.fs
 
60
 
 
61
How can I erase the entire database?
 
62
------------------------------------
 
63
 
 
64
Delete the ``Data.fs`` file and the ``blobs`` directory.  This is, of course, permanent.  If there is the slightest chance you'll ever want that data, moving rather than deleting the files is advisable.
 
65
 
 
66
Packing the database.
 
67
---------------------
 
68
 
 
69
The ZODB is designed to keep a record of transactions, which can be used by an application to allow "undo" functionality.  One implication of this, however, is that the database file grows in size as it stores a longer and longer list of changes to each object.  To shrink the database back to a more efficient size, one can "pack" it.  Because SchoolTool does not allow you to undo transactions, there is no practical reason not to pack the database.  
 
70
 
 
71
Packing the database does not have to be done very frequently -- certainly not daily.  Monthly or weekly should suffice, but your mileage may vary depending on the intensity of usage.  It may be something you do prior to high demand periods, such as before teachers submit grades.  Backing up your database prior to packing it should not be necessary, but nonetheless it is not a bad idea.
 
72
 
 
73
To pack the database via the web, you must be logged in as a member of "Site Managers." Navigate to the **Server** tab at the top of the page, then click on **Actions: Pack Database**.  You will see a spinner indicating that packing is in progress.  If you stay on the page, you will get a confirmation dialog:
 
74
 
 
75
   .. image:: images/packing.png
 
76
 
 
77
Depending on your site's database usage, this process could take several minutes and put a load on the server, so plan to pack the database at an off-peak time.
 
78