summaryrefslogtreecommitdiff
path: root/upgrade-to-3.0-native-from-2.3-openpkg/00-sync-from-kolab2.sh
blob: b1bf6a2fa12fcd257f4b5a49b6baaf8bbfe195d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash

 . ./settings.sh

set_file_permissions=0

while [ $# -gt 0 ]; do
    case $1 in
        --fix-perms|--fix-permissions)
            set_file_permissions=1
            shift
        ;;
    esac
done

service cyrus-imapd stop

rm -rf /var/lib/imap/annotations.db

rsync -rltHvz --delete --partial --progress ${kolab2_base}/mailboxes.db /var/lib/imap/mailboxes.db

rsync -rltHvz --delete --partial --progress ${kolab2_base}/domain/ /var/lib/imap/domain/

rsync -rltHvz --delete --partial --progress ${kolab2_base}/spool/ /var/spool/imap/

chown -R cyrus:mail /var/lib/imap /var/spool/imap

if [ ${set_file_permissions} -eq 1 ]; then
    count_start=`date +'%s'`

    echo -n "Counting files... "
    total_files=`find /var/lib/imap /var/spool/imap -type f | wc -l`
    count_end=`date +'%s'`
    echo "DONE. (${total_files} in $(( ${count_end} - ${count_start} )) seconds)"

    last_percent=0
    i=0
    find /var/lib/imap /var/spool/imap -type f | while read file; do
        chmod 640 "${file}"
        let i++
        percent=$(( ${i} * 100 / ${total_files} ))
        if [ ${percent} -gt ${last_percent} ]; then
            echo "${percent}% completed."
            last_percent=${percent}
        fi
    done

    echo -n "Counting dirs... "
    total_dirs=`find /var/lib/imap /var/spool/imap -type d | wc -l`
    echo "DONE."

    last_percent=0
    i=0
    find /var/lib/imap /var/spool/imap -type d | while read dir; do
        chmod 750 "${dir}"
        let i++
        percent=$(( ${i} * 100 / ${total_files} ))
        if [ ${percent} -gt ${last_percent} ]; then
            echo "${percent}% completed."
            last_percent=${percent}
        fi
    done

fi
rsync -aHvz --delete --progress --link-dest /var/lib/imap/ /var/lib/imap/ /var/lib/imap.orig/
rsync -aHvz --delete --progress --link-dest /var/spool/imap/ /var/spool/imap/ /var/spool/imap.orig/