Bug 9754

Summary: koha-remove optionally includes var/lib and var/spool
Product: Koha Reporter: Magnus Enger <magnus>
Component: PackagingAssignee: Marcel de Rooy <m.de.rooy>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P5 - low CC: brendan, dcook, f.demians, julian.maurice, m.de.rooy, mirko, mtj, pablo.bianchi, robin
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=16291
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=13902
Change sponsored?: --- Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Bug Depends on:    
Bug Blocks: 16291, 17266    
Attachments: Bug 9754: koha-remove optionally includes var/lib and var/spool
Bug 9754: koha-remove optionally includes var/lib and var/spool
Bug 9754: koha-remove optionally includes var/lib and var/spool

Description Magnus Enger 2013-03-06 12:55:52 UTC
While testing something else, I have created and removed quite a number of instances on the same server. By chance I discovered that removing instances has not removed the instance-specific direcories below /var/lib/koha/, and the permissions on these directories are completely off:

$ ls -l /var/lib/koha/
total 44
drwxr-xr-x 4 test-koha  test-koha  4096 2012-11-21 15:59 buskfylk
drwxr-xr-x 4 norge-koha norge-koha 4096 2012-12-09 21:14 esme
drwxr-xr-x 4 test1-koha test1-koha 4096 2012-11-09 14:15 marc21
drwxr-xr-x 4       1005       1005 4096 2012-12-28 13:00 munka21
drwxr-xr-x 4 norge-koha norge-koha 4096 2013-03-05 17:54 mytest
drwxr-xr-x 4 usa-koha   usa-koha   4096 2013-03-06 11:12 norge
drwxr-xr-x 4 usa-koha   usa-koha   4096 2012-12-10 18:47 normarc
drwxr-xr-x 4 norge-koha norge-koha 4096 2011-12-03 18:13 sksk
drwxr-xr-x 4 test-koha  test-koha  4096 2012-12-10 08:36 test
drwxr-xr-x 4 test1-koha test1-koha 4096 2013-03-05 17:54 test1
drwxr-xr-x 4 usa-koha   usa-koha   4096 2013-03-06 13:17 usa

The prmissions for test and test1 are OK, the others are not. 

I created an instance called "norge", then removed it and created it again. As a result of the situation above I now get a permission error when I try to re-index Zebra for this instance, but I still get hits from the previous incarnation of the instance, presumably because the indexes etc are still there.
Comment 1 Robin Sheat 2013-03-06 22:32:32 UTC
Hmm. I'm not sure that it should remove user-generated data (perhaps a --purge option would be good for this), and by the same token it probably shouldn't overwrite existing data. However the permissions being wrong is obviously an issue. I think perhaps the correct approach is to ensure the permissions are correct and set a flag to do a full zebra reindex.

I'm open to other ideas though, I'm not totally sure what the best approach is. Another option is perhaps to have an existing directory renamed out of the way if koha-create would cause a name conflict.

Thoughts on this?
Comment 2 Mirko Tietgen 2014-02-27 16:06:45 UTC
(In reply to Robin Sheat from comment #1)
> Hmm. I'm not sure that it should remove user-generated data (perhaps a
> --purge option would be good for this)

