diff --git a/examples/example.rdiff b/examples/example.rdiff
index 323b3ebec99e4a0c7c00b0bdf504670785ba0113..00629842dc4e7ca15a8024afcb8500bfb41c8cfe 100644
--- a/examples/example.rdiff
+++ b/examples/example.rdiff
@@ -66,6 +66,12 @@
 ##
 ## Default:
 # output_as_info = no
+#
+
+# temporary directory used by rdiff-backup
+# (default = /tmp or /usr/tmp, depending on the system)
+#tempdir = /tmp
+
 
 ######################################################
 ## source section
diff --git a/handlers/rdiff.in b/handlers/rdiff.in
index 2a06d2ec8cecd0dd13aa8fd32d83f8c41ae6e847..7adecc8413a967ca0557645380aa8a7381539b61 100644
--- a/handlers/rdiff.in
+++ b/handlers/rdiff.in
@@ -86,6 +86,7 @@ getconf nicelevel 0
 getconf bwlimit
 getconf ignore_version no
 getconf output_as_info no
+getconf tempdir
 
 setsection source
 getconf type; sourcetype=$type
@@ -214,6 +215,18 @@ fi
 
 execstr="$RDIFFBACKUP $options --print-statistics "
 
+### Temporary directory
+if [ -n "$tempdir" ]; then
+   if [ ! -d "$tempdir" ]; then
+      info "Temporary directory ($tempdir) does not exist, creating it."
+      mkdir -p "$tempdir"
+      [ $? -eq 0 ] || fatal "Could not create temporary directory ($tempdir)."
+      chmod 0700 "$tempdir"
+   fi
+   info "Using $tempdir as TEMPDIR"
+   execstr="${execstr} --tempdir '$tempdir' "
+fi
+
 set -o noglob
 
 symlinks_warning="Maybe you have mixed symlinks and '*' in this statement, which is not supported."