Commit a66269b6 authored by Ophélie Gagnard's avatar Ophélie Gagnard

douai: Add backup scripts.

Modify slightly scripts from hydro66
parent 648e186f
#!/bin/sh
set -e
h=douai-capri-`printf %03u $1`
ip=192.168.46.$((50+$1))
mkdir -p $h
cd $h
SSH='ssh -o BatchMode=yes -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
R=/re6stnet.tar.xz
O=/etc-opt.tar.xz
$SSH $ip "set -e; umask 077; cd /etc; tar -caf $R re6stnet; tar -caf $O opt"
rsync -e "$SSH" -av $ip:$R $ip:$O $ip:/opt/slapos/slapos.xml $ip:/etc/network/interfaces .
sed -ri '/^auto ens1$/,$!d; s/(dns-nameservers).*/\1 80.80.80.80 80.80.81.81/' interfaces
#!/usr/bin/python3
# apt install dnsmasq-base python3-bottle python3-gevent
import argparse, os, signal, subprocess, sys
from bottle import default_app, route, static_file
from gevent import pywsgi
from ctypes import CDLL, util as ctypes_util, get_errno, c_int, c_long
libc = CDLL(ctypes_util.find_library('c'), use_errno=True)
class Prctl(object):
def __init__(self, option, nargs):
self.option = option
self.args0 = (0,) * (4 - nargs)
def __call__(self, *args):
try:
prctl = self._prctl
except AttributeError:
prctl = self._prctl = libc.prctl
prctl.argtypes = c_int, c_long, c_long, c_long, c_long
r = prctl(self.option, *(args + self.args0))
if r == -1:
e = get_errno()
raise OSError(e, os.strerror(e))
return r
PR_SET_PDEATHSIG = Prctl(1, 1)
def killIfParentDies(ppid=os.getpid()):
PR_SET_PDEATHSIG(signal.SIGTERM)
if os.getppid() != ppid: # check race
sys.exit(1)
CWD = os.getcwd()
@route('/<p:re:.+/.+>')
def static(p):
return static_file(p, root=CWD)
def main():
parser = argparse.ArgumentParser()
_ = parser.add_argument
_('-p', '--port', type=int, default=69)
_('host')
_('dnsmasq', nargs=argparse.REMAINDER)
args = parser.parse_args()
host = args.host
iface = subprocess.check_output(('ip', '-o', 'address', 'show', 'to', host),
universal_newlines=True).split()[1]
cmd = ['dnsmasq', '-d', '--enable-tftp', '--tftp-root=' + CWD,
'--interface=' + iface, '--listen-address=' + host]
cmd += args.dnsmasq
subprocess.Popen(cmd, preexec_fn=killIfParentDies)
try:
pywsgi.WSGIServer((host, args.port), default_app()).serve_forever()
except KeyboardInterrupt:
pass
if __name__ == '__main__':
sys.exit(main())
#!/bin/sh
set -e
cd douai-capri-`printf %03u $1`
ip=10.0.45.$((50+$1))
SSH='ssh -o BatchMode=yes -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
$SSH $ip reboot
#!/bin/sh
set -e
h=douai-capri-`printf %03u $1`
ip=192.168.46.$((50+$1))
cd $h
SSH='ssh -o BatchMode=yes -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
rsync -e "$SSH" -av etc-opt.tar.xz re6stnet.tar.xz slapos.xml $ip:
$SSH $ip 'set -e; systemctl stop cron; mkdir /opt/slapos; mv slapos.xml /opt/slapos; cd /etc; for x in ~/etc-opt.tar.xz ~/re6stnet.tar.xz; do tar -xaf $x; rm $x; done; cd; wget https://deploy.erp5.net/vifib-base; bash vifib-base; cd /etc/opt/slapos/ssl/partition_pki; for x in *; do y=${x%.*}; y=${y#slappart}; [ "$y" = "*" ] || chown slapuser$y: "$x"; done'
rsync -e "$SSH" -a /opt/slapgrid/f8b3d5ce4f68c34837520c8843c6b2fd $ip:/opt/slapgrid/
$SSH $ip systemctl start cron
#!/bin/sh
exec ./pxe 192.168.46.50 --port=0 --log-dhcp \
--dhcp-range=192.168.46.200,192.168.46.239,255.255.255.0,infinite \
--dhcp-option=option:router,192.168.46.1 \
--dhcp-option=option:dns-server,80.80.80.80,80.80.81.81 \
--dhcp-boot=debian-installer/amd64/grubx64.efi
#!/bin/sh
set -e
cd douai-capri-`printf %03u $1`
ip=10.0.45.$((50+$1))
SSH='ssh -o BatchMode=yes -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
$SSH $ip 'set -e; systemctl stop cron; set -- `pgrep -f /usr/sbin/CRON`; x=$*; x=${x// /,}; while pgrep -f "/opt/slapos/bin/slapos node instance" -P $x; do sleep 1; done >/dev/null; slapos node supervisorctl shutdown; while [ "`lsof +d /srv/slapgrid`" ]; do sleep 1; done'
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment