-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestoreDirMailbox.pl
executable file
·146 lines (109 loc) · 3.73 KB
/
restoreDirMailbox.pl
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/perl -w
use strict;
####### MAIN ##########
my $account = shift;
my $backupId = shift;
my $backupIdFull ='';
my (@listedir) = @ARGV;
checkParam();
restoreAccountBak();
foreach (@listedir){
saveDirAccountBak($_);
restoreDirAccount($_);
}
delAccountBak();
#Full backup for an account
#zmbackup -f - demo1.domain.com -a [email protected]
#Restore
#zmrestore -a $account -lb $backupIdFULL -ca -pre bak_
#zmrestore -a $account -restoreToIncrLabel $backupId -lb $backupIdFull -br -ca -pre bak_
#Create directory into inbox
#zmmailbox -z -m [email protected] cf /inbox/Rep
#Rename directory
#zmmailbox -z -m [email protected] rf /inbox/toto/foo /inbox/toto/foo_bak
##############################
#Check script parameters
sub checkParam{
if(($account && $account =~ /^[^ ]+@[^ ]+$/) && (!$backupId) ){
print `zmbackupquery -a $account`;
exit 0;
}
if(($account && $account =~ /^[^ ]+@[^ ]+$/) && ($backupId && $backupId =~ /^(full|incr)[^ ]+$/) && (@listedir && $#listedir >= 0)){
if ($backupId =~ /^incr[^ ]+$/){
my @query = `zmbackupquery -a $account`;
my $flag = 0;
foreach (@query){
$flag = 1 if $_ =~ /^[ ]+Label:[ ]+$backupId/;
if($_ =~ /^[ ]+Label:[ ]+(full.*)/ && $flag eq 1){
$backupIdFull = $1;
chomp($backupIdFull);
last;
}
}
if(!$backupIdFull || $backupIdFull eq ''){
echo_red("backup full non trouvé");
exit 0;
}
}
return 1;
}
echo_white("$0 <user\@domain.com> <LabelBackup> <dir/subdir...>");
echo_blue("\t<dir/subdir> : For a directory into \"Boite de Reception\" you have to prefix with ",1); echo_red("inbox/",1); echo_blue(" example inbox/dir/sudir");
exit 0;
}
### restore account to bak_compte
sub restoreAccountBak{
echo_green("restoreAccountBak $account --> bak_$account");
# print "zmrestore -a $account -ca -pre bak_\n";
if($backupIdFull eq ''){
print `zmrestore -a $account -lb $backupId -ca -pre bak_`;
}else{
print `zmrestore -a $account -restoreToIncrLabel $backupId -lb $backupIdFull -br -ca -pre bak_`;
}
}
### Backup account directory in /tmp
sub saveDirAccountBak{
my $dir = shift;
echo_green("saveDirAccountBak - $dir");
# print `zmmailbox -z -m bak_$account rf /inbox/$dir /inbox/$dir\_bak`;
print `zmmailbox -z -m bak_$account rf "/$dir" "/$dir\_bak"`;
# print `zmmailbox -z -m bak_$account getRestURL "/inbox/$dir\_bak?fmt=zip" > /tmp/$account.zip`;
print `zmmailbox -z -m bak_$account getRestURL "/$dir\_bak?fmt=zip" > /tmp/$account.zip`;
}
### Restore directory in rep_bak
sub restoreDirAccount{
my $dir = shift;
echo_green("restoreDirAccount - $dir");
# print "zmmailbox -z -m $account postRestURL \"/?fmt=zip\" /tmp/$account.zip\n";
print `zmmailbox -z -m $account postRestURL "/?fmt=zip" /tmp/$account.zip`;
}
### Delete account_bak
sub delAccountBak{
echo_green("delAccountBak - bak_$account");
# print "zmprov da bak_$account\n";
print `zmprov da bak_$account`;
}
sub echo_red {
print defined($_[1]) ? "\033[0;31m$_[0]\033[0;37m" : "\033[0;31m$_[0]\033[0;37m\n";
}
sub echo_green {
print defined($_[1]) ? "\033[0;32m$_[0]\033[0;37m" : "\033[0;32m$_[0]\033[0;37m\n";
}
sub echo_yellow {
print defined($_[1]) ? "\033[0;33m$_[0]\033[0;37m" : "\033[0;33m$_[0]\033[0;37m\n";
}
sub echo_blue {
print defined($_[1]) ? "\033[0;34m$_[0]\033[0;37m" : "\033[0;34m$_[0]\033[0;37m\n";
}
sub echo_pink {
print defined($_[1]) ? "\033[0;35m$_[0]\033[0;37m" : "\033[0;35m$_[0]\033[0;37m\n";
}
sub echo_cyan {
print defined($_[1]) ? "\033[0;36m$_[0]\033[0;37m" : "\033[0;36m$_[0]\033[0;37m\n";
}
sub echo_white {
print defined($_[1]) ? "\033[0;37m$_[0]\033[0;37m" : "\033[0;37m$_[0]\033[0;37m\n";
}
sub echo_grey {
print defined($_[1]) ? "\033[1;30m$_[0]\033[0;37m" : "\033[1;30m$_[0]\033[0;37m\n";
}