rsync backup of /home/.ecryptfs causes errors

Daniel Convissor danielc at analysisandsolutions.com
Wed Dec 9 19:43:14 UTC 2009


Hi James:

On Wed, Dec 09, 2009 at 03:30:10PM +0700, James Taylor wrote:
> 
> Well, surely the .ecryptfs file must be open and in use by the user that 
> is logged into that account, so even if these errors did not prevent you 
> from copying it, you would risk getting an inconsistent and thus 
> corrupted copy of the file if you succeeded in copying it while it was 
> in use, and likely lose everything it contained.
> 
> Inevitably, to take a consistent backup copy of the .ecryptfs file 
> you'll need to make sure the corresponding user is logged out.

Exactly what I was thinking.  I was looking for a clean/supported way of 
handling all this.  Below is what I came up with and my limited testing 
has been positive.  Note, this is my own system, so booting off "other" 
users isn't a big deal.  What do people think?

vvvvvvvvvvvvvvvv
#! /bin/bash

# Ensure encrypted and unencrypted versions of encrypted home
# directories don't jockey each other.
#
# First, loop through /home and check the status of each directory.
for dir in `ls -ad /home/*` ; do
    user=${dir:6}
    if [ -f $dir/Access-Your-Private-Data.desktop ] ; then
        # This user's directory is not mounted at this time.
        # Back it up.
        rsync -aH --delete $dir /bk/rsync-home/$user
    else
        # This user's directory not encrypted at the moment, and...
        if [ -d /home/.ecryptfs/$user ] ; then
            # is usually encrypted.  Kick them off and unmount their dir.
            sync
            killall -w -u $user
            sync
            umount /home/$user
            sleep 3
            sync
            rsync -aH --delete $dir /bk/rsync-home/$user
        else
            # is ususally not encrypted.   Back it up.
            rsync -aH --delete $dir /bk/rsync-home/$user
        fi
    fi
done

# Second, back up the actual encrypted file system.
rsync -aH --delete /home/.ecryptfs /bk/rsync-home
^^^^^^^^^^^^^^^^

Thanks,

--Dan

-- 
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
            data intensive web and database programming
                http://www.AnalysisAndSolutions.com/
 4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335 f: 718-854-0409




More information about the ubuntu-users mailing list