CanDo Maintenance and Backups

System Maintenance

Maintenance of Ubuntu Linux and CanDo is generally as simple as regularly running

sudo apt-get update
sudo apt-get upgrade

When the kernel packages are updated, you will want to reboot your server.

sudo shutdown -r now
                

More information can be found in the Ubuntu server documentation.

Packing the database

To maintain good system performance, the CanDo database should be "packed" from time to time.

Backups - the least you need to know

The CanDo database file is kept at /var/lib/schooltool/Data.fs. This file should be backed up regularly, along with the /var/lib/schooltool/blobs directory. (This directory contains image files, generated pdf reports and other binary files.) In order to back up these files, you must give your user account permission to read these directories and files by adding your account to the schooltool group. (For <username> subsitute your user name.)

sudo usermod -a -G schooltool <username>
                

Log out and log back in to confirm that you can now see these directories

sudo ls -l /var/lib/schooltool

sudo ls -1 /var/lib/schooltool/blobs

Now you should be able to back up those files using common SFTP-capable tools, such as FileZilla or Cyberduck (Mac only).

Other backup strategies, such as backing up to network shares and compression are of course possible. The Ubuntu server documentation includes some discussion.

NOTE: We cannot recommend making backups using File Transfer Protocol (FTP) as under certain circumstances file corruption can occur. Whatever backup scheme you choose, it is imperative that you test restoring from your backups before you need to rely on them on your production server.

Snapshots

It can be useful to keep "snapshots" of the state of CanDo at particular moments in time. Here is one way to accomplish this. NOTE: This script does not rotate the snapshots. If you use this method, you will need to clean up the file system manually to keep it from filling. How often you have to do so, depends on server space.

First, add your user account to the schooltool group as detailed above.

Create directories to store the snapshots.

sudo mkdir -p /var/lib/schooltool/cando-backups/zip
sudo chown -R schooltool:schooltool /var/lib/schooltool/cando-backups
                

Now copy this script to /etc/cron.daily.

wget http://cando.cteresource.org/cando-daily-pkg.py
chmod +x cando-daily-pkg.py
sudo mv cando-daily-pkg.py /etc/cron.daily/cando-snapshot
                

The script will now be run daily by the run-parts utility. Time-stamped copies of the database file will be kept in /var/lib/schooltool/cando-backups. Compressed copies are kept in /var/lib/schooltool/cando-backups/zip. While the script is running, CanDo will be unavailable to users, so you will want to check the time that run-parts is set to run and modify as necessary.

sudo nano /etc/crontab
                

Look for the line that includes 'cron.daily.' In this example, the scripts in /etc/cron.daily are run beginning at 6:25 a.m.

25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
                

The daily scripts could be made to run starting at 3:25 a.m. simply by changing the 6 in the second column to a 3.

25 3    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
                

Restore

Whatever backup strategy you choose, it is wise to test that you can restore from backups before relying on it and to test again periodically.

To restore from a backup, stop the server, backup the live database (just in case), copy the backup into place, and restart the server:

sudo service schooltool stop
sudo mv /var/lib/schooltool/Data.fs ~/Data.fs.just.in.case
sudo cp /path/to/backup/Data.fs  /var/lib/schooltool/Data.fs
sudo chown schooltool:schooltool /var/lib/schooltool/Data.fs
sudo chmod 644 /var/lib/schooltool/Data.fs
sudo service schooltool start
                

The server will take some time to come back online as it processes the restored database file. You can monitor this process, using the top command. When CPU uitilization drops back down to normal levels, you should be able to log into your restored CanDo instance.