+1 for the purge option. I expected koha-remove to remove »everything« and got a lot of errors for existing register files when doing koha-restore.
Comment 3 Robin Sheat 2014-03-02 22:19:00 UTC
(In reply to Mirko Tietgen from comment #2)
> +1 for the purge option. I expected koha-remove to remove »everything« and
> got a lot of errors for existing register files when doing koha-restore.

Then we should really have koha-create/koha-restore understand that these things could happen and to check for them first, doing something appropriately.
Comment 4 Mirko Tietgen 2014-03-03 15:53:41 UTC
*** Bug 10999 has been marked as a duplicate of this bug. ***
Comment 5 David Cook 2015-03-30 02:38:21 UTC
Still an issue in 3.18.5. 

I did a koha-create, then a koha-remove, then a koha-restore. Here's the output of the koha-restore:

sudo koha-restore library.sql.gz library.tar.gz
ERROR: File exists: /var/lib/koha/library/
ERROR: File exists: /var/lib/koha/library/plugins/
ERROR: File exists: /var/lib/koha/library/biblios/
ERROR: File exists: /var/lib/koha/library/biblios/key/
ERROR: File exists: /var/lib/koha/library/biblios/shadow/
ERROR: File exists: /var/lib/koha/library/biblios/tmp/
ERROR: File exists: /var/lib/koha/library/biblios/register/
ERROR: File exists: /var/lib/koha/library/biblios/register/reci-0.mf
ERROR: File exists: /var/lib/koha/library/biblios/register/gmatch-0.mf
ERROR: File exists: /var/lib/koha/library/biblios/register/dict-0.mf
ERROR: File exists: /var/lib/koha/library/biblios/register/isambB-0.mf
ERROR: File exists: /var/lib/koha/library/biblios/register/recdB-0.mf
ERROR: File exists: /var/lib/koha/library/biblios/register/isambA-0.mf
ERROR: File exists: /var/lib/koha/library/biblios/register/isambD-0.mf
ERROR: File exists: /var/lib/koha/library/biblios/register/isambC-0.mf
ERROR: File exists: /var/lib/koha/library/biblios/register/sort18-0.mf
ERROR: File exists: /var/lib/koha/library/biblios/register/recdA-0.mf
ERROR: File exists: /var/lib/koha/library/biblios/register/sort23-0.mf
ERROR: File exists: /var/lib/koha/library/authorities/
ERROR: File exists: /var/lib/koha/library/authorities/key/
ERROR: File exists: /var/lib/koha/library/authorities/shadow/
ERROR: File exists: /var/lib/koha/library/authorities/tmp/
ERROR: File exists: /var/lib/koha/library/authorities/register/
ERROR 1396 (HY000) at line 1: Operation DROP USER failed for 'koha_library'@'%'
[ ok ] Restarting web server: apache2 ... waiting .

I figure koha-remove should remove everything... but if there's no consensus on that one, I'm happy to have a --purge or --force option. It would be nice to be able to completely destroy any trace of an instance afterward.
Comment 6 Marcel de Rooy 2016-01-14 11:50:36 UTC Comment hidden (obsolete)
Comment 7 Chris Cormack 2016-01-17 02:20:27 UTC Comment hidden (obsolete)
Comment 8 Jonathan Druart 2016-01-19 10:38:53 UTC
Created attachment 46855 [details] [review]
Bug 9754: koha-remove optionally includes var/lib and var/spool

Currently, the files in the folder /var/lib/koha/[instance] and also
in /var/spool/koha/[instance] are not removed.
This patch adds the option -p|--purge-all to include those two
directories when removing files.

Note: There was a small bug in the for loop. On the -k line the extra
shift statement is one too much.

NOTE: Verify that you use the adjusted koha-remove in the test plan
and not accidentally an older version of this script.

Test plan:
[1] Create an instance test.
[2] Run koha-remove and verify that /var/lib/koha/test still exists.
[3] Create an instance test2.
[4] Run koha-remove -k -p and verify that the sql database still exists
    but the two instance folders in var/lib/koha and var/spool/koha are
    gone.

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 9 Brendan Gallagher 2016-01-27 02:30:52 UTC
Pushed to Master - Should be in the May 2016 Release.  Thanks!
Comment 10 Julian Maurice 2016-01-29 10:43:34 UTC
Patch pushed to 3.22.x, will be in 3.22.3
Comment 11 Frédéric Demians 2016-02-12 06:37:15 UTC
This patch has been pushed to 3.20.x, will be in 3.20.9.
Comment 12 Marcel de Rooy 2018-05-30 14:24:09 UTC
*** Bug 20835 has been marked as a duplicate of this bug. ***