Skip to content
Snippets Groups Projects
Commit 98e62c95 authored by micah's avatar micah :speech_balloon:
Browse files

. make maildir helper look in every subdirectory of the source directory for

           maildirs, rather than just looking in the directories [a-zA-Z0-9], thanks
           for the patch from chris@cenolan.com (Trac#43)
parent 0a6abfc3
Branches
Tags
No related merge requests found
...@@ -34,7 +34,10 @@ version 0.9.6 -- unreleased ...@@ -34,7 +34,10 @@ version 0.9.6 -- unreleased
. New handler from rhatto designed to incrementally pull content from . New handler from rhatto designed to incrementally pull content from
a website to a local folder, based on the rsync handler a website to a local folder, based on the rsync handler
maildir: maildir:
. fixed bug where maildirs that start with a number were skipped. . fixed bug where maildirs that start with a number were skipped
. make maildir helper look in every subdirectory of the source directory for
maildirs, rather than just looking in the directories [a-zA-Z0-9], thanks
for the patch from chris@cenolan.com (Trac#43).
. make deleted maildirs record the date they were deleted . make deleted maildirs record the date they were deleted
. add destid_file configuration option to enable you to specify an alternate . add destid_file configuration option to enable you to specify an alternate
ssh public key authentication file (defaulting to /root/.ssh/id_rsa) ssh public key authentication file (defaulting to /root/.ssh/id_rsa)
......
...@@ -7,15 +7,33 @@ ...@@ -7,15 +7,33 @@
# in terms of cpu and bandwidth so it runs pretty slow. # in terms of cpu and bandwidth so it runs pretty slow.
# Hardlinking is used to save storage space. # Hardlinking is used to save storage space.
# #
# each users maildir will contain these files: # This handler expects that your maildir directory structure is
# either one of the following:
#
# 1. /$srcdir/[a-zA-Z0-9]/$user for example:
# /var/maildir/a/anarchist
# /var/maildir/a/arthur
# ...
# /var/maildir/Z/Zaphod
# /var/maildir/Z/Zebra
#
# 2. or the following:
# /var/maildir/domain.org/user1
# /var/maildir/domain.org/user2
# ...
# /var/maildir/anotherdomain.org/user1
# /var/maildir/anotherdomain.org/user2
# ...
#
# if the configuration is setup to have keepdaily at 3,
# keepweekly is 2, and keepmonthly is 1, then each user's
# maildir backup snapshot directory will contain these files:
# daily.1 # daily.1
# daily.2 # daily.2
# daily.3 # daily.3
# weekly.1 # weekly.1
# weekly.2 # weekly.2
# monthly.1 # monthly.1
# if keepdaily is 3, keepweekly is 2, and keepmonthly is 1.
# the actual maildir is stored within each snapshot directory.
# #
# The basic algorithm is to rsync each maildir individually, # The basic algorithm is to rsync each maildir individually,
# and to use hard links for retaining historical data. # and to use hard links for retaining historical data.
...@@ -53,7 +71,6 @@ getconf destid_file /root/.ssh/id_rsa ...@@ -53,7 +71,6 @@ getconf destid_file /root/.ssh/id_rsa
getconf multiconnection notset getconf multiconnection notset
letters="0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z"
failedcount=0 failedcount=0
# strip trailing / # strip trailing /
destdir=${destdir%/} destdir=${destdir%/}
...@@ -76,9 +93,9 @@ excludes="--exclude '.Trash/\*' --exclude '.Mistakes/\*' --exclude '.Spam/\*'" ...@@ -76,9 +93,9 @@ excludes="--exclude '.Trash/\*' --exclude '.Mistakes/\*' --exclude '.Spam/\*'"
function do_user() { function do_user() {
local user=$1 local user=$1
local btype=$2 local btype=$2
local letter=${user:0:1} local userdir=${3%/}
local source="$srcdir/$letter/$user/" local source="$srcdir/$userdir/$user/"
local target="$destdir/$letter/$user/$btype.1" local target="$destdir/$userdir/$user/$btype.1"
if [ ! -d $source ]; then if [ ! -d $source ]; then
warning "maildir $source not found" warning "maildir $source not found"
return return
...@@ -111,15 +128,16 @@ function do_remove() { ...@@ -111,15 +128,16 @@ function do_remove() {
local tmp1=`maketemp maildir-tmp-file` local tmp1=`maketemp maildir-tmp-file`
local tmp2=`maketemp maildir-tmp-file` local tmp2=`maketemp maildir-tmp-file`
ssh -p $destport -i $estid_file $destuser@$desthost mkdir -p "$destdir/deleted" ssh -p $destport -i $destid_file $destuser@$desthost mkdir -p "$destdir/deleted"
for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z; do cd "$srcdir"
ls -1 "$srcdir/$i/" | sort > $tmp1 for userdir in `ls -d1 */`; do
ssh -p $destport $destuser@$desthost ls -1 "$destdir/$i/" | sort > $tmp2 ls -1 "$srcdir/$userdir" | sort > $tmp1
ssh -p $destport $destuser@$desthost ls -1 "$destdir/$userdir" | sort > $tmp2
for deluser in `join -v 2 $tmp1 $tmp2`; do for deluser in `join -v 2 $tmp1 $tmp2`; do
[ "$deluser" != "" ] || continue [ "$deluser" != "" ] || continue
info "removing $destuser@$desthost:$destdir/$i/$deluser/" info "removing $destuser@$desthost:$destdir/$userdir$deluser/"
ssh -p $destport -i $destid_file $destuser@$desthost mv "$destdir/$i/$deluser/" "$destdir/deleted" ssh -p $destport $destuser@$desthost mv "$destdir/$userdir$deluser/" "$destdir/deleted"
ssh -p $destport -i $destid_file $destuser@$desthost "date +%c%n%s > '$destdir/$i/$deluser/deleted_on'" ssh -p $destport -i $destid_file $destuser@$desthost "date +%c%n%s > '$destdir/$userdir$deluser/deleted_on'"
done done
done done
rm $tmp1 rm $tmp1
...@@ -129,8 +147,8 @@ function do_remove() { ...@@ -129,8 +147,8 @@ function do_remove() {
function do_rotate() { function do_rotate() {
[ "$rotate" == "yes" ] || return; [ "$rotate" == "yes" ] || return;
local user=$1 local user=$1
local letter=${user:0:1} local userdir=${2%/}
local backuproot="$destdir/$letter/$user" local backuproot="$destdir/$userdir/$user"
( (
ssh -T -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file <<EOF ssh -T -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file <<EOF
##### BEGIN REMOTE SCRIPT ##### ##### BEGIN REMOTE SCRIPT #####
...@@ -227,9 +245,9 @@ EOF ...@@ -227,9 +245,9 @@ EOF
function setup_remote_dirs() { function setup_remote_dirs() {
local user=$1 local user=$1
local backuptype=$2 local backuptype=$2
local letter=${user:0:1} local userdir=${3%/}
local dir="$destdir/$letter/$user/$backuptype" local dir="$destdir/$userdir/$user/$backuptype"
local tmpdir="$destdir/$letter/$user/rotate.tmp" local tmpdir="$destdir/$userdir/$user/rotate.tmp"
( (
ssh -T -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file <<EOF ssh -T -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file <<EOF
if [ ! -d $destdir ]; then if [ ! -d $destdir ]; then
...@@ -331,16 +349,18 @@ if [ "$backup" == "yes" ]; then ...@@ -331,16 +349,18 @@ if [ "$backup" == "yes" ]; then
setup_remote_dirs $testuser $btype setup_remote_dirs $testuser $btype
do_user $testuser $btype do_user $testuser $btype
else else
for i in $letters; do [ -d "$srcdir" ] || fatal "directory $srcdir not found."
[ -d "$srcdir/$i" ] || fatal "directory $srcdir/$i not found." cd "$srcdir"
cd "$srcdir/$i" for userdir in `ls -d1 */`; do
debug $i [ -d "$srcdir/$userdir" ] || fatal "directory $srcdir/$userdir not found."
cd "$srcdir/$userdir"
debug $userdir
for user in `ls -1`; do for user in `ls -1`; do
[ "$user" != "" ] || continue [ "$user" != "" ] || continue
debug $user debug "$user $userdir"
do_rotate $user do_rotate $user $userdir
setup_remote_dirs $user $btype setup_remote_dirs $user $btype $userdir
do_user $user $btype do_user $user $btype $userdir
done done
done done
fi fi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment