Samba4 Howto backup/restore including user_xattrs

Enrico Ehrhardt intruder0815 at
Thu Dec 15 06:03:08 MST 2011

Finally, I managed to get complete backup including all the xattrs. The
samba_backup script located in ./source4/scripting/bin doesn't save the
attributes at all (well, it's tar's fault). If you're using user_xattr on
your filesystem, you will get trouble with NT-attributes on restore.

Using the bsdtar program will help out in this situation. On most systems,
bsdtar isn't installed by default, but it should be easy to get from

On Debian-like systems 'apt get install bsdtar' should work.

For this to work as easy as possible, I've slightly changed the
samba_backup script - a patch is located below.

Now, you should be able to get a full working backup of your data by

$ ./source4/scripting/bin/samba_backup

This should put all your files into /usr/local/backups/

Now, you should be able to restore the data by calling:

$ cd /usr/local/samba
$ bsdtar -xjpf /usr/local/backups/your_backupXYZ.tar.bz2

(the p in -xjpf preserves all attributes and writes them back to disk, this
is mandatory)

Have a nice day!

-------------- next part --------------
diff --git a/source4/scripting/bin/samba_backup b/source4/scripting/bin/samba_backup
index 75ebec6..e34981e 100755
--- a/source4/scripting/bin/samba_backup
+++ b/source4/scripting/bin/samba_backup
@@ -48,6 +48,10 @@ cd $FROMWHERE
 for d in $DIRS;do
        relativedirname=`find . -type d -name "$d" -prune`
        n=`echo $d | sed 's/\//_/g'`
+       # remove all sockets
+       find $relativedirname -type s -exec rm {} \;
        if [ "$d" = "private" ]; then
                find $relativedirname -name "*.ldb.bak" -exec rm {} \;
                for ldb in `find $relativedirname -name "*.ldb"`; do
@@ -57,14 +61,14 @@ for d in $DIRS;do
                                exit 1
-               tar cjf ${WHERE}/samba4_${n}.${WHEN}.tar.bz2  $relativedirname --exclude=*.ldb >/dev/null 2>&1
+               bsdtar cjf ${WHERE}/samba4_${n}.${WHEN}.tar.bz2 --exclude "*.ldb" $relativedirname
                if [ $? -ne 0 ]; then
                        echo "Error while archiving ${WHERE}/samba4_${n}.${WHEN}.tar.bz2"
                        exit 1
                find $relativedirname -name "*.ldb.bak" -exec rm {} \;
-               tar cjf ${WHERE}/${n}.${WHEN}.tar.bz2  $relativedirname >/dev/null 2>&1
+               bsdtar cjf ${WHERE}/${n}.${WHEN}.tar.bz2  $relativedirname
                if [ $? -ne 0 ]; then
                        echo "Error while archiving ${WHERE}/${n}.${WHEN}.tar.bz2"
                        exit 1

More information about the samba-technical mailing list