3 # koha-restore: restore a Koha site from a dump (from koha-dump)
4 # Copyright 2010 Catalyst IT, Ltd
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
30 [ "$#" = 2 ] || die "Usage: $0 sqldump configdump"
35 # Verify that no files in the config dump exist on the filesystem.
37 tar -tf "$configdump" |
43 echo "ERROR: File exists: /$x" 1>&2
46 if [ "$anyexists" = yes ]
48 die "Config dump $configdump has files that exist on the filesystem."
52 # Create user and group.
53 name=$(tar tf "$configdump" |
54 sed -n '/^etc\/koha\/sites\/\([^/]*\)\/$/s//\1/p')
56 adduser --no-create-home --disabled-login --gecos "Koha instance $username" \
60 # Create dirs. Some of them will be in the tarball, but not all, e.g.,
61 # /var/run and /var/lock.
62 koha-create-dirs "$name"
66 tar -C / -xf "$configdump"
69 # Re-create database and database user.
71 mysqluser="koha_$name"
72 mysqlpwd="$(sed -n '/.*<pass>\(.*\)<\/pass>.*/s//\1/p' /etc/koha/sites/$name/koha-conf.xml)"
73 zcat "$sqldump" | mysql --defaults-extra-file=/etc/mysql/koha-common.cnf
74 mysql --defaults-extra-file=/etc/mysql/koha-common.cnf <<eof || true
75 DROP USER '$mysqluser';
77 mysql --defaults-extra-file=/etc/mysql/koha-common.cnf << eof || true
78 CREATE USER '$mysqluser' IDENTIFIED BY '$mysqlpwd';
79 GRANT ALL PRIVILEGES ON $mysqldb.* TO '$mysqluser';
82 koha-rebuild-zebra --full "$name"
86 /etc/init.d/apache2 restart