Koha/misc/cronjobs
Jared Camins-Esakov bbcb1d784b Bug 8268: Add database dump to export tool
This patch builds on work by Lars Wirzenius for the Koha packages.

To date, the only way for a Koha librarian to obtain a complete backup
of their system has been to log into the system via SSH (or FTP) to
download the mysqldump file. This patch makes it possible for
superlibrarians in properly configured systems to download night backups
via the staff client's Export tool.

Recognizing that this is functionality with potentially very grave
security implications, system administrators must manually enable these
features in the koha-conf.xml configuration file.

The following configuration settings have been added to the koha-conf.xml
file:
* backupdir => directory where backups should be stored.
* backup_db_via_tools => whether to allow superlibrarians to download
  database backups via the Export tool. The default is disabled, and
  there is no way -- by design -- to enable this option without manually
  editing koha-conf.xml.
* backup_conf_via_tools => whether to allow superlibrarians to download
  configuration backups via the Export tool (this may be applicable to
  packages only). The default is disabled, and there is no way -- by
  design -- to enable this option without manually editing koha-conf.xml.

This commit modifies the following scripts to make use of the new
backupdir configuration option:
* koha-dump and koha-run-backups in the Debian packages
* The sample backup script misc/cronjobs/backup.sh

Note that for security reasons, superlibrarians will not be allowed
to download files that are not owned by the web server's effective user.
This imposes a de facto dependency on ITK (for Apache) or running the
web server as the Koha user (as is done with Plack).

To test:
1. Apply patch.
2. Go to export page as a superlibrarian. Notice that no additional
   export options appear because they have not been enabled.
3. Add <backupdir>$KOHADEV/var/spool</backup> to the <config> section
   of your koha-conf.xml (note that you will need to adjust that so that
   it is pointing at a logical directory).
4. Create the aforementioned directory.
5. Go to export page as a superlibrarian. Notice that no additional
   export options appear because they have not been enabled.
6. Add <backup_db_via_tools>1</backup_db_via_tools> to the <config>
   section of your koha-conf.xml
7. Go to the export page as a superlibrarian. Notice the new tab.
8. Go to the export page as a non-superlibrarian. Notice there is no
   new tab.
9. Run: mysqldump -u koha -p koha | gzip > $BACKUPDIR/backup.sql.gz
   (substituting appropriate user, password, and database name)
10. Go to the export page as a superlibrarian, and look at the "Export
    database" tab. If you are running the web server as your Koha user,
    and ran the above command as your Koha user, you should now see the
    file listed as an option for download.
11. If you *did* see the file listed, change the ownership to something
    else: sudo chown root:root $BACKUPDIR/backup.sql.gz
11a. Confirm that you no longer see the file listed when you look at the
     "Export database" tab.
12. Change the ownership on the file to your web server (or Koha) user:
    sudo chown www-data:www-data backup.sql.gz
13. Go to the export page as a superlibrarian, and look at the "Export
    database" tab. You should now see backup.sql.gz listed.
14. Choose to download backup.sql.gz
15. Confirm that the downloaded file is what you were expecting.

If you are interested, you can repeat the above steps but replace
<backup_db_via_tools> with <backup_conf_via_tools>, and instead of
creating an sql file, create a tar file.

To test packaging: run koha-dump, confirm that it still creates a
usable backup.

------

This signoff contains two changes:

10-1. If no backup/conf files were present, then the message telling you
so doesn't appear and the download button does. Made them behave
correctly.
10-2. The test for a file existing required it to be owned by the
webserver UID. This change makes it so it only has to be readable.

