最後更新: 2017-04-27
介紹
當 folder vmail1 不夠位時, 將 mailbox 搬去 folder vmail2
mv-mailbox.sh
#!/bin/bash # mailbox _USR=postmaster _DOM=example.com # DB Setting _dbuser= _dbpass= _db=vmail # folder _old_folder=vmail1 _new_folder=vmail2 #################################################### #################################################### #### SRC & DST _SRC=/home/vmail/$_old_folder/$_DOM/$_USR/ _DST=/home/vmail/$_new_folder/$_DOM/$_USR/ #### check folder if [ ! -d $_SRC ]; then echo "Source folder do not exist" exit fi #### first sync echo "First sync" rsync -a $_SRC $_DST #### lock user _sql_disable_user="UPDATE mailbox SET active=0 WHERE mailbox.username='$_USR@$_DOM' limit 1" echo $_sql_disable_user | mysql -u $_dbuser $_db -p$_dbpass doveadm kick $_USR@$_DOM #### re-sync echo "Re-sync" rsync --delete -a $_SRC $_DST #### update db & unlock user # update to DST _sql_set_storagenode="UPDATE mailbox SET storagenode='$_new_folder' WHERE mailbox.username='$_USR@$_DOM' limit 1" echo $_sql_set_storagenode | mysql -u $_dbuser $_db -p$_dbpass # unlock _sql_enable_user="UPDATE mailbox SET active=1 WHERE mailbox.username='$_USR@$_DOM' limit 1" echo $_sql_enable_user | mysql -u $_dbuser $_db -p$_dbpass #### check size _old_size=`find $_SRC -type f | wc -l` _new_size=`find $_DST -type f | wc -l` echo "Old: " $_old_size echo "New: " $_new_size #### remove old path if [[ x$_old_size = x$_new_size ]]; then echo "rm -rf $_SRC" fi