Bug 9498 - Update encoding for Norwegian sample Z39.50 servers
[koha.git] / debian / scripts / koha-restore
blobcaf4c7d99fda3628a9fae3fb969e0e96c5151781
1 #!/bin/sh
3 # koha-restore: restore a Koha site from a dump (from koha-dump)
4 # Copyright 2010 Catalyst IT, Ltd
5 #
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/>.
20 set -e
23 die() {
24 echo "$@" 1>&2
25 exit 1
29 # Parse command line.
30 [ "$#" = 2 ] || die "Usage: $0 sqldump configdump"
31 sqldump="$1"
32 configdump="$2"
35 # Verify that no files in the config dump exist on the filesystem.
36 anyexists=no
37 tar -tf "$configdump" |
38 while read x
40 if [ -e "/$x" ]
41 then
42 anyexists=yes
43 echo "ERROR: File exists: /$x" 1>&2
45 done
46 if [ "$anyexists" = yes ]
47 then
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')
55 username="$name-koha"
56 adduser --no-create-home --disabled-login --gecos "Koha instance $username" \
57 --home "/var/lib/koha/$name" --quiet "$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"
65 # Unpack tarball.
66 tar -C / -xf "$configdump"
69 # Re-create database and database user.
70 mysqldb="koha_$name"
71 mysqluser="koha_$name"
72 mysqlpwd="$( xmlstarlet sel -t -v 'yazgfs/config/pass' /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';
76 eof
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';
80 FLUSH PRIVILEGES;
81 eof
82 koha-rebuild-zebra --full "$name"
85 # Restart Apache.
86 /etc/init.d/apache2 restart