View | Details | Raw Unified | Return to bug 14532
Collapse All | Expand All

(-)a/debian/docs/koha-dump.xml (-2 / +36 lines)
Lines 23-34 Link Here
23
23
24
  <refsynopsisdiv>
24
  <refsynopsisdiv>
25
    <cmdsynopsis>
25
    <cmdsynopsis>
26
      <command>koha-dump</command> <arg choice="req" rep="norepeat"><replaceable>instancename</replaceable></arg>
26
      <command>koha-dump</command>
27
      <arg choice="noreq">
28
        <option>--help</option>|<option>-h</option>
29
        <option>--include-indexes</option>|<option>-i</option>
30
        <option>--quiet</option>|<option>-q</option>
31
      </arg>
32
      <arg choice="req" rep="repeat"><replaceable>instancename</replaceable></arg>
27
    </cmdsynopsis>
33
    </cmdsynopsis>
28
  </refsynopsisdiv>
34
  </refsynopsisdiv>
29
35
36
  <refsect1>
37
    <title>Options</title>
38
    <variablelist>
39
40
      <varlistentry>
41
        <term><option>--include-indexes</option>|<option>-i</option></term>
42
        <listitem>
43
          <para>Make <command>koha-dump</command> include Zebra indexes during the dump operation. This is useful for fast recovering Koha instances using <command>koha-restore</command> (i.e. there's no need to reindex your database). The drawback is that dumps tend to be a lot bigger and slower to create.</para>
44
        </listitem>
45
      </varlistentry>
46
47
      <varlistentry>
48
        <term><option>--quiet</option>|<option>-q</option></term>
49
        <listitem>
50
          <para>Make <command>koha-dump</command> run silently.</para>
51
        </listitem>
52
      </varlistentry>
53
54
      <varlistentry>
55
        <term><option>--help</option>|<option>-h</option></term>
56
        <listitem>
57
          <para>Show usage information.</para>
58
        </listitem>
59
      </varlistentry>
60
61
    </variablelist>
62
  </refsect1>
63
30
  <refsect1><title>Description</title>
64
  <refsect1><title>Description</title>
31
  <para>Dump all contents and configs for a Koha site.</para>
65
  <para>Dump all contents and configs for one or more Koha instances.</para>
32
  </refsect1>
66
  </refsect1>
33
  
67
  
34
  <refsect1><title>See also</title>
68
  <refsect1><title>See also</title>
(-)a/debian/scripts/koha-dump (-38 / +116 lines)
Lines 30-69 fi Link Here
30
# Make sure the files we create are not accessible by anyone else.
30
# Make sure the files we create are not accessible by anyone else.
31
umask 0077
31
umask 0077
32
32
33
# Parse command line.
33
usage()
34
[ "$#" = 1 ] || die "Usage: $0 instancename"
34
{
35
name="$1"
35
    local scriptname=$(basename $0)
36
kohaconfig="/etc/koha/sites/$name/koha-conf.xml"
36
37
date="$(date +%Y-%m-%d)"
37
    cat <<EOF
38
38
$scriptname
39
echo "Dumping Koha site $name:"
39
40
40
This script dumps your Koha instance data for backup or migration.
41
41
42
# Dump database.
42
Usage:
43
mysqlhost="$( xmlstarlet sel -t -v 'yazgfs/config/hostname' $kohaconfig )"
43
$scriptname [--quiet|-q] [--include-indexes|-i] instancename1 [instancename2...]
44
mysqldb="$( xmlstarlet sel -t -v 'yazgfs/config/database' $kohaconfig )"
44
$scriptname -h|--help
45
mysqluser="$( xmlstarlet sel -t -v 'yazgfs/config/user' $kohaconfig )"
45
46
mysqlpass="$( xmlstarlet sel -t -v 'yazgfs/config/pass' $kohaconfig )"
46
    --include-indexes|-i  Include Zebra indexes on the backup.
47
backupdir="$( xmlstarlet sel -t -v 'yazgfs/config/backupdir' $kohaconfig || true )"
47
    --quiet|-q            Make the script avoid printing to STDOUT
48
[ -z "$backupdir" ] && backupdir="/var/spool/koha/$name"
48
                          (useful for calling from another scripts).
49
dbdump="$backupdir/$name-$date.sql.gz"
49
    --help|-h             Display this help message
50
echo "* DB to $dbdump"
50
51
mysqldump --databases --host="$mysqlhost" \
51
EOF
52
    --user="$mysqluser" --password="$mysqlpass" "$mysqldb" | 
52
}
53
    gzip > "$dbdump"
53
54
chown "root:$name-koha" "$dbdump"
54
dump_instance()
55
chmod g+r "$dbdump"
55
{
56
56
    local name=$1
57
instancefile="$name.conf"
57
58
58
    kohaconfig="/etc/koha/sites/$name/koha-conf.xml"
59
# Dump configs, logs, etc.
59
    date="$(date +%Y-%m-%d)"
60
metadump="$backupdir/$name-$date.tar.gz"
60
61
echo "* configs, logs to $metadump"
61
    [ "$quiet" = "no" ] && echo "Dumping Koha site $name:"
62
tar -C / -czf "$metadump" \
62
63
    "etc/koha/sites/$name" \
63
    # Dump database.
64
    "etc/apache2/sites-available/$instancefile" \
64
    mysqlhost="$( xmlstarlet sel -t -v 'yazgfs/config/hostname' $kohaconfig )"
65
    "etc/apache2/sites-enabled/$instancefile" \
65
    mysqldb="$( xmlstarlet sel -t -v 'yazgfs/config/database' $kohaconfig )"
66
    "var/lib/koha/$name" \
66
    mysqluser="$( xmlstarlet sel -t -v 'yazgfs/config/user' $kohaconfig )"
67
    "var/log/koha/$name"
67
    mysqlpass="$( xmlstarlet sel -t -v 'yazgfs/config/pass' $kohaconfig )"
68
68
    backupdir="$( xmlstarlet sel -t -v 'yazgfs/config/backupdir' $kohaconfig || true )"
69
echo "Done."
69
    [ -z "$backupdir" ] && backupdir="/var/spool/koha/$name"
70
    dbdump="$backupdir/$name-$date.sql.gz"
71
    [ "$quiet" = "no" ] && echo "* DB to $dbdump"
72
    mysqldump --databases --host="$mysqlhost" \
73
        --user="$mysqluser" --password="$mysqlpass" "$mysqldb" | 
74
        gzip > "$dbdump"
75
    chown "root:$name-koha" "$dbdump"
76
    chmod g+r "$dbdump"
77
78
    instancefile="$name.conf"
79
80
    # Dump configs, logs, etc.
81
    metadump="$backupdir/$name-$date.tar.gz"
82
    [ "$quiet" = "no" ] && echo "* configs, logs to $metadump"
83
84
    zebra_files=""
85
    if [ "$include_indexes" = "yes" ]
86
        zebra_files="var/lib/koha/$name"
87
    fi
88
89
    tar -C / -czf "$metadump" \
90
        "etc/koha/sites/$name" \
91
        "etc/apache2/sites-available/$instancefile" \
92
        "etc/apache2/sites-enabled/$instancefile" \
93
        "var/log/koha/$name" "$zebra_files"
94
95
    [ "$quiet" = "no" ] && echo "Done."
96
}
97
98
# Default values
99
quiet="no"
100
include_indexes="no"
101
102
while [ $# -gt 0 ]; do
103
104
    case "$1" in
105
        -i|--include-indexes)
106
            include_indexes="yes"
107
            shift ;;
108
        -h|--help)
109
            usage ; exit 0 ;;
110
        -q|--quiet)
111
            quiet="yes"
112
            shift ;;
113
        -*)
114
            die "Error: invalid option switch ($1)" ;;
115
        *)
116
            # We expect the remaining stuff are the instance names
117
            break ;;
118
    esac
119
120
done
121
122
# Read instance names
123
if [ $# -gt 0 ]; then
124
    # We have at least one instance name
125
    for name in "$@"; do
126
127
        if is_instance $name; then
128
129
            dump_instance $name
130
131
        else
132
            if [ "$quiet" = "no" ]; then
133
                die "Error: Invalid instance name $name"
134
            else
135
                exit 1
136
            fi
137
        fi
138
139
    done
140
else
141
    if [ "$quiet" = "no" ]; then
142
        die "Error: you must provide at least one instance name"
143
    else
144
        exit 1
145
    fi
146
fi
147
148
exit 0
70
- 

Return to bug 14532