Saving ownership as non-root

Shachar Shemesh rsync at shemesh.biz
Thu Aug 17 08:07:20 GMT 2006


Paul Slootman wrote:

> Hence although it would look like you could use rsync to backup device
> nodes and so on via fakeroot, as soon as the fakeroot session is ended,
> the information is gone. There is some support for persistent storage of
> the fake info, but that's not perfect; I wouldn't rely on it for _my_
> backups.
>   
I, obviously, cannot argue with what you will or will not do for your
backups. For one of my projects, I created a wrapper around fakeroot
that makes it persistent, and even allows it to be used by several
independently launched processes simultaneously. The script is far from
perfect, and needs lots of tweaking UI wise. The main problem is that it
takes the directory from which the "fake" script was launched as an
indication where to store the persistent state. Otherwise, it seems to
work fairly flawlessly for me. The script is attached to this mail.

I took the liberty of CCing fakeroot's author on this mail, to notify
him of the existence of this thread.
>> Additionally it would be a nice idea to refer to "fakeroot" from the
>> rsync manual. - It took me a day to find that out. And am still looking
>> for alternatives... Anyone?
>>     
>
> the mention in the manual would have to be pretty explicit about the
> caveats.
>   
There is only two caveat that I encountered (aside from the obvious one,
that files do not look right when viewed not from within fakeroot). This
is after fairly extensive use of fakeroot, quite outside its original
intended use pattern.

The first is that the "killfaked" script must be run in order for the
state information to be stored to disk. This is not a major problem,
usually, as all "killfaked" does is to kill the faked daemon gracefully.
Any normal session exit will, effectively, do the same. We can also rig
the script used for rsync to make sure the state is stored at the end of
the rsync session.

The second is that a directory handled by fakeroot must not be
manipulated without it, or strange things will happen. Simple moves and
renames inside the directory structure are currently ok, but any
permission change, as well as files being deleted or created, may result
in extremely strange looking files.
> Paul Slootman
>   
Shachar
-------------- next part --------------
#!/bin/sh
# Run fakeroot with persistent storage of information
# Copyright (C) 2005, 2006 by Shachar Shemesh
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
#
# $Id: fake,v 1.7 2005/09/20 15:15:15 sun Exp $

set -e

statedir=`dirname $0`
statefile=$statedir/.fakerootenv
keyfile=/tmp/fakedkey_`whoami`_`ls -id $statedir | cut -d ' ' -f 1`


if [ ! -f $keyfile ] || [ ! -d /proc/`cut -d : -f 2 < $keyfile` ] ||
    ! ( readlink /proc/`cut -d : -f 2 $keyfile`/exe | grep -q '/faked-sysv$' )
then
    echo "Starting fakeroot daemon"
    touch $statefile
    /usr/bin/faked-sysv --save-file $statefile --load < $statefile > $keyfile
fi

FAKEROOTKEY=`cut -d: -f1 $keyfile`
LD_LIBRARY_PATH=/usr/lib/libfakeroot
LD_PRELOAD=libfakeroot-sysv.so.0
export FAKEROOTKEY LD_LIBRARY_PATH LD_PRELOAD

exec "$@"
-------------- next part --------------
#!/bin/sh
# Kill the persistent faked daemon created by previous calls to "fake", and save the persistent data
# Copyright (C) 2005, 2006 by Shachar Shemesh
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
#
# $Id: killfaked,v 1.4 2005/09/19 15:36:06 sun Exp $

set -e

statedir=`dirname $0`
keyfile=/tmp/fakedkey_`whoami`_`ls -id $statedir | cut -d ' ' -f 1`

if [ -f $keyfile ] && [ -d /proc/`cut -d : -f 2 < $keyfile` ] &&
    ( readlink /proc/`cut -d : -f 2 $keyfile`/exe | grep -q '/faked-sysv$' )
then
    kill `cut -d : -f 2 $keyfile`
    rm $keyfile
else
    echo "faked not running"
    rm -f $keyfile
fi


More information about the rsync mailing list