Initial commit
This commit is contained in:
147
OLD/sync_to_a-neu.mx.sh
Executable file
147
OLD/sync_to_a-neu.mx.sh
Executable file
@@ -0,0 +1,147 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
_target_hostname=a-neu.mx.oopen.de
|
||||
|
||||
_databases="postfix roundcubemail roundcubemail2 roundcubemail-alt"
|
||||
_web_dirs="adm.oopen.de webmail2.oopen.de webmail-alt.oopen.de webmail.oopen.de webmail-opcache.oopen.de"
|
||||
|
||||
# -------------
|
||||
# --- Some functions
|
||||
# -------------
|
||||
echononl(){
|
||||
echo X\\c > /tmp/shprompt$$
|
||||
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
|
||||
echo -e -n "$*\\c" 1>&2
|
||||
else
|
||||
echo -e -n "$*" 1>&2
|
||||
fi
|
||||
rm /tmp/shprompt$$
|
||||
}
|
||||
error(){
|
||||
echo ""
|
||||
echo -e "\t[ \033[31m\033[1mFehler\033[m ]: $*"
|
||||
echo ""
|
||||
}
|
||||
|
||||
warn (){
|
||||
echo ""
|
||||
echo -e "\t[ \033[33m\033[1mWarning\033[m ]: $*"
|
||||
echo ""
|
||||
}
|
||||
|
||||
info (){
|
||||
echo ""
|
||||
echo -e "\t[ \033[32m\033[1mInfo\033[m ]: $*"
|
||||
echo ""
|
||||
}
|
||||
|
||||
echo_done() {
|
||||
echo -e "\033[80G[ \033[32mdone\033[m ]"
|
||||
}
|
||||
echo_ok() {
|
||||
echo -e "\033[80G[ \033[32mok\033[m ]"
|
||||
}
|
||||
echo_warning() {
|
||||
echo -e "\033[80G[ \033[33m\033[1mwarn\033[m ]"
|
||||
}
|
||||
echo_failed(){
|
||||
echo -e "\033[80G[ \033[1;31mfailed\033[m ]"
|
||||
}
|
||||
echo_skipped() {
|
||||
echo -e "\033[80G[ \033[33m\033[1mskipped\033[m ]"
|
||||
}
|
||||
|
||||
|
||||
echo ""
|
||||
echononl " Syncing /var/QUARANTINE"
|
||||
rsync -a -e ssh --delete /var/QUARANTINE ${_target_hostname}:/var/ > /dev/null 2>&1
|
||||
if [[ "$?" = "0" ]]; then
|
||||
echo_ok
|
||||
else
|
||||
echo_failed
|
||||
fi
|
||||
|
||||
echononl " Syncing /var/deleted-maildomains.."
|
||||
rsync -a -e ssh --delete /var/deleted-maildomains ${_target_hostname}:/var/ > /dev/null 2>&1
|
||||
if [[ "$?" = "0" ]]; then
|
||||
echo_ok
|
||||
else
|
||||
echo_failed
|
||||
fi
|
||||
|
||||
echononl " Syncing /var/deleted-maildirs.."
|
||||
rsync -a -e ssh --delete /var/deleted-maildirs ${_target_hostname}:/var/ > /dev/null 2>&1
|
||||
if [[ "$?" = "0" ]]; then
|
||||
echo_ok
|
||||
else
|
||||
echo_failed
|
||||
fi
|
||||
|
||||
echononl " Syncing /var/vmail.."
|
||||
rsync -a -e ssh --delete /var/vmail ${_target_hostname}:/var/ > /dev/null 2>&1
|
||||
if [[ "$?" = "0" ]]; then
|
||||
echo_ok
|
||||
else
|
||||
echo_failed
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
for _db in $_databases ; do
|
||||
_dump_file="/tmp/$_db-`date +%Y%m%d-%H%M`".sql
|
||||
echononl " Dumping Database $_db"
|
||||
su - postgres -c "pg_dump -c -C $_db" > $_dump_file 2> /dev/null
|
||||
if [[ "$?" = "0" ]]; then
|
||||
echo_ok
|
||||
else
|
||||
echo_failed
|
||||
fi
|
||||
|
||||
echononl " Copy Dumpfile $_db to ${_target_hostname}"
|
||||
scp $_dump_file ${_target_hostname}:/tmp >/dev/null 2>&1
|
||||
if [[ "$?" = "0" ]]; then
|
||||
echo_ok
|
||||
else
|
||||
echo_failed
|
||||
fi
|
||||
|
||||
echononl " Delete Dumpfile $_db here.."
|
||||
rm $_dump_file >/dev/null 2>&1
|
||||
if [[ "$?" = "0" ]]; then
|
||||
echo_ok
|
||||
else
|
||||
echo_failed
|
||||
fi
|
||||
|
||||
echononl " Restore Database $_db at ${_target_hostname}"
|
||||
ssh ${_target_hostname} "su - postgres -c \"psql < $_dump_file\" > /dev/null 2>&1"
|
||||
if [[ "$?" = "0" ]]; then
|
||||
echo_ok
|
||||
else
|
||||
echo_failed
|
||||
fi
|
||||
|
||||
echononl " Delete Dumpfile $_db at ${_target_hostname}.."
|
||||
ssh ${_target_hostname} "rm $_dump_file" >/dev/null 2>&1
|
||||
if [[ "$?" = "0" ]]; then
|
||||
echo_ok
|
||||
else
|
||||
echo_failed
|
||||
fi
|
||||
|
||||
echo ""
|
||||
done
|
||||
|
||||
for _dir in $_web_dirs ; do
|
||||
echononl " Syncing /var/www/${_dir}"
|
||||
rsync -a -e ssh --delete /var/www/$_dir ${_target_hostname}:/var/www/ > /dev/null 2>&1
|
||||
if [[ "$?" = "0" ]]; then
|
||||
echo_ok
|
||||
else
|
||||
echo_failed
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
echo ""
|
||||
exit 0
|
||||
Reference in New Issue
Block a user