3 ### Make fake snapshots by remounting a filesystem readonly
5 ### (c) 2011 Mark Wooding
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of the distorted.org.uk backup suite.
12 ### distorted-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 ### distorted-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 along
23 ### with distorted-backup; if not, write to the Free Software Foundation,
24 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 ###--------------------------------------------------------------------------
30 ### Parse the command line.
32 ## Provide help or version information.
33 usage
="usage: $quis DEVICE [KEY=VALUE ...]"
34 version
="$quis, version 1.0.0"
36 0,*) echo >&2 "$usage"; exit 1 ;;
37 *,-v |
*,--version
) echo "$version"; exit ;;
44 dir=MOUNTPT Mount point of filesystem.
45 op=OPERATION \`snap' to create snapshot, or \`unsnap' to remove.
46 tag=TAG Disambiguation tag to store in filesystem.
52 ## Scan the option keys.
59 *) echo >&2 "$quis: malformed option \`$i'"; exit 1 ;;
62 case "$k" in *.ro
) k
=${k%.ro} ;; ?
*.?
*) continue ;; esac
64 op | tag | dir
) eval "O$k=\$v" ;;
65 *) echo >&2 "$quis: unknown option \`$k'"; win
=nil
;;
68 case $win in nil
) exit 1 ;; esac
70 ## Find a mount point if none was given.
71 sdn
='s/^b[^ ]* *[^ ]* *[^ ]* *[^ ]* *\([0-9]*\), *\([0-9]*\) .*$/\1:\2/'
76 devno
=$
(ls -lL
"/dev/$dev" |
sed "$sdn")
79 *) echo >&2 "$quis: $dev is not a block device"; exit 1 ;;
81 while read <&3 d m fs hunoz
; do
82 if [ ! -b
"$d" ]; then continue; fi
83 dn
=$
(ls -lL
"$d" |
sed "$sdn")
87 t
) echo >&2 "$quis: /dev/$dev mounted multiple times"; exit 1 ;;
97 t
) ;; *) echo >&2 "$quis: /dev/$dev apparently not mounted"; exit 1 ;;
100 ###--------------------------------------------------------------------------
101 ### Take or remove the snapshot.
106 echo "$Otag" >"$Odir/.snap"
107 mount
-oremount
,ro
"/dev/$dev" "$Odir"
112 if [ ! -f
"$Odir/.snap" ]; then
113 echo >&2 "$quis: no snapshot tag"
116 read tag
<"$Odir/.snap"
120 echo >&2 "$quis: tag mismatch (found \`$tag' but expected \`$Otag')"
124 mount
-oremount
,rw
"/dev/$dev" "$Odir"
129 echo >&2 "$quis: unknown operation \`$Oop'"
135 ###----- That's all, folks --------------------------------------------------