Migrando masivamente contenido de cuentas de correo con Imapsync

M

 

En ocasiones requerimos migrar masivamente el contenido de las cuentas de correo de un servidor a otro. Para este caso usaremos Imapsync. 

Usaremos un script con este objetivo y un archivo plano llamado file.txt que contiene las variables

#!/bin/sh
#

## Fuente
##http://www.linuxbrigade.com/migrate-mail-one-server-another-imapsync/

# $Id: sync_loop_unix.sh,v 1.8 2018/02/12 21:53:40 gilles Exp gilles $

# Example for imapsync massive migration on Unix systems.
# See also http://imapsync.lamiral.info/FAQ.d/FAQ.Massive.txt
#
# Data is supposed to be in file.txt in the following format:
# host001_1;user001_1;password001_1;host001_2;user001_2;password001_2;
# ...
# Separator is character semi-colon ";" it can be changed by any character changing IFS=';'
# in the while loop below.
# # Each line contains 6 columns, columns are parameter values for
# --host1 --user1 --password1 --host2 --user2 --password2
# and a trailing empty fake column to avoid CR LF part going
# in the 6th parameter password2. Don't forget the last semicolon.
#
# You can add extra options after the variable "$@"
# Use character backslash \ at the end of each supplementary line, except for the last one.
# You can also pass extra options via the parameters of this script since
# they will be in "$@"

# The credentials filename "file.txt" used for the loop can be renamed
# by changing "file.txt" below.


# Si solo quisieramos buscar e los ultimos mensajes
--search "SENTSINCE 22-Mar-2018"

#Para eliminar los mensajes que no estan en el origen en el destino...pudieron ya ser borrados
--delete2 

## Para evitar duplicacion
--nosyncacls --syncinternaldates 



echo Looping on account credentials found in file.txt
echo

{ while IFS=';' read  h1 u1 p1 h2 u2 p2 fake
    do
        { echo "$h1" | tr -d '\r' | egrep '^#|^ *$' ; } > /dev/null && continue # this skip commented lines in file.txt
        echo "==== Starting imapsync from host1 $h1 user1 $u1 to host2 $h2 user2 $u2 ===="
        imapsync --nosyncacls --syncinternaldates --host1 "$h1" --user1 "$u1" --password1 "$p1" \
                 --host2 "$h2" --user2 "$u2" --password2 "$p2" --fast  --tmpdir ~ --useuid --nofoldersizes --delete2  \
                 "$@"
        echo "==== Ended imapsync from host1 $h1 user1 $u1 to host2 $h2 user2 $u2 ===="
        echo
    done
} < file.txt

 

file.txt tendría el siguiente formato

# Example file.txt for imapsync massive migration.
#
# $Id: file.txt,v 1.14 2018/02/11 13:42:58 gilles Exp gilles $ 
#
# Each line contains 6 columns, columns are parameters for 
# --host1 --user1 --password1 --host2 --user2 --password2
# and a trailing empty fake column to avoid CR LF part going 
# in the 6th parameter password2. Don't forget the last semicolon.
#
# Windows: see the script examples/sync_loop_windows.bat 
# Unix:    see the script examples/sync_loop_unix.sh 
#
# Lines starting with a # are comments and ignored
# Blank lines are ignored as well


# Now the data example 
host001_1;user001_1;password001_1;host001_2;user001_2;password001_2;
host002_1;user002_1;password002_1;host002_2;user002_2;password002_2;
host003_1;user003_1;password003_1;host003_2;user003_2;password003_2;

# Another comment blabla
host004_1;user004_1;password004_1;host004_2;user004_2;password004_2;

# This last example is a real one, ie, truly working in the real world.
test1.lamiral.info;test1;secret1;test2.lamiral.info;test2;secret2;

 

 

 

Sobre el autor

Enviar Comentario

Por admin

Entradas recientes

Comentarios recientes

Archivos

Categorías

Meta

admin

Get in touch

Quickly communicate covalent niche markets for maintainable sources. Collaboratively harness resource sucking experiences whereas cost effective meta-services.