3 # Copyright (C) 2005-2009 Junjiro Okajima
5 # This program, aufs is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 # The development of this script is sponcered by ASUSTek Computer Inc.
21 # Kindly they agreed that I keep my aufs work as free software as it has
35 test ! -x $f && EEcho
$f is not installed
&& exit 1
37 # special handling for backward compatibility.
39 # aufs in the donated eeepc is aufs1 20080211 without CONFIG_AUFS_COMPAT.
40 # /etc/default/aufs was introduced in aufs1 20080922.
41 # shwh/noshwh was introduced in aufs1 20080310 with CONFIG_AUFS_SHWH.
42 # noshwh became always available regardless CONFIG_AUFS_SHWH in aufs1 20081117.
51 echo ${me}: warning
, broken
$f, assuming aufs is
$AUFS_VERSION
53 test ! -s $f && EEcho
$f is not installed
&& exit 1
58 test $AUFS_VERSION -lt 20081117 && noshwh
=0
61 AUFS_SUPER_MAGIC
=1635083891
62 AUFS_SUPER_MAGIC_HEX
=0x61756673
65 AUFS_WH_DIROPQ
=.wh..wh..opq
68 ########################################
70 _Rsync
="rsync --exclude=lost+found"
71 Rsync
="$_Rsync -aHSx --devices --specials --delete-before"
74 RsyncWh
="$_Rsync -ptgoHx"
78 echo "find \"$1\" -xdev -depth \(
80 \( -name $AUFS_WH_DIROPQ
81 -o ! -name ${AUFS_WH_PFX2}\* \) \)
83 ! -name ${AUFS_WH_PFX2}\*
85 ! -wholename \"$1/lost+found\" \)
92 find .
-xdev -name ${AUFS_WH_PFX}\
* ! -name ${AUFS_WH_PFX2}\
* \
96 f
=$
(echo "$wh" |
sed -e '
99 s:/'${AUFS_WH_PFX}':/:
101 test -e "$dst/$f" ||
echo "$wh"
104 $RsyncWh --files-from=- .
/ "$2"
110 $Copy $@
"$mntpnt"/ "$dst"
116 test $hinotify -ne 1 && echo ${me}: warning
, -i is not specified
118 test $
(stat
-f -c %T
"$src") = nfs
&& src_is_nfs
=1
122 eval $
(FindForRm
"$src") |
124 if [ $src_is_nfs -eq 1 ]
126 mount
-o remount
"$mntpnt"
127 mount
-o remount
"$src"
135 _move $@
"$mntpnt"/ "$dst"
145 move
--exclude=${AUFS_WH_PFX}\
*
148 # backward compatibility
156 t
=$
(FindForRm src_branch |
sed -e '
162 $me Options move | move_with_wh | copy \\
163 mntpnt src_branch dst_branch [ options for rsync ]
166 $me [ -w | --wh ] [ -i | --inotify ] Options \\
167 mntpnt cmd [ parameters for cmd ]
173 The dst_branch must be mounted as writable.
174 During the operation, the mntpnt is set readonly.
175 If you are opening a file for writing on the writable branch,
176 you need to close the file before invoking this script.
177 The -w or --wh option requires CONFIG_AUFS_SHWH enabled.
178 The -i or --inotify option requires CONFIG_AUFS_HINOTIFY enabled.
180 'copy' is a shortcut for
182 $Copy mntpnt/ dst_branch
183 'move' is a shortcut for
186 mntpnt/ dst_branch && \\
189 Note: in most cases, you will need '-i' option, and
190 find(1) is invoked by $me only when rsync(1)
192 'move_with_wh' is a simple variation of 'move' which moves
193 whiteouts separately before the actual 'move'.
195 If you execute this script under linux-2.6.24 or earlier, the
196 kernel may produce a harmless warning "inotify.c:NNN
197 set_dentry_child_flags()". The message was already removed in
201 - Copy and reflect all the modification (modifed files, newly
202 created and removed ones) in the upper branch to the lower
203 branch. This operation is for aufs which has only 2 branches,
204 and mainly for a system shutdown script.
205 All files on the upper branch remain.
207 $ sudo $me copy /your/aufs /your/upper_branch /your/lower_branch
209 - Like above (2 branches), move and reflect all modifications
210 from upper to lower. Almost all files on the upper branch will
211 be removed. You can still use this aufs after the
212 operation. But the inode number may be changed. If your
213 application which depends upon the inode number was running at
214 that time, it may not work correctly.
216 $ sudo $me move /your/aufs /your/upper_branch /your/lower_branch
219 # - Like above (2 branches), generate a new middle layer like a
220 # snapshot including whiteouts and make the upper_branch almost
221 # empty, but untouch the lower_branch.
224 # $ dd if=/dev/zero of=\$img bs=4k count=1k
225 # $ mkfs -t ext2 -F \$img
226 # $ sudo mount -o rw,loop \$img /your/new_branch
227 # $ sudo mount -o remount,ins:1:/your/new_branch=ro+wh /your/aufs
228 # $ sudo $me _move /your/aufs /your/upper_branch /your/lower_branch \\
229 # "--remove-source-files \\
230 # --exclude=$AUFS_WH_BASE \\
231 # --exclude=$AUFS_WH_PLINKDIR \\
232 # --exclude=$AUFS_WH_TMPDIR \\
233 # /your/upper_branch/ /your/new_branch; \\
234 # mount -o remount,ro /your/new_branch"
238 ########################################
250 -i|
--inotify) hinotify
=1;;
251 -n|
--dry_run) dry_run
=echo;;
252 -q|
--quiet) quiet
=+x
;;
253 -h|
--help) Usage
; exit 0;;
260 test $# -lt 2 && Usage
1>&2 && exit 1
262 _move|move|copy|move_w|move_with_wh
)
263 test $# -lt 4 && Usage
1>&2 && exit 1
279 case $
(stat
-f -c %T
"$mntpnt") in
280 aufs|UNKNOWN
*${AUFS_SUPER_MAGIC_HEX}*) ;;
282 EEcho
"$mntpnt" is not aufs
287 cur_opts
=$
(MntOpts
"$mntpnt")
288 test ! "$cur_opts" &&
289 EEcho bad
/proc
/mounts or
"$mntpnt" is not mounted
&&
291 cur_opts
="udba=reval,noshwh,$cur_opts"
292 test $noshwh -eq 0 && cur_opts
=$
(echo $cur_opts |
sed -e 's/,noshwh//')
294 # force flushing the pusedo-links
295 tmp_opts
="remount,ro,udba=reval,noshwh"
296 test $noshwh -eq 0 && tmp_opts
=$
(echo $tmp_opts |
sed -e 's/,noshwh//')
297 test $wh -eq 1 && tmp_opts
="$tmp_opts,shwh"
298 test $hinotify -eq 1 && tmp_opts
="$tmp_opts,udba=inotify"
301 trap "$dry_run mount -o remount,$cur_opts \"$mntpnt\"" EXIT
303 $dry_run mount
-o $tmp_opts "$mntpnt"
304 eval "$dry_run $cmd $cmd_opts"