5 ### (c) 2012 Mark Wooding
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of the `rsync-backup' program.
12 ### rsync-backup is free software; you can redistribute it and/or modify
13 ### it under the terms of the GNU General Public License as published by
14 ### the Free Software Foundation; either version 2 of the License, or
15 ### (at your option) any later version.
17 ### rsync-backup is distributed in the hope that it will be useful,
18 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ### GNU General Public License for more details.
22 ### You should have received a copy of the GNU General Public License
23 ### along with rsync-backup; if not, write to the Free Software Foundation,
24 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 mkdir -p @pkglocalstatedir@
29 INDEXDB=@pkglocalstatedir@/index.db
30 : ${STOREDIR=@mntbkpdir@/store}
31 : ${METADIR=@mntbkpdir@/meta}
33 if [ ! -f $STOREDIR/.rsync-backup-store ]; then
34 echo >&2 "$quis: no backup volume mounted"
37 : ${VOLUME=$(cat $METADIR/volume)}
39 ## If the database exists then we're OK. (This will turn into a version
40 ## check and upgrade if the schema changes.)
41 if [ ! -f "$INDEXDB" ]; then
43 ## Create the database.
45 sqlite3 "$INDEXDB.new" <<EOF
47 version INTEGER NOT NULL);
48 INSERT INTO meta (version) VALUES (0);
55 PRIMARY KEY (host, fs, date));
56 CREATE INDEX idx_byvol ON idx (vol);
60 mv "$INDEXDB.new" "$INDEXDB"
64 ## Do everything in a single transaction. SQLite is pretty good at this,
65 ## and also it'll avoid updating the database until it sees a `COMMIT'
66 ## command, so if we fail halfway through we're still OK. So it's safe to
67 ## start by removing all of the current records referring to this volume.
70 DELETE FROM idx WHERE vol = '$VOLUME';
73 ## Now work through the various filesystems. This is a slightly cheesy way
75 for i in $STOREDIR/*/*/last; do
77 ## Parse out the host and filesystem names.
80 host=${i##*/} i=${i%/*}
82 ## And work through the date list.
83 for j in $STOREDIR/$host/$fs/*; do
84 if [ -L "$j" ] || [ ! -d "$j" ]; then continue; fi
88 INSERT INTO idx (host, fs, date, vol)
89 VALUES ('$host', '$fs', '$date', '$VOLUME');
98 } | sqlite3 "$INDEXDB"
100 ###----- That's all, folks --------------------------------------------------