Signed-off-by: Robin Sheat <robin@catalyst.net.nz>
2012-07-12 17:40:21 +02:00
..
holds bug 7641 follow-up: activate use strict (see coding guidelines) 2012-03-29 15:10:16 +02:00
rss Bug 5370: Fix all references to koha.org 2010-11-08 09:41:47 +13:00
social_data Bug 7470: Babeltheque integration 2012-03-26 14:24:04 +02:00
stats Bug 2505 - remove unnecessary -w and replace with use warnings; 2010-04-07 13:27:07 -04:00
thirdparty Bug 8384: Some Perl scripts do not compile 2012-07-10 10:50:58 +02:00
advance_notices.pl Talking Tech Support - Phase I - Followup - Fix Messaging Preferences 2012-06-10 17:46:58 +02:00
backup.sh Bug 8268: Add database dump to export tool 2012-07-12 17:40:21 +02:00
batch_anonymise.pl Bug 6572: Script batch anonymisation wrapper 2011-10-20 13:57:14 +13:00
build_browser_and_cloud.pl Bug 2505 - Add commented use warnings where missing in the misc/ directory 2010-04-21 20:26:44 +12:00
cart_to_shelf.pl 7368 Typo in cart_to_shelf 2012-03-16 11:50:29 +01:00
check-url.pl Bug 6267: [SIGNED-OFF]Fix a typo 2012-06-09 14:44:17 +02:00
cleanup_database.pl Bug 7240: Cleaning up import tables and action_logs 2012-01-13 12:20:51 +01:00
cloud-kw.pl Bug 5385: POD Cleanups (part 2) 2010-11-12 10:06:56 +13:00
cloud-sample.conf Fixes bugs #2875-2879 2008-12-29 19:59:44 -06:00
CONFIGURE.gmail Bug 5251 : Enhancement: [3.2] (Resubmission) Adding code to support using gmail as an SMTP server 2011-04-08 14:01:15 +12:00
create_koc_db.pl Bug 2505 - remove unnecessary -w and replace with use warnings; 2010-04-07 13:27:07 -04:00
crontab.example Bug 6557: Record bib popularity in totalissues 2012-06-29 14:29:22 +02:00
fines.pl Bug 5549 : Refactor fines.pl 2012-03-20 13:27:12 +13:00
gather_print_notices.pl bug_7001: Issue and Reserve slips are notices. 2012-03-09 10:11:20 +01:00
import_webservice_batch.pl bug_7613: OCLC Connexion gateway 2012-04-06 17:26:20 +02:00
j2a.pl Bug 7157 follow-up: j2a.pl executable again 2012-01-27 12:18:25 +01:00
longoverdue.pl Bug 7526 - longoverdue.pl leaves items marked as lost as still checked out to patron 2012-03-20 11:22:52 +01:00
MARC21_parse_test.pl Bug 6752: Be stricter with utf-8 encoding of output 2012-01-27 12:11:06 +01:00
overdue_notices.pl Bug 8267 - Overdue notices not working 2012-06-20 23:14:56 +02:00
printoverdues.sh Bug 6048: printoverdues.sh bash odities 2011-10-07 14:14:53 +13:00
process_message_queue.pl Bug 5251 : Enhancement: [3.2] (Resubmission) Adding code to support using gmail as an SMTP server 2011-04-08 14:01:15 +12:00
purge_suggestions.pl Bug 5944 : (MT #3000) new cronjob script to delete old suggestions 2011-03-24 22:10:20 +13:00
runreport.pl Bug 5253: Add options to runreport.pl 2011-03-29 22:53:06 +13:00
serialsUpdate.pl Bug 2505 - remove unnecessary -w and replace with use warnings; 2010-04-07 13:27:07 -04:00
services_throttle.pl Minor updates to minor cronjob script. 2008-12-31 09:47:54 -06:00
smsoverdues.pl Bug 3810: Ensure all calls to Mail::Sendmail handled consistently 2011-03-16 20:57:12 +13:00
staticfines.pl Bug 6858: Adds staticfines.pl for static fines processing 2012-05-28 16:29:48 +02:00
update_totalissues.pl Bug 6557: Record bib popularity in totalissues 2012-06-29 14:29:22 +02:00
zebraqueue_start.pl Bug 2505 - Add commented use warnings where missing in the misc/ directory 2010-04-21 20:26:44 +12:00