5.9. Backup your data

If your database crashes for whatever reasons, the first question you'll hear is: "You've got a backup, don't you?". At this point in your life you shouldn't even think about not having a backup.

There's basically two ways to create a backup of your reference data: Use a risx dump or use a SQL dump. The risx dump is slower but it would allow you to transfer the data to a refdb installation using a different database server. The SQL dump is faster but you're tied to the database server you're using. If you use SQLite as your database backend, you may simply grab copies of the database files. Each database is stored in one file. This file holds all required information and is platform-independent, so it is suitable for backup purposes.

Warning

Backups are useful only if you create them regularly. You should work out a schedule based on how often the contents of the database change. Think about setting up a cron job for nightly or weekly snapshots.

5.9.1. Creating a risx dump

All you need to do is to retrieve all references and write them to a file in risx format. Use the getref command in refdbc for this purpose:

refdbc: getref -t risx -s NOHOLES -o all.ris :ID:>0

The -s NOHOLES option will dump skeleton references for references that you deleted from the database. This simplifies re-creating the same ID values in a new database.

5.9.2. Creating a SQL dump

This is best done with the command line tools shipped with you database server. You should consult the manual of your database server, but the following commands should be all it takes:

If you run MySQL as your database server, run:

$ mysqldump -u root -p --opt dbname > dbname.dump

This assumes that "root" is the name of your database administrator account and "dbname" is the name of your database.

If you run PostgreSQL instead, use this command:

$ pg_dump -u pgsql -C dbname > dbname.dump

This assumes that "pgsql" is the name of your database administrator account and "dbname" is the name of your database.

To restore a database from a dump, use the command line clients shipped with your database server. For MySQL, the required sequence is:

$ mysql -u root -p -e "CREATE DATABASE dbname"
$ mysql -u root -p dbname < dbname.dump

whereas the following would do the trick with PostgreSQL:

$ psql -u pgsql template1 < dbname.dump

Tip: SQL dumps are also well suited to create backups of refdb, the common refdb database.