Release of EvoBSD 6.8.0 #37
|
@ -1,177 +1,368 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Script Evobackup client
|
||||||
|
# See https://gitea.evolix.org/evolix/evobackup
|
||||||
|
#
|
||||||
|
# Author: Gregory Colpart <reg@evolix.fr>
|
||||||
|
# Contributors:
|
||||||
|
# Romain Dessort <rdessort@evolix.fr>
|
||||||
|
# Benoît Série <bserie@evolix.fr>
|
||||||
|
# Tristan Pilat <tpilat@evolix.fr>
|
||||||
|
# Victor Laborie <vlaborie@evolix.fr>
|
||||||
|
# Jérémy Lecour <jlecour@evolix.fr>
|
||||||
|
#
|
||||||
|
# Licence: AGPLv3
|
||||||
|
#
|
||||||
|
# /!\ DON'T FORGET TO SET "MAIL" and "SERVERS" VARIABLES
|
||||||
|
|
||||||
#
|
# Fail on unassigned variables
|
||||||
# Script Evobackup plus ou moins forké
|
set -u
|
||||||
# See https://forge.evolix.org/projects/evobackup
|
|
||||||
#
|
##### Configuration ###################################################
|
||||||
|
|
||||||
|
# email adress for notifications
|
||||||
|
MAIL=jdoe@example.com
|
||||||
|
|
||||||
|
# list of hosts (hostname or IP) and SSH port for Rsync
|
||||||
|
SERVERS="node0.backup.example.com:2XXX node1.backup.example.com:2XXX"
|
||||||
|
|
||||||
|
# Should we fallback on servers when the first is unreachable ?
|
||||||
|
SERVERS_FALLBACK=${SERVERS_FALLBACK:-1}
|
||||||
|
|
||||||
|
# timeout (in seconds) for SSH connections
|
||||||
|
SSH_CONNECT_TIMEOUT=${SSH_CONNECT_TIMEOUT:-30}
|
||||||
|
|
||||||
|
## We use /home/backup : feel free to use your own dir
|
||||||
|
LOCAL_BACKUP_DIR="/home/backup"
|
||||||
|
|
||||||
|
# You can set "linux" or "bsd" manually or let it choose automatically
|
||||||
|
SYSTEM=$(uname | tr '[:upper:]' '[:lower:]')
|
||||||
|
|
||||||
|
# Change these 2 variables if you have more than one backup cron
|
||||||
|
PIDFILE="/var/run/evobackup.pid"
|
||||||
|
LOGFILE="/var/log/evobackup.log"
|
||||||
|
|
||||||
|
## Enable/Disable tasks
|
||||||
|
LOCAL_TASKS=${LOCAL_TASKS:-1}
|
||||||
|
SYNC_TASKS=${SYNC_TASKS:-1}
|
||||||
|
|
||||||
|
##### SETUP AND FUNCTIONS #############################################
|
||||||
|
|
||||||
|
BEGINNING=$(/bin/date +"%d-%m-%Y ; %H:%M")
|
||||||
|
|
||||||
|
# shellcheck disable=SC2174
|
||||||
|
mkdir -p -m 700 ${LOCAL_BACKUP_DIR}
|
||||||
|
|
||||||
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
|
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
|
||||||
|
|
||||||
## lang = C for english outputs
|
## lang = C for english outputs
|
||||||
LANGUAGE=C
|
export LANGUAGE=C
|
||||||
LANG=C
|
export LANG=C
|
||||||
|
|
||||||
## Force umask
|
## Force umask
|
||||||
umask 077
|
umask 077
|
||||||
|
|
||||||
|
## Initialize variable to store SSH connection errors
|
||||||
|
SERVERS_SSH_ERRORS=""
|
||||||
|
|
||||||
|
# Call test_server with "HOST:PORT" string
|
||||||
|
# It will return with 0 if the server is reachable.
|
||||||
|
# It will return with 1 and a message on stderr if not.
|
||||||
|
test_server() {
|
||||||
|
item=$1
|
||||||
|
# split HOST and PORT from the input string
|
||||||
|
host=$(echo "${item}" | cut -d':' -f1)
|
||||||
|
port=$(echo "${item}" | cut -d':' -f2)
|
||||||
|
|
||||||
|
# Test if the server is accepting connections
|
||||||
|
ssh -q -o "ConnectTimeout ${SSH_CONNECT_TIMEOUT}" "${host}" -p "${port}" -t "exit"
|
||||||
|
# shellcheck disable=SC2181
|
||||||
|
if [ $? = 0 ]; then
|
||||||
|
# SSH connection is OK
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
# SSH connection failed
|
||||||
|
new_error=$(printf "Failed to connect to \`%s' within %s seconds" "${item}" "${SSH_CONNECT_TIMEOUT}")
|
||||||
|
SERVERS_SSH_ERRORS=$(printf "%s\n%s" "${SERVERS_SSH_ERRORS}" "${new_error}" | sed -e '/^$/d')
|
||||||
|
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
# Call pick_server with an optional positive integer to get the nth server in the list.
|
||||||
|
pick_server() {
|
||||||
|
increment=${1:-0}
|
||||||
|
list_length=$(echo "${SERVERS}" | wc -w)
|
||||||
|
|
||||||
|
if [ "${increment}" -ge "${list_length}" ]; then
|
||||||
|
# We've reached the end of the list
|
||||||
|
new_error="No more server available"
|
||||||
|
SERVERS_SSH_ERRORS=$(printf "%s\n%s" "${SERVERS_SSH_ERRORS}" "${new_error}" | sed -e '/^$/d')
|
||||||
|
|
||||||
|
# Log errors to stderr
|
||||||
|
printf "%s\n" "${SERVERS_SSH_ERRORS}" >&2
|
||||||
|
# Log errors to logfile
|
||||||
|
printf "%s\n" "${SERVERS_SSH_ERRORS}" >> $LOGFILE
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Extract the day of month, without leading 0 (which would give an octal based number)
|
||||||
|
today=$(date +%e)
|
||||||
|
# A salt is useful to randomize the starting point in the list
|
||||||
|
# but stay identical each time it's called for a server (based on hostname).
|
||||||
|
salt=$(hostname | cksum | cut -d' ' -f1)
|
||||||
|
# Pick an integer between 0 and the length of the SERVERS list
|
||||||
|
# It changes each day
|
||||||
|
item=$(( (today + salt + increment) % list_length ))
|
||||||
|
# cut starts counting fields at 1, not 0.
|
||||||
|
field=$(( item + 1 ))
|
||||||
|
|
||||||
|
echo "${SERVERS}" | cut -d' ' -f${field}
|
||||||
|
}
|
||||||
|
|
||||||
## Verify other evobackup process and kill if needed
|
## Verify other evobackup process and kill if needed
|
||||||
PIDFILE=/var/run/evobackup.pid
|
if [ -e "${PIDFILE}" ]; then
|
||||||
if [ -e $PIDFILE ]; then
|
pid=$(cat "${PIDFILE}")
|
||||||
|
# Does process still exist ?
|
||||||
|
if kill -0 ${pid} 2> /dev/null; then
|
||||||
# Killing the childs of evobackup.
|
# Killing the childs of evobackup.
|
||||||
for pid in $(ps h --ppid $(cat $PIDFILE) -o pid | tr -s '\n' ' '); do
|
for ppid in $(pgrep -P "${pid}"); do
|
||||||
kill -9 $pid;
|
kill -9 "${ppid}";
|
||||||
done
|
done
|
||||||
# Then kill the main PID.
|
# Then kill the main PID.
|
||||||
kill -9 $(cat $PIDFILE)
|
kill -9 "${pid}"
|
||||||
echo "$0 tourne encore (PID `cat $PIDFILE`). Processus killé" >&2
|
printf "%s is still running (PID %s). Process has been killed" "$0" "${pid}\n" >&2
|
||||||
|
else
|
||||||
|
rm -f ${PIDFILE}
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
echo "$$" > $PIDFILE
|
echo "$$" > ${PIDFILE}
|
||||||
trap "rm -f $PIDFILE" EXIT
|
# shellcheck disable=SC2064
|
||||||
|
trap "rm -f ${PIDFILE}" EXIT
|
||||||
|
|
||||||
# Variable to choose different backup server with date
|
##### LOCAL BACKUP ####################################################
|
||||||
NODE=$(expr `date +%d` % 2 + 2)
|
|
||||||
|
|
||||||
# port SSH
|
if [ "${LOCAL_TASKS}" = "1" ]; then
|
||||||
SSH_PORT=2XXX
|
# You can comment or uncomment sections below to customize the backup
|
||||||
|
|
||||||
# email adress for notifications
|
## OpenLDAP : example with slapcat
|
||||||
MAIL={{ general_alert_email }}
|
# slapcat -l ${LOCAL_BACKUP_DIR}/ldap.bak
|
||||||
|
|
||||||
# backup server used
|
## MySQL
|
||||||
SRV=node$NODE.backup2.evolix.net
|
|
||||||
|
|
||||||
# choose "linux" or "bsd"
|
## example with global and compressed mysqldump
|
||||||
SYSTEME=$(uname | tr '[:upper:]' '[:lower:]')
|
# mysqldump --defaults-extra-file=/etc/mysql/debian.cnf -P 3306 \
|
||||||
|
# --opt --all-databases --force --events --hex-blob | gzip --best > ${LOCAL_BACKUP_DIR}/mysql.bak.gz
|
||||||
|
|
||||||
## We use /home/backup : feel free to use your own dir
|
## example with two dumps for each table (.sql/.txt) for all databases
|
||||||
mkdir -p -m 700 /home/backup
|
# for i in $(echo SHOW DATABASES | mysql --defaults-extra-file=/etc/mysql/debian.cnf -P 3306 \
|
||||||
|
# | egrep -v "^(Database|information_schema|performance_schema|sys)" ); \
|
||||||
|
# do mkdir -p -m 700 /home/mysqldump/$i ; chown -RL mysql /home/mysqldump ; \
|
||||||
|
# mysqldump --defaults-extra-file=/etc/mysql/debian.cnf --force -P 3306 -Q --opt --events --hex-blob --skip-comments \
|
||||||
|
# --fields-enclosed-by='\"' --fields-terminated-by=',' -T /home/mysqldump/$i $i; done
|
||||||
|
|
||||||
## OpenLDAP : example with slapcat
|
## example with SQL dump (schema only, no data) for each databases
|
||||||
# slapcat -l /home/backup/ldap.bak
|
# mkdir -p -m 700 /home/mysqldump/
|
||||||
|
# for i in $(mysql --defaults-extra-file=/etc/mysql/debian.cnf -P 3306 -e 'show databases' -s --skip-column-names \
|
||||||
|
# | egrep -v "^(Database|information_schema|performance_schema|sys)"); do
|
||||||
|
# mysqldump --defaults-extra-file=/etc/mysql/debian.cnf --force -P 3306 --no-data --databases $i > /home/mysqldump/${i}.schema.sql
|
||||||
|
# done
|
||||||
|
|
||||||
### MySQL
|
## example with compressed SQL dump (with data) for each databases
|
||||||
|
# mkdir -p -m 700 /home/mysqldump/
|
||||||
|
# for i in $(mysql --defaults-extra-file=/etc/mysql/debian.cnf -P 3306 -e 'show databases' -s --skip-column-names \
|
||||||
|
# | egrep -v "^(Database|information_schema|performance_schema|sys)"); do
|
||||||
|
# mysqldump --defaults-extra-file=/etc/mysql/debian.cnf --force -P 3306 --events --hex-blob $i | gzip --best > /home/mysqldump/${i}.sql.gz
|
||||||
|
# done
|
||||||
|
|
||||||
## example with global and compressed mysqldump
|
## example with *one* uncompressed SQL dump for *one* database (MYBASE)
|
||||||
# mysqldump --defaults-extra-file=/etc/mysql/debian.cnf -P 3306 \
|
# mkdir -p -m 700 /home/mysqldump/MYBASE
|
||||||
# --opt --all-databases --force --events --hex-blob | gzip --best > /home/backup/mysql.bak.gz
|
# chown -RL mysql /home/mysqldump/
|
||||||
|
# mysqldump --defaults-extra-file=/etc/mysql/debian.cnf --force -Q \
|
||||||
|
# --opt --events --hex-blob --skip-comments -T /home/mysqldump/MYBASE MYBASE
|
||||||
|
|
||||||
## example with two dumps for each table (.sql/.txt) for all databases
|
## example with mysqlhotcopy
|
||||||
# for i in $(echo SHOW DATABASES | mysql --defaults-extra-file=/etc/mysql/debian.cnf -P 3306 \
|
# mkdir -p -m 700 /home/mysqlhotcopy/
|
||||||
# | egrep -v "^(Database|information_schema|performance_schema)" ); \
|
# mysqlhotcopy BASE /home/mysqlhotcopy/
|
||||||
# do mkdir -p /home/mysqldump/$i ; chown -RL mysql /home/mysqldump ; \
|
|
||||||
# mysqldump --defaults-extra-file=/etc/mysql/debian.cnf --force -P 3306 -Q --opt --events --hex-blob --skip-comments -T \
|
|
||||||
# /home/mysqldump/$i $i; done
|
|
||||||
|
|
||||||
## example with compressed SQL dump for each databases
|
## example for multiples MySQL instances
|
||||||
# mkdir -p /home/mysqldump/
|
# mysqladminpasswd=$(grep -m1 'password = .*' /root/.my.cnf|cut -d" " -f3)
|
||||||
# for i in $(mysql --defaults-extra-file=/etc/mysql/debian.cnf -P 3306 -e 'show databases' -s --skip-column-names \
|
# grep -E "^port\s*=\s*\d*" /etc/mysql/my.cnf |while read instance; do
|
||||||
# | egrep -v "^(Database|information_schema|performance_schema)"); do
|
# instance=$(echo "$instance"|awk '{ print $3 }')
|
||||||
# mysqldump --defaults-extra-file=/etc/mysql/debian.cnf --force -P 3306 --events --hex-blob $i | gzip --best > /home/mysqldump/${i}.sql.gz
|
# if [ "$instance" != "3306" ]
|
||||||
# done
|
# then
|
||||||
|
# mysqldump -P $instance --opt --all-databases --hex-blob -u mysqladmin -p$mysqladminpasswd > ${LOCAL_BACKUP_DIR}/mysql.$instance.bak
|
||||||
|
# fi
|
||||||
|
# done
|
||||||
|
|
||||||
## example with *one* uncompressed SQL dump for *one* database (MYBASE)
|
## PostgreSQL
|
||||||
# mkdir -p -m 700 /home/mysqldump/MYBASE
|
|
||||||
# chown -RL mysql /home/mysqldump/
|
|
||||||
# mysqldump --defaults-extra-file=/etc/mysql/debian.cnf --force -Q \
|
|
||||||
# --opt --events --hex-blob --skip-comments -T /home/mysqldump/MYBASE MYBASE
|
|
||||||
|
|
||||||
## example with mysqlhotcopy
|
## example with pg_dumpall (warning: you need space in ~postgres)
|
||||||
# mkdir -p /home/mysqlhotcopy/
|
# su - postgres -c "pg_dumpall > ~/pg.dump.bak"
|
||||||
# mysqlhotcopy BASE /home/mysqlhotcopy/
|
# mv ~postgres/pg.dump.bak ${LOCAL_BACKUP_DIR}/
|
||||||
|
## another method with gzip directly piped
|
||||||
|
# cd /var/lib/postgresql
|
||||||
|
# sudo -u postgres pg_dumpall | gzip > ${LOCAL_BACKUP_DIR}/pg.dump.bak.gz
|
||||||
|
# cd - > /dev/null
|
||||||
|
|
||||||
## example for multiples MySQL instances
|
## example with all tables from MYBASE excepts TABLE1 and TABLE2
|
||||||
# mysqladminpasswd=`cat /root/.my.cnf |grep -m1 'password = .*' |cut -d" " -f3`
|
# pg_dump -p 5432 -h 127.0.0.1 -U USER --clean -F t --inserts -f ${LOCAL_BACKUP_DIR}/pg-backup.tar -t 'TABLE1' -t 'TABLE2' MYBASE
|
||||||
# grep -E "^port\s*=\s*\d*" /etc/mysql/my.cnf |while read instance; do
|
|
||||||
# instance=$(echo $instance |tr -d '\t')
|
|
||||||
# instance=${instance// /}
|
|
||||||
# instance=${instance//port=/}
|
|
||||||
# if [ "$instance" != "3306" ]
|
|
||||||
# then
|
|
||||||
# mysqldump -P $instance --opt --all-databases --hex-blob -u mysqladmin -p$mysqladminpasswd > /home/backup/mysql.$instance.bak
|
|
||||||
# fi
|
|
||||||
# done
|
|
||||||
|
|
||||||
### PostgreSQL
|
## example with only TABLE1 and TABLE2 from MYBASE
|
||||||
|
# pg_dump -p 5432 -h 127.0.0.1 -U USER --clean -F t --inserts -f ${LOCAL_BACKUP_DIR}/pg-backup.tar -T 'TABLE1' -T 'TABLE2' MYBASE
|
||||||
|
|
||||||
## example with pg_dumpall (warning: you need space in ~postgres)
|
## MongoDB
|
||||||
# su - postgres -c "pg_dumpall > ~/pg.dump.bak"
|
|
||||||
# mv ~postgres/pg.dump.bak /home/backup/
|
|
||||||
|
|
||||||
## example with all tables from MYBASE excepts TABLE1 and TABLE2
|
## don't forget to create use with read-only access
|
||||||
# pg_dump -p 5432 -h 127.0.0.1 -U USER --clean -F t --inserts -f /home/backup/pg-backup.tar -t 'TABLE1' -t 'TABLE2' MYBASE
|
## > use admin
|
||||||
|
## > db.createUser( { user: "mongobackup", pwd: "PASS", roles: [ "backup", ] } )
|
||||||
|
# test -d ${LOCAL_BACKUP_DIR}/mongodump/ && rm -rf ${LOCAL_BACKUP_DIR}/mongodump/
|
||||||
|
# mkdir -p -m 700 ${LOCAL_BACKUP_DIR}/mongodump/
|
||||||
|
# mongodump --quiet -u mongobackup -pPASS -o ${LOCAL_BACKUP_DIR}/mongodump/
|
||||||
|
# if [ $? -ne 0 ]; then
|
||||||
|
# echo "Error with mongodump!"
|
||||||
|
# fi
|
||||||
|
|
||||||
## example with only TABLE1 and TABLE2 from MYBASE
|
## Redis
|
||||||
# pg_dump -p 5432 -h 127.0.0.1 -U USER --clean -F t --inserts -f /home/backup/pg-backup.tar -T 'TABLE1' -T 'TABLE2' MYBASE
|
|
||||||
|
|
||||||
## MongoDB : example with mongodump
|
## example with copy .rdb file
|
||||||
## don't forget to create use with read-only access
|
# cp /var/lib/redis/dump.rdb ${LOCAL_BACKUP_DIR}/
|
||||||
## > use admin
|
|
||||||
## > db.addUser("mongobackup", "PASS", true);
|
|
||||||
# mongodump -u mongobackup -pPASS -o /home/backup/mongodump/ >/dev/null 2>&1 |grep -v "^connected to:"
|
|
||||||
|
|
||||||
## Redis : example with copy .rdb file
|
## ElasticSearch
|
||||||
# cp /var/lib/redis/dump.rdb /home/backup/
|
|
||||||
|
|
||||||
## ElasticSearch : example with rsync (warning: don't forget to use NFS if you have a cluster)
|
## Take a snapshot as a backup.
|
||||||
## Disable ES translog flush
|
## Warning: You need to have a path.repo configured.
|
||||||
# curl -s -XPUT 'localhost:9200/_settings' -d '{"index.translog.disable_flush": true}' >/dev/null
|
## See: https://wiki.evolix.org/HowtoElasticsearch#snapshots-et-sauvegardes
|
||||||
## Flushes translog
|
# curl -s -XDELETE "localhost:9200/_snapshot/snaprepo/snapshot.daily" -o /tmp/es_delete_snapshot.daily.log
|
||||||
# curl -s 'localhost:9200/_flush' | grep -qe '"ok":true'
|
# curl -s -XPUT "localhost:9200/_snapshot/snaprepo/snapshot.daily?wait_for_completion=true" -o /tmp/es_snapshot.daily.log
|
||||||
## If it succeed, do an rsync of the datadir
|
## Clustered version here
|
||||||
# if [ $? -eq 0 ]; then
|
## It basically the same thing except that you need to check that NFS is mounted
|
||||||
# rsync -a /var/lib/elasticsearch /home/backup/
|
# if ss | grep ':nfs' | grep -q 'ip\.add\.res\.s1' && ss | grep ':nfs' | grep -q 'ip\.add\.res\.s2'
|
||||||
# else
|
# then
|
||||||
# echo "Error when flushing ES translog indexes."
|
# curl -s -XDELETE "localhost:9200/_snapshot/snaprepo/snapshot.daily" -o /tmp/es_delete_snapshot.daily.log
|
||||||
# fi
|
# curl -s -XPUT "localhost:9200/_snapshot/snaprepo/snapshot.daily?wait_for_completion=true" -o /tmp/es_snapshot.daily.log
|
||||||
## In any case re-enable translog flush
|
# else
|
||||||
# curl -s -XPUT 'localhost:9200/_settings' -d '{"index.translog.disable_flush": false}' > /dev/null
|
# echo 'Cannot make a snapshot of elasticsearch, at least one node is not mounting the repository.'
|
||||||
|
# fi
|
||||||
|
## If you need to keep older snapshot, for example the last 10 daily snapshots, replace the XDELETE and XPUT lines by :
|
||||||
|
# for snapshot in $(curl -s -XGET "localhost:9200/_snapshot/snaprepo/_all?pretty=true" | grep -Eo 'snapshot_[0-9]{4}-[0-9]{2}-[0-9]{2}' | head -n -10); do
|
||||||
|
# curl -s -XDELETE "localhost:9200/_snapshot/snaprepo/${snapshot}" | grep -v -Fx '{"acknowledged":true}'
|
||||||
|
# done
|
||||||
|
# date=$(date +%F)
|
||||||
|
# curl -s -XPUT "localhost:9200/_snapshot/snaprepo/snapshot_${date}?wait_for_completion=true" -o /tmp/es_snapshot_${date}.log
|
||||||
|
|
||||||
## Dump MBR / table partitions with dd and sfdisk
|
## RabbitMQ
|
||||||
## Linux
|
|
||||||
# dd if=/dev/sda of=/home/backup/MBR bs=512 count=1 2>&1 | egrep -v "(records in|records out|512 bytes)"
|
|
||||||
# sfdisk -d /dev/sda > /home/backup/partitions 2>&1 | egrep -v "(Warning: extended partition does not start at a cylinder boundary|DOS and Linux will interpret the contents differently)"
|
|
||||||
## OpenBSD
|
|
||||||
# disklabel sd0 > /home/backup/partitions
|
|
||||||
|
|
||||||
# backup MegaCli config
|
## export config
|
||||||
#megacli -CfgSave -f /home/backup/megacli_conf.dump -a0 >/dev/null
|
#rabbitmqadmin export ${LOCAL_BACKUP_DIR}/rabbitmq.config >> $LOGFILE
|
||||||
|
|
||||||
## Dump network routes with mtr and traceroute (warning: could be long with aggressive firewalls)
|
## MegaCli config
|
||||||
for addr in 8.8.8.8 backup.evolix.net www.evolix.fr www.evolix.net; do
|
|
||||||
mtr -r $addr > /home/backup/mtr-${addr} 2>/dev/null
|
|
||||||
traceroute -n $addr > /home/backup/traceroute-${addr} 2>/dev/null
|
|
||||||
done
|
|
||||||
|
|
||||||
## Dump process with ps
|
#megacli -CfgSave -f ${LOCAL_BACKUP_DIR}/megacli_conf.dump -a0 >/dev/null
|
||||||
ps aux >/home/backup/ps.out
|
|
||||||
|
|
||||||
if [ $SYSTEME = "linux" ]; then
|
## Dump system and kernel versions
|
||||||
## Dump network connections with netstat
|
uname -a > ${LOCAL_BACKUP_DIR}/uname
|
||||||
netstat -taupen >/home/backup/netstat.out
|
|
||||||
|
## Dump network routes with mtr and traceroute (warning: could be long with aggressive firewalls)
|
||||||
|
for addr in 8.8.8.8 www.evolix.fr travaux.evolix.net; do
|
||||||
|
mtr -r ${addr} > ${LOCAL_BACKUP_DIR}/mtr-${addr}
|
||||||
|
traceroute -n ${addr} > ${LOCAL_BACKUP_DIR}/traceroute-${addr} 2>&1
|
||||||
|
done
|
||||||
|
|
||||||
|
## Dump process with ps
|
||||||
|
ps auwwx >${LOCAL_BACKUP_DIR}/ps.out
|
||||||
|
|
||||||
|
if [ "${SYSTEM}" = "linux" ]; then
|
||||||
|
## Dump network connections with ss
|
||||||
|
ss -taupen > ${LOCAL_BACKUP_DIR}/netstat.out
|
||||||
|
|
||||||
## List Debian packages
|
## List Debian packages
|
||||||
dpkg -l >/home/backup/packages
|
dpkg -l > ${LOCAL_BACKUP_DIR}/packages
|
||||||
else
|
dpkg --get-selections > ${LOCAL_BACKUP_DIR}/packages.getselections
|
||||||
|
apt-cache dumpavail > ${LOCAL_BACKUP_DIR}/packages.available
|
||||||
|
|
||||||
|
## Dump MBR / table partitions
|
||||||
|
disks=$(lsblk -l | grep disk | grep -v -E '(drbd|fd[0-9]+)' | awk '{print $1}')
|
||||||
|
for disk in ${disks}; do
|
||||||
|
dd if="/dev/${disk}" of="${LOCAL_BACKUP_DIR}/MBR-${disk}" bs=512 count=1 2>&1 | grep -Ev "(records in|records out|512 bytes)"
|
||||||
|
fdisk -l "/dev/${disk}" > "${LOCAL_BACKUP_DIR}/partitions-${disk}" 2>&1
|
||||||
|
done
|
||||||
|
cat ${LOCAL_BACKUP_DIR}/partitions-* > ${LOCAL_BACKUP_DIR}/partitions
|
||||||
|
|
||||||
|
## Dump iptables
|
||||||
|
if [ -x /sbin/iptables ]; then
|
||||||
|
{ /sbin/iptables -L -n -v; /sbin/iptables -t filter -L -n -v; } > ${LOCAL_BACKUP_DIR}/iptables.txt
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Dump findmnt(8) output
|
||||||
|
FINDMNT_BIN=$(command -v findmnt)
|
||||||
|
if [ -x ${FINDMNT_BIN} ]; then
|
||||||
|
${FINDMNT_BIN} > ${LOCAL_BACKUP_DIR}/findmnt.txt
|
||||||
|
fi
|
||||||
|
else
|
||||||
## Dump network connections with netstat
|
## Dump network connections with netstat
|
||||||
netstat -finet -atn >/home/backup/netstat.out
|
netstat -finet -atn > ${LOCAL_BACKUP_DIR}/netstat.out
|
||||||
|
|
||||||
## List OpenBSD packages
|
## List OpenBSD packages
|
||||||
pkg_info -m >/home/backup/packages
|
pkg_info -m > ${LOCAL_BACKUP_DIR}/packages
|
||||||
|
|
||||||
|
## Dump MBR / table partitions
|
||||||
|
disklabel sd0 > ${LOCAL_BACKUP_DIR}/partitions
|
||||||
|
|
||||||
|
## Dump pf infos
|
||||||
|
pfctl -sa > ${LOCAL_BACKUP_DIR}/pfctl-sa.txt
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Dump rights
|
||||||
|
#getfacl -R /var > ${LOCAL_BACKUP_DIR}/rights-var.txt
|
||||||
|
#getfacl -R /etc > ${LOCAL_BACKUP_DIR}/rights-etc.txt
|
||||||
|
#getfacl -R /usr > ${LOCAL_BACKUP_DIR}/rights-usr.txt
|
||||||
|
#getfacl -R /home > ${LOCAL_BACKUP_DIR}/rights-home.txt
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
##### REMOTE BACKUP ###################################################
|
||||||
|
|
||||||
|
n=0
|
||||||
|
server=""
|
||||||
|
if [ "${SERVERS_FALLBACK}" = "1" ]; then
|
||||||
|
# We try to find a suitable server
|
||||||
|
while :; do
|
||||||
|
server=$(pick_server "${n}")
|
||||||
|
test $? = 0 || exit 2
|
||||||
|
|
||||||
|
if test_server "${server}"; then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
server=""
|
||||||
|
n=$(( n + 1 ))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
# we force the server
|
||||||
|
server=$(pick_server "${n}")
|
||||||
|
fi
|
||||||
|
|
||||||
|
SSH_SERVER=$(echo "${server}" | cut -d':' -f1)
|
||||||
|
SSH_PORT=$(echo "${server}" | cut -d':' -f2)
|
||||||
|
|
||||||
HOSTNAME=$(hostname)
|
HOSTNAME=$(hostname)
|
||||||
|
|
||||||
DATE=$(/bin/date +"%d-%m-%Y")
|
if [ "${SYSTEM}" = "linux" ]; then
|
||||||
|
|
||||||
DEBUT=$(/bin/date +"%d-%m-%Y ; %H:%M")
|
|
||||||
|
|
||||||
if [ $SYSTEME = "linux" ]; then
|
|
||||||
rep="/bin /boot /lib /opt /sbin /usr"
|
rep="/bin /boot /lib /opt /sbin /usr"
|
||||||
else
|
else
|
||||||
rep="/bsd /bin /sbin /usr"
|
rep="/bsd /bin /sbin /usr"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
/usr/local/bin/rsync -avzh --stats --delete --delete-excluded --force --ignore-errors --partial \
|
|
||||||
|
if [ "${SYNC_TASKS}" = "1" ]; then
|
||||||
|
# /!\ DO NOT USE COMMENTS in the rsync command /!\
|
||||||
|
# It breaks the command and destroys data, simply remove (or add) lines.
|
||||||
|
|
||||||
|
# Remote shell command
|
||||||
|
RSH_COMMAND="ssh -p ${SSH_PORT} -o 'ConnectTimeout ${SSH_CONNECT_TIMEOUT}'"
|
||||||
|
|
||||||
|
rsync -avzh --stats --delete --delete-excluded --force --ignore-errors --partial \
|
||||||
--exclude "lost+found" \
|
--exclude "lost+found" \
|
||||||
--exclude ".nfs.*" \
|
--exclude ".nfs.*" \
|
||||||
--exclude "/var/log" \
|
--exclude "/var/log" \
|
||||||
|
@ -200,23 +391,29 @@ fi
|
||||||
--exclude "/var/lib/amavis/tmp" \
|
--exclude "/var/lib/amavis/tmp" \
|
||||||
--exclude "/var/lib/clamav/*.tmp" \
|
--exclude "/var/lib/clamav/*.tmp" \
|
||||||
--exclude "/home/mysqltmp" \
|
--exclude "/home/mysqltmp" \
|
||||||
$rep \
|
--exclude "/var/lib/php/sessions" \
|
||||||
|
${rep} \
|
||||||
/etc \
|
/etc \
|
||||||
/root \
|
/root \
|
||||||
/var \
|
/var \
|
||||||
/home \
|
/home \
|
||||||
-e "ssh -p $SSH_PORT" \
|
-e "${RSH_COMMAND}" \
|
||||||
root@${SRV}:/var/backup/ \
|
"root@${SSH_SERVER}:/var/backup/" \
|
||||||
| tail -30 >> /var/log/evobackup.log
|
| tail -30 >> $LOGFILE
|
||||||
|
fi
|
||||||
|
|
||||||
FIN=$(/bin/date +"%d-%m-%Y ; %H:%M")
|
##### REPORTING #######################################################
|
||||||
|
|
||||||
echo "EvoBackup - $HOSTNAME - START $DEBUT" \
|
END=$(/bin/date +"%d-%m-%Y ; %H:%M")
|
||||||
>> /var/log/evobackup.log
|
|
||||||
|
|
||||||
echo "EvoBackup - $HOSTNAME - STOP $FIN" \
|
printf "EvoBackup - %s - START %s ON %s (LOCAL_TASKS=%s SYNC_TASKS=%s)\n" \
|
||||||
>> /var/log/evobackup.log
|
"${HOSTNAME}" "${BEGINNING}" "${SSH_SERVER}" "${LOCAL_TASKS}" "${SYNC_TASKS}" \
|
||||||
|
>> $LOGFILE
|
||||||
|
|
||||||
tail -10 /var/log/evobackup.log | \
|
printf "EvoBackup - %s - STOP %s ON %s (LOCAL_TASKS=%s SYNC_TASKS=%s)\n" \
|
||||||
mail -s "[info] EvoBackup - Client $HOSTNAME" \
|
"${HOSTNAME}" "${END}" "${SSH_SERVER}" "${LOCAL_TASKS}" "${SYNC_TASKS}" \
|
||||||
$MAIL
|
>> $LOGFILE
|
||||||
|
|
||||||
|
tail -10 $LOGFILE | \
|
||||||
|
mail -s "[info] EvoBackup - Client ${HOSTNAME}" \
|
||||||
|
${MAIL}
|
||||||
|
|
Loading…
Reference in a new issue