Support for sync jail on other node
This commit is contained in:
parent
65d2b291cc
commit
d809f01606
26
bkctl
26
bkctl
|
@ -24,6 +24,7 @@ sub_help(){
|
|||
echo " stop <jailname>"
|
||||
echo " reload <jailname>"
|
||||
echo " restart <jailname>"
|
||||
echo " sync <jailname>"
|
||||
echo " status [<jailname>]"
|
||||
echo " key <jailname> [<keyfile>]"
|
||||
echo " port <jailname> [<ssh_port>]"
|
||||
|
@ -199,6 +200,27 @@ sub_status() {
|
|||
echo "$jail $status $port $inc $ip"
|
||||
}
|
||||
|
||||
sub_sync() {
|
||||
set -e
|
||||
if [ -z $NODE ]; then
|
||||
echo "You must define \$NODE in /etc/default/evobackup !" >&2
|
||||
exit 1
|
||||
fi
|
||||
jail=$1
|
||||
check_jail $jail
|
||||
port=$(get_port $jail)
|
||||
key=$(get_key $jail)
|
||||
rsync -a ${CONFDIR}/$jail $NODE:${CONFDIR}/$jail
|
||||
bkctl key $jail > /tmp/evobackup-${jail}.pub
|
||||
rsync -a /tmp/evobackup-${jail}.pub $NODE:/tmp/evobackup-${jail}.pub
|
||||
ssh $NODE bkctl init $jail
|
||||
ssh $NODE bkctl port $jail $port
|
||||
ssh $NODE bkctl key $jail /tmp/evobackup-${jail}.pub
|
||||
for ip in $(get_ip $jail); do
|
||||
ssh $NODE bkctl ip $jail $ip
|
||||
done
|
||||
}
|
||||
|
||||
sub_inc() {
|
||||
date=$(date +"%Y-%m-%d-%H")
|
||||
for jail in $(ls -1 $CONFDIR); do
|
||||
|
@ -322,7 +344,7 @@ get_ip() {
|
|||
set_ip() {
|
||||
jail=$1
|
||||
ip=$2
|
||||
if [ $ip = "all" ]; then
|
||||
if [[ $ip = "all" || $ip = "0.0.0.0/0" ]]; then
|
||||
ips="0.0.0.0/0"
|
||||
else
|
||||
ips=$(get_ip $jail)
|
||||
|
@ -369,7 +391,7 @@ main() {
|
|||
fi
|
||||
sub_${subcommand} $jail $option
|
||||
;;
|
||||
"start" | "stop" | "reload" | "restart")
|
||||
"start" | "stop" | "reload" | "restart" | "sync")
|
||||
if [ -z $jail ]; then
|
||||
sub_help
|
||||
exit 1
|
||||
|
|
42
jail_init.sh
42
jail_init.sh
|
@ -1,42 +0,0 @@
|
|||
#!/bin/bash
|
||||
#!! Need export JAIL="jailName"
|
||||
|
||||
|
||||
ipBackup1=198.51.100.10
|
||||
ipBackup2=198.51.100.20
|
||||
|
||||
# Start jail.
|
||||
echo -e "\e[34mStarting jail...\e[39m"
|
||||
mount -t proc proc-chroot /backup/jails/$JAIL/proc/
|
||||
mount -t devtmpfs udev /backup/jails/$JAIL/dev/
|
||||
mount -t devpts devpts /backup/jails/$JAIL/dev/pts
|
||||
chroot /backup/jails/$JAIL /usr/sbin/sshd > /dev/null
|
||||
# Plan-sauvegardes.
|
||||
echo -e "$(grep Port /backup/jails/$JAIL/etc/ssh/sshd_config |cut -d ' ' -f 2) $JAIL ($(grep AllowUsers /backup/jails/$JAIL/etc/ssh/sshd_config |cut -d ' ' -f 2 |cut -d '@' -f 2))\n" >> PLAN-SAUVEGARDES
|
||||
# File for incs.
|
||||
echo -e "\e[34mCreate file inc config...\e[39m"
|
||||
cp inc.tpl /etc/evobackup/$JAIL
|
||||
# iptables rules.
|
||||
echo -e "\e[34mAdd iptables rule...\e[39m"
|
||||
echo -e "# $JAIL\n/sbin/iptables -A INPUT -p tcp --sport 1024: --dport $(grep Port /backup/jails/${JAIL}/etc/ssh/sshd_config |cut -d ' ' -f 2) -s $(grep AllowUsers /backup/jails/${JAIL}/etc/ssh/sshd_config |cut -d ' ' -f 2 |cut -d '@' -f 2) -j ACCEPT" >> /etc/firewall.rc.jails
|
||||
/etc/init.d/minifirewall restart
|
||||
|
||||
# Create the jail on the second server.
|
||||
echo -e "\e[34mDeploy on second server...\e[39m"
|
||||
rsync -a --exclude='var/backup/**' --exclude='proc/**' --exclude='dev/**' /backup/jails/$JAIL/ ${ipBackup2}:/backup/jails/$JAIL/
|
||||
rsync -a /etc/evobackup/$JAIL ${ipBackup2}:/etc/evobackup/
|
||||
rsync -a /etc/firewall.rc.jails ${ipBackup2}:/etc/
|
||||
ssh ${ipBackup2} "
|
||||
mount -t proc proc-chroot /backup/jails/$JAIL/proc/
|
||||
mount -t devtmpfs udev /backup/jails/$JAIL/dev/
|
||||
mount -t devpts devpts /backup/jails/$JAIL/dev/pts
|
||||
chroot /backup/jails/$JAIL /usr/sbin/sshd > /dev/null
|
||||
/etc/init.d/minifirewall restart
|
||||
"
|
||||
echo -e "\e[32mDone!\e[39m"
|
||||
|
||||
# Information to user
|
||||
|
||||
echo "You can add these iptables rules to backuped server:"
|
||||
echo /sbin/iptables -A INPUT -p tcp --sport $(grep Port /backup/jails/${JAIL}/etc/ssh/sshd_config |cut -d ' ' -f 2) --dport 1024:65535 -s $ipBackup1 -m state --state ESTABLISHED,RELATED -j ACCEPT
|
||||
echo /sbin/iptables -A INPUT -p tcp --sport $(grep Port /backup/jails/${JAIL}/etc/ssh/sshd_config |cut -d ' ' -f 2) --dport 1024:65535 -s $ipBackup2 -m state --state ESTABLISHED,RELATED -j ACCEPT
|
Loading…
Reference in a new issue