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" \
61 tar -C / -xf "$configdump"
64 # Re-create database and database user.
66 mysqluser="koha_$name"
67 mysqlpwd="$(sed -n '/.*<pass>\(.*\)<\/pass>.*/s//\1/p' /etc/koha/sites/$name/koha-conf.xml)"
68 zcat "$sqldump" | mysql --defaults-extra-file=/etc/mysql/debian.cnf
69 mysql --defaults-extra-file=/etc/mysql/debian.cnf <<eof || true
70 DROP USER '$mysqluser';
72 mysql --defaults-extra-file=/etc/mysql/debian.cnf << eof || true
73 CREATE USER '$mysqluser' IDENTIFIED BY '$mysqlpwd';
74 GRANT ALL PRIVILEGES ON $mysqldb.* TO '$mysqluser';
80 /etc/init.d/apache2 restart