Release 10.0.0 #100
|
@ -1,5 +1,7 @@
|
||||||
|
#jinja2:variable_start_string:'[%' , variable_end_string:'%]'
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Careful, the zzz_evobackup template was last updated on 2020/03/23
|
# Careful, the zzz_evobackup template was last updated on 2020/04/15
|
||||||
|
#
|
||||||
# Script Evobackup client
|
# Script Evobackup client
|
||||||
# See https://gitea.evolix.org/evolix/evobackup
|
# See https://gitea.evolix.org/evolix/evobackup
|
||||||
#
|
#
|
||||||
|
@ -18,7 +20,6 @@
|
||||||
# Fail on unassigned variables
|
# Fail on unassigned variables
|
||||||
set -u
|
set -u
|
||||||
|
|
||||||
|
|
||||||
##### Configuration ###################################################
|
##### Configuration ###################################################
|
||||||
|
|
||||||
# email adress for notifications
|
# email adress for notifications
|
||||||
|
@ -46,7 +47,7 @@ LOGFILE="{{ evobackup_client__log_path }}"
|
||||||
## Enable/Disable tasks
|
## Enable/Disable tasks
|
||||||
LOCAL_TASKS=${LOCAL_TASKS:-1}
|
LOCAL_TASKS=${LOCAL_TASKS:-1}
|
||||||
SYNC_TASKS=${SYNC_TASKS:-1}
|
SYNC_TASKS=${SYNC_TASKS:-1}
|
||||||
|
[%
|
||||||
##### SETUP AND FUNCTIONS #############################################
|
##### SETUP AND FUNCTIONS #############################################
|
||||||
|
|
||||||
BEGINNING=$(/bin/date +"%d-%m-%Y ; %H:%M")
|
BEGINNING=$(/bin/date +"%d-%m-%Y ; %H:%M")
|
||||||
|
@ -84,7 +85,7 @@ test_server() {
|
||||||
else
|
else
|
||||||
# SSH connection failed
|
# SSH connection failed
|
||||||
new_error=$(printf "Failed to connect to \`%s' within %s seconds" "${item}" "${SSH_CONNECT_TIMEOUT}")
|
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')
|
SERVERS_SSH_ERRORS=$(printf "%s\\n%s" "${SERVERS_SSH_ERRORS}" "${new_error}" | sed -e '/^$/d')
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
@ -97,12 +98,12 @@ pick_server() {
|
||||||
if [ "${increment}" -ge "${list_length}" ]; then
|
if [ "${increment}" -ge "${list_length}" ]; then
|
||||||
# We've reached the end of the list
|
# We've reached the end of the list
|
||||||
new_error="No more server available"
|
new_error="No more server available"
|
||||||
SERVERS_SSH_ERRORS=$(printf "%s\n%s" "${SERVERS_SSH_ERRORS}" "${new_error}" | sed -e '/^$/d')
|
SERVERS_SSH_ERRORS=$(printf "%s\\n%s" "${SERVERS_SSH_ERRORS}" "${new_error}" | sed -e '/^$/d')
|
||||||
|
|
||||||
# Log errors to stderr
|
# Log errors to stderr
|
||||||
printf "%s\n" "${SERVERS_SSH_ERRORS}" >&2
|
printf "%s\\n" "${SERVERS_SSH_ERRORS}" >&2
|
||||||
# Log errors to logfile
|
# Log errors to logfile
|
||||||
printf "%s\n" "${SERVERS_SSH_ERRORS}" >> $LOGFILE
|
printf "%s\\n" "${SERVERS_SSH_ERRORS}" >> $LOGFILE
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -124,6 +125,8 @@ pick_server() {
|
||||||
if [ -e "${PIDFILE}" ]; then
|
if [ -e "${PIDFILE}" ]; then
|
||||||
pid=$(cat "${PIDFILE}")
|
pid=$(cat "${PIDFILE}")
|
||||||
# Does process still exist ?
|
# Does process still exist ?
|
||||||
|
# ignore check because multiple processes might exist
|
||||||
|
# shellcheck disable=SC2086
|
||||||
if kill -0 ${pid} 2> /dev/null; then
|
if kill -0 ${pid} 2> /dev/null; then
|
||||||
# Killing the childs of evobackup.
|
# Killing the childs of evobackup.
|
||||||
for ppid in $(pgrep -P "${pid}"); do
|
for ppid in $(pgrep -P "${pid}"); do
|
||||||
|
@ -131,7 +134,7 @@ if [ -e "${PIDFILE}" ]; then
|
||||||
done
|
done
|
||||||
# Then kill the main PID.
|
# Then kill the main PID.
|
||||||
kill -9 "${pid}"
|
kill -9 "${pid}"
|
||||||
printf "%s is still running (PID %s). Process has been killed" "$0" "${pid}\n" >&2
|
printf "%s is still running (PID %s). Process has been killed" "$0" "${pid}\\n" >&2
|
||||||
else
|
else
|
||||||
rm -f ${PIDFILE}
|
rm -f ${PIDFILE}
|
||||||
fi
|
fi
|
||||||
|
@ -156,32 +159,54 @@ if [ "${LOCAL_TASKS}" = "1" ]; then
|
||||||
## Dump process with ps
|
## Dump process with ps
|
||||||
ps auwwx >${LOCAL_BACKUP_DIR}/ps.out
|
ps auwwx >${LOCAL_BACKUP_DIR}/ps.out
|
||||||
|
|
||||||
## Dump network connections with ss
|
if [ "${SYSTEM}" = "linux" ]; then
|
||||||
ss -taupen > ${LOCAL_BACKUP_DIR}/netstat.out
|
## Dump network connections with ss
|
||||||
|
ss -taupen > ${LOCAL_BACKUP_DIR}/netstat.out
|
||||||
|
|
||||||
## List Debian packages
|
## List Debian packages
|
||||||
dpkg -l > ${LOCAL_BACKUP_DIR}/packages
|
dpkg -l > ${LOCAL_BACKUP_DIR}/packages
|
||||||
dpkg --get-selections > ${LOCAL_BACKUP_DIR}/packages.getselections
|
dpkg --get-selections > ${LOCAL_BACKUP_DIR}/packages.getselections
|
||||||
apt-cache dumpavail > ${LOCAL_BACKUP_DIR}/packages.available
|
apt-cache dumpavail > ${LOCAL_BACKUP_DIR}/packages.available
|
||||||
|
|
||||||
## Dump MBR / table partitions
|
## Dump MBR / table partitions
|
||||||
disks=$(lsblk -l | grep disk | grep -v -E '(drbd|fd[0-9]+)' | awk '{print $1}')
|
disks=$(lsblk -l | grep disk | grep -v -E '(drbd|fd[0-9]+)' | awk '{print $1}')
|
||||||
for disk in ${disks}; do
|
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)"
|
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
|
fdisk -l "/dev/${disk}" > "${LOCAL_BACKUP_DIR}/partitions-${disk}" 2>&1
|
||||||
done
|
done
|
||||||
cat ${LOCAL_BACKUP_DIR}/partitions-* > ${LOCAL_BACKUP_DIR}/partitions
|
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
|
||||||
|
netstat -finet -atn > ${LOCAL_BACKUP_DIR}/netstat.out
|
||||||
|
|
||||||
|
## List OpenBSD 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
|
||||||
|
|
||||||
## 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
|
fi
|
||||||
|
|
||||||
## Dump findmnt(8) output
|
## Dump rights
|
||||||
FINDMNT_BIN=$(command -v findmnt)
|
#getfacl -R /var > ${LOCAL_BACKUP_DIR}/rights-var.txt
|
||||||
if [ -x ${FINDMNT_BIN} ]; then
|
#getfacl -R /etc > ${LOCAL_BACKUP_DIR}/rights-etc.txt
|
||||||
${FINDMNT_BIN} > ${LOCAL_BACKUP_DIR}/findmnt.txt
|
#getfacl -R /usr > ${LOCAL_BACKUP_DIR}/rights-usr.txt
|
||||||
fi
|
#getfacl -R /home > ${LOCAL_BACKUP_DIR}/rights-home.txt
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
##### REMOTE BACKUP ###################################################
|
##### REMOTE BACKUP ###################################################
|
||||||
|
@ -212,7 +237,7 @@ SSH_PORT=$(echo "${server}" | cut -d':' -f2)
|
||||||
HOSTNAME=$(hostname)
|
HOSTNAME=$(hostname)
|
||||||
|
|
||||||
if [ "${SYSTEM}" = "linux" ]; then
|
if [ "${SYSTEM}" = "linux" ]; then
|
||||||
rep="/bin /boot /lib /opt /sbin /usr"
|
rep="/bin /boot /lib /opt /sbin /usr /srv"
|
||||||
else
|
else
|
||||||
rep="/bsd /bin /sbin /usr"
|
rep="/bsd /bin /sbin /usr"
|
||||||
fi
|
fi
|
||||||
|
@ -225,6 +250,8 @@ if [ "${SYNC_TASKS}" = "1" ]; then
|
||||||
# Remote shell command
|
# Remote shell command
|
||||||
RSH_COMMAND="ssh -i /root/.ssh/evobackup_id -p ${SSH_PORT} -o 'ConnectTimeout ${SSH_CONNECT_TIMEOUT}'"
|
RSH_COMMAND="ssh -i /root/.ssh/evobackup_id -p ${SSH_PORT} -o 'ConnectTimeout ${SSH_CONNECT_TIMEOUT}'"
|
||||||
|
|
||||||
|
# ignore check because we want it to split the different arguments to $rep
|
||||||
|
# shellcheck disable=SC2086
|
||||||
rsync -avzh --stats --delete --delete-excluded --force --ignore-errors --partial \
|
rsync -avzh --stats --delete --delete-excluded --force --ignore-errors --partial \
|
||||||
--exclude "lost+found" \
|
--exclude "lost+found" \
|
||||||
--exclude ".nfs.*" \
|
--exclude ".nfs.*" \
|
||||||
|
@ -268,14 +295,15 @@ fi
|
||||||
|
|
||||||
END=$(/bin/date +"%d-%m-%Y ; %H:%M")
|
END=$(/bin/date +"%d-%m-%Y ; %H:%M")
|
||||||
|
|
||||||
printf "EvoBackup - %s - START %s ON %s (LOCAL_TASKS=%s SYNC_TASKS=%s)\n" \
|
printf "EvoBackup - %s - START %s ON %s (LOCAL_TASKS=%s SYNC_TASKS=%s)\\n" \
|
||||||
"${HOSTNAME}" "${BEGINNING}" "${SSH_SERVER}" "${LOCAL_TASKS}" "${SYNC_TASKS}" \
|
"${HOSTNAME}" "${BEGINNING}" "${SSH_SERVER}" "${LOCAL_TASKS}" "${SYNC_TASKS}" \
|
||||||
>> $LOGFILE
|
>> $LOGFILE
|
||||||
|
|
||||||
printf "EvoBackup - %s - STOP %s ON %s (LOCAL_TASKS=%s SYNC_TASKS=%s)\n" \
|
printf "EvoBackup - %s - STOP %s ON %s (LOCAL_TASKS=%s SYNC_TASKS=%s)\\n" \
|
||||||
"${HOSTNAME}" "${END}" "${SSH_SERVER}" "${LOCAL_TASKS}" "${SYNC_TASKS}" \
|
"${HOSTNAME}" "${END}" "${SSH_SERVER}" "${LOCAL_TASKS}" "${SYNC_TASKS}" \
|
||||||
>> $LOGFILE
|
>> $LOGFILE
|
||||||
|
|
||||||
tail -10 $LOGFILE | \
|
tail -10 $LOGFILE | \
|
||||||
mail -s "[info] EvoBackup - Client ${HOSTNAME}" \
|
mail -s "[info] EvoBackup - Client ${HOSTNAME}" \
|
||||||
${MAIL}
|
${MAIL}
|
||||||
|
%]
|
||||||
|
|
Loading…
Reference in a new issue