This commit is contained in:
Gero Müller 2017-06-12 10:45:18 +10:00
parent 611911c8b1
commit 90792e34f8
2 changed files with 14 additions and 21 deletions

View File

@ -7,13 +7,14 @@ set -e
cat > /etc/apt/sources.list <<EOF cat > /etc/apt/sources.list <<EOF
deb http://mirror.hetzner.de/debian/packages stretch main contrib non-free deb http://mirror.hetzner.de/debian/packages stretch main contrib non-free
deb http://mirror.hetzner.de/debian/security stretch/updates main contrib non-free
EOF EOF
apt update apt update
echo "Install important system tools." echo "Install important system tools."
apt install -y htop ne iotop curl wget zsh figlet iptraf borgbackup apt install -y htop ne iotop curl wget zsh figlet iptraf borgbackup systemd-cron apticron logwatch unattended-upgrades
echo "Use zsh!" echo "Use zsh!"
@ -42,10 +43,6 @@ hostname -F /etc/hostname
echo "Nice motd." echo "Nice motd."
figlet `hostname -f | sed 's/\./ \. /g'` > /etc/motd figlet `hostname -f | sed 's/\./ \. /g'` > /etc/motd
echo "Install system and security utils."
apt install -y systemd-cron apticron logwatch unattended-upgrades
apt install -y ssmtp apt install -y ssmtp
( exec ne /etc/ssmtp/* ) ( exec ne /etc/ssmtp/* )
@ -56,6 +53,7 @@ for i in {4..6}; do
systemctl disable getty@tty$i.service systemctl disable getty@tty$i.service
done done
echo "setup systembackup"
wget -q -O /usr/local/sbin/systembackup https://code.camijo.de/gmueller/server-scripts/raw/master/systembackup wget -q -O /usr/local/sbin/systembackup https://code.camijo.de/gmueller/server-scripts/raw/master/systembackup
if [ ! -f /etc/systembackup.conf ] then if [ ! -f /etc/systembackup.conf ] then
cat >>/etc/systembackup.conf <<EOF cat >>/etc/systembackup.conf <<EOF

View File

@ -1,29 +1,30 @@
#!/bin/bash #!/bin/bash
export PATH=/usr:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# FUNCTIONS # FUNCTIONS
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
cleanup() { cleanup() {
if [ "y" == "$MYSQL" ]; then if [ "y" == "$MYSQL" ]; then
umount -f /var/lib/mysql-snapshot || true /bin/umount -f /var/lib/mysql-snapshot || true
lvremove -f /dev/vg0/mysql-snapshot || true /sbin/lvremove -f /dev/vg0/mysql-snapshot || true
fi fi
} }
mount_snapshot() { mount_snapshot() {
echo "mounting /var/lib/mysql-snapshot..." echo "mounting /var/lib/mysql-snapshot..."
mkdir -p /var/lib/mysql-snapshot /bin/mkdir -p /var/lib/mysql-snapshot
mount /dev/vg0/mysql-snapshot /var/lib/mysql-snapshot /bin/mount /dev/vg0/mysql-snapshot /var/lib/mysql-snapshot
echo "mounted /var/lib/mysql-snapshot." echo "mounted /var/lib/mysql-snapshot."
} }
create_snapshot() { create_snapshot() {
echo "locking database..." echo "locking database..."
mysql << EOF /usr/bin/mysql --defaults-extra-file=/root/.my.cnf << EOF
FLUSH TABLES; FLUSH TABLES;
FLUSH TABLES WITH READ LOCK; FLUSH TABLES WITH READ LOCK;
system lvcreate --snapshot -n mysql-snapshot -L16G /dev/vg0/mysql system /sbin/lvcreate --snapshot -n mysql-snapshot -L16G /dev/vg0/mysql
UNLOCK TABLES; UNLOCK TABLES;
EOF EOF
echo "database locked" echo "database locked"
@ -35,7 +36,7 @@ EOF
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
if [ ! -f /etc/systembackup.conf ]; then if [ ! -f /etc/systembackup.conf ]; then
echo "systembackup not configured" echo "systembackup not configured (/etc/systembackup.conf)"
exit 1 exit 1
fi fi
@ -69,7 +70,7 @@ fi
# BACKUP # BACKUP
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
BORG_PASSPHRASE=$PASSPHRASE /usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 borg create --stats -v \ BORG_PASSPHRASE=$PASSPHRASE /usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 /usr/bin/borg create --stats -v \
$REPOSITORY::'{hostname}-{now:%Y-%m-%d-%H}' \ $REPOSITORY::'{hostname}-{now:%Y-%m-%d-%H}' \
/ \ / \
--compression lzma \ --compression lzma \
@ -91,12 +92,6 @@ BORG_PASSPHRASE=$PASSPHRASE /usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 borg cre
# PRUNE # PRUNE
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
BORG_PASSPHRASE=$PASSPHRASE /usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 borg prune -v --list $REPOSITORY --prefix '{hostname}-' \ BORG_PASSPHRASE=$PASSPHRASE /usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 /usr/bin/borg prune -v --list $REPOSITORY --prefix '{hostname}-' \
--keep-hourly=6 --keep-daily=7 --keep-weekly=4 --keep-monthly=6 --keep-hourly=6 --keep-daily=7 --keep-weekly=4 --keep-monthly=6
# ----------------------------------------------------------------------------
# CLEANUP
# ----------------------------------------------------------------------------
cleanup