今天是个好日子
因此,我尝试在 Zimbra 服务器上执行备份,并找到了文档(Zimbra 备份程序) 并意识到脚本无法正常工作。
来自文档的脚本
运行备份所有.sh:
echo "*******************************************************"
echo "* Zimbra - Backup all email accounts *"
echo "*******************************************************"
echo""
#
echo Start time of the backup = $(date +%T)
before="$(date +%s)"
#
echo ""
ZHOME=/opt/zimbra
ZBACKUP=$ZHOME/backup/mailbox
echo "Generating backup files ..."
su - zimbra -c "/opt/backup/SCRIPT_ZIBRA_BACKUP_ALL_ACCOUNTS/zimbra_backup_allaccounts.sh"
echo "Sending files to backup all email accounts for Machine2 (10.0.0.X - CrossOver Cable on eth1 \o/ ) ..."
rsync -avH $ZBACKUP root@ipaddress:/opt/zimbra_backup_accounts
before2="$(date +%s)"
#
echo The process lasted = $(date +%T)
# Calculating time
after="$(date +%s)"
elapsed="$(expr $after - $before)"
hours=$(($elapsed / 3600))
elapsed=$(($elapsed - $hours * 3600))
minutes=$(($elapsed / 60))
seconds=$(($elapsed - $minutes * 60))
echo The complete backup lasted : "$hours hours $minutes minutes $seconds seconds"
第二个脚本:
* Script 2
zimbraBackupAllAccounts.sh
ZHOME=/opt/zimbra
ZBACKUP=$ZHOME/backup/mailbox
ZCONFD=$ZHOME/conf
DATE=`date +"%a"`
ZDUMPDIR=$ZBACKUP/$DATE
ZMBOX=/opt/zimbra/bin/zmmailbox
if [ ! -d $ZDUMPDIR ]; then
mkdir -p $ZDUMPDIR
fi
echo " Running zmprov ... "
for mbox in `zmprov -l gaa`
do
echo " Generating files from backup $mbox ..."
$ZMBOX -z -m $mbox getRestURL "//?fmt=zip" > $ZDUMPDIR/$mbox.zip
done
此脚本在此部分失败。
echo " Running zmprov ... "
for mbox in `zmprov -l gaa`
do
echo " Generating files from backup $mbox ..."
$ZMBOX -z -m $mbox getRestURL "//?fmt=zip" > $ZDUMPDIR/$mbox.zip
以下命令返回...
zm邮箱-z-m[电子邮件保护] -t 0 getRestURL "/inbox?fm 错误:zclient.IO_ERROR(无法从https://FQDN/home/[电子邮件保护]/收件箱?fmt=zip:FQDN)(原因:java.net.UnknownHostException FQDN)
我注意到当我通过网络界面登录时我可以下载自己的电子邮件。https://mail.somedomain.com/home/bob///?fmt=tgz。
不过,我需要能够访问所有这些帐户,而且显然无需登录每个帐户。
我如何备份所有人的电子邮件?据我了解,该脚本失败是因为它需要一个 FQDN,但我无法设置此参数,或者至少从我尝试过的方法来看,没有结果。
答案1
因此有一种方法可以在脚本中指定主机名。我制作了这个,您可以随意复制和使用。以 zimbra 用户身份运行它。
#!/bin/bash
#check that only the Zimbra user runs this.
if [ "$(whoami)" != "zimbra" ]; then
echo "Script must be run as user: zimbra"
exit -1
fi
echo " Running zmprov ... "
for mbox in `zmprov -l gaa`
do
echo " Generating files from backup $mbox ..."
zmmailbox -z -m $mbox getRestURL -u "https://example.com" "//?fmt=zip" > "/opt/zimbra/backup/dump/backup_${mbox}.zip"
done