Cosmetic changes : quotes, braces and extracted variable #16
|
@ -26,13 +26,16 @@ SERVERS="node0.backup.example.com:2XXX node1.backup.example.com:2XXX"
|
||||||
# timeout (in seconds) for the SSH test
|
# timeout (in seconds) for the SSH test
|
||||||
SSH_CONNECT_TIMEOUT=30
|
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
|
# You can set "linux" or "bsd" manually or let it choose automatically
|
||||||
SYSTEM=$(uname | tr '[:upper:]' '[:lower:]')
|
SYSTEM=$(uname | tr '[:upper:]' '[:lower:]')
|
||||||
|
|
||||||
##### SETUP AND FUNCTIONS #############################################
|
##### SETUP AND FUNCTIONS #############################################
|
||||||
|
|
||||||
# shellcheck disable=SC2174
|
# shellcheck disable=SC2174
|
||||||
mkdir -p -m 700 /home/backup
|
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
|
||||||
|
|
||||||
|
@ -88,33 +91,33 @@ pick_server() {
|
||||||
}
|
}
|
||||||
|
|
||||||
## Verify other evobackup process and kill if needed
|
## Verify other evobackup process and kill if needed
|
||||||
PIDFILE=/var/run/evobackup.pid
|
PIDFILE="/var/run/evobackup.pid"
|
||||||
if [ -e $PIDFILE ]; then
|
if [ -e "${PIDFILE}" ]; then
|
||||||
pid=$(cat "$PIDFILE")
|
pid=$(cat "${PIDFILE}")
|
||||||
# Killing the childs of evobackup.
|
# Killing the childs of evobackup.
|
||||||
for ppid in $(ps h --ppid "$pid" -o pid | tr -s '\n' ' '); do
|
for ppid in $(ps h --ppid "${pid}" -o pid | tr -s '\n' ' '); do
|
||||||
kill -9 "$ppid";
|
kill -9 "${ppid}";
|
||||||
done
|
done
|
||||||
# Then kill the main PID.
|
# Then kill the main PID.
|
||||||
kill -9 "$pid"
|
kill -9 "${pid}"
|
||||||
echo "$0 is still running (PID $pid). Process has been killed" >&2
|
echo "$0 is still running (PID ${pid}). Process has been killed" >&2
|
||||||
fi
|
fi
|
||||||
echo "$$" > $PIDFILE
|
echo "$$" > ${PIDFILE}
|
||||||
# shellcheck disable=SC2064
|
# shellcheck disable=SC2064
|
||||||
trap "rm -f $PIDFILE" EXIT
|
trap "rm -f ${PIDFILE}" EXIT
|
||||||
|
|
||||||
##### LOCAL BACKUP ####################################################
|
##### LOCAL BACKUP ####################################################
|
||||||
|
|
||||||
# You can comment or uncomment sections below to customize the backup
|
# You can comment or uncomment sections below to customize the backup
|
||||||
|
|
||||||
## OpenLDAP : example with slapcat
|
## OpenLDAP : example with slapcat
|
||||||
# slapcat -l /home/backup/ldap.bak
|
# slapcat -l ${LOCAL_BACKUP_DIR}/ldap.bak
|
||||||
|
|
||||||
### MySQL
|
### MySQL
|
||||||
|
|
||||||
## example with global and compressed mysqldump
|
## example with global and compressed mysqldump
|
||||||
# mysqldump --defaults-extra-file=/etc/mysql/debian.cnf -P 3306 \
|
# mysqldump --defaults-extra-file=/etc/mysql/debian.cnf -P 3306 \
|
||||||
# --opt --all-databases --force --events --hex-blob | gzip --best > /home/backup/mysql.bak.gz
|
# --opt --all-databases --force --events --hex-blob | gzip --best > ${LOCAL_BACKUP_DIR}/mysql.bak.gz
|
||||||
|
|
||||||
## example with two dumps for each table (.sql/.txt) for all databases
|
## example with two dumps for each table (.sql/.txt) for all databases
|
||||||
# for i in $(echo SHOW DATABASES | mysql --defaults-extra-file=/etc/mysql/debian.cnf -P 3306 \
|
# for i in $(echo SHOW DATABASES | mysql --defaults-extra-file=/etc/mysql/debian.cnf -P 3306 \
|
||||||
|
@ -146,7 +149,7 @@ trap "rm -f $PIDFILE" EXIT
|
||||||
# instance=$(echo "$instance"|awk '{ print $3 }')
|
# instance=$(echo "$instance"|awk '{ print $3 }')
|
||||||
# if [ "$instance" != "3306" ]
|
# if [ "$instance" != "3306" ]
|
||||||
# then
|
# then
|
||||||
# mysqldump -P $instance --opt --all-databases --hex-blob -u mysqladmin -p$mysqladminpasswd > /home/backup/mysql.$instance.bak
|
# mysqldump -P $instance --opt --all-databases --hex-blob -u mysqladmin -p$mysqladminpasswd > ${LOCAL_BACKUP_DIR}/mysql.$instance.bak
|
||||||
# fi
|
# fi
|
||||||
# done
|
# done
|
||||||
|
|
||||||
|
@ -154,31 +157,31 @@ trap "rm -f $PIDFILE" EXIT
|
||||||
|
|
||||||
## example with pg_dumpall (warning: you need space in ~postgres)
|
## example with pg_dumpall (warning: you need space in ~postgres)
|
||||||
# su - postgres -c "pg_dumpall > ~/pg.dump.bak"
|
# su - postgres -c "pg_dumpall > ~/pg.dump.bak"
|
||||||
# mv ~postgres/pg.dump.bak /home/backup/
|
# mv ~postgres/pg.dump.bak ${LOCAL_BACKUP_DIR}/
|
||||||
## another method with gzip directly piped
|
## another method with gzip directly piped
|
||||||
# cd /var/lib/postgresql
|
# cd /var/lib/postgresql
|
||||||
# sudo -u postgres pg_dumpall | gzip > /home/backup/pg.dump.bak.gz
|
# sudo -u postgres pg_dumpall | gzip > ${LOCAL_BACKUP_DIR}/pg.dump.bak.gz
|
||||||
# cd - > /dev/null
|
# cd - > /dev/null
|
||||||
|
|
||||||
## example with all tables from MYBASE excepts TABLE1 and TABLE2
|
## example with all tables from MYBASE excepts TABLE1 and TABLE2
|
||||||
# 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
|
# 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 only TABLE1 and TABLE2 from MYBASE
|
## example with only TABLE1 and TABLE2 from MYBASE
|
||||||
# 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
|
# 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
|
||||||
|
|
||||||
## MongoDB : example with mongodump
|
## MongoDB : example with mongodump
|
||||||
## don't forget to create use with read-only access
|
## don't forget to create use with read-only access
|
||||||
## > use admin
|
## > use admin
|
||||||
## > db.createUser( { user: "mongobackup", pwd: "PASS", roles: [ "backup", ] } )
|
## > db.createUser( { user: "mongobackup", pwd: "PASS", roles: [ "backup", ] } )
|
||||||
# test -d /home/backup/mongodump/ && rm -rf /home/backup/mongodump/
|
# test -d ${LOCAL_BACKUP_DIR}/mongodump/ && rm -rf ${LOCAL_BACKUP_DIR}/mongodump/
|
||||||
# mkdir -p -m 700 /home/backup/mongodump/
|
# mkdir -p -m 700 ${LOCAL_BACKUP_DIR}/mongodump/
|
||||||
# mongodump --quiet -u mongobackup -pPASS -o /home/backup/mongodump/
|
# mongodump --quiet -u mongobackup -pPASS -o ${LOCAL_BACKUP_DIR}/mongodump/
|
||||||
# if [ $? -ne 0 ]; then
|
# if [ $? -ne 0 ]; then
|
||||||
# echo "Error with mongodump!"
|
# echo "Error with mongodump!"
|
||||||
# fi
|
# fi
|
||||||
|
|
||||||
## Redis : example with copy .rdb file
|
## Redis : example with copy .rdb file
|
||||||
# cp /var/lib/redis/dump.rdb /home/backup/
|
# cp /var/lib/redis/dump.rdb ${LOCAL_BACKUP_DIR}/
|
||||||
|
|
||||||
## ElasticSearch, take a snapshot as a backup.
|
## ElasticSearch, take a snapshot as a backup.
|
||||||
## Warning: You need to have a path.repo configured.
|
## Warning: You need to have a path.repo configured.
|
||||||
|
@ -202,48 +205,48 @@ trap "rm -f $PIDFILE" EXIT
|
||||||
# curl -s -XPUT "localhost:9200/_snapshot/snaprepo/snapshot_${date}?wait_for_completion=true" -o /tmp/es_snapshot_${date}.log
|
# curl -s -XPUT "localhost:9200/_snapshot/snaprepo/snapshot_${date}?wait_for_completion=true" -o /tmp/es_snapshot_${date}.log
|
||||||
|
|
||||||
## RabbitMQ : export config
|
## RabbitMQ : export config
|
||||||
#rabbitmqadmin export /home/backup/rabbitmq.config >> /var/log/evobackup.log
|
#rabbitmqadmin export ${LOCAL_BACKUP_DIR}/rabbitmq.config >> /var/log/evobackup.log
|
||||||
|
|
||||||
## Dump MBR / table partitions with dd and sfdisk
|
## Dump MBR / table partitions with dd and sfdisk
|
||||||
## Linux
|
## Linux
|
||||||
#for disk in $(ls /dev/[sv]d[a-z] 2>/dev/null); do
|
#for disk in $(ls /dev/[sv]d[a-z] 2>/dev/null); do
|
||||||
# name=$(basename $disk)
|
# name=$(basename $disk)
|
||||||
# dd if=$disk of=/home/backup/MBR-$name bs=512 count=1 2>&1 | egrep -v "(records in|records out|512 bytes)"
|
# dd if=$disk of=${LOCAL_BACKUP_DIR}/MBR-$name bs=512 count=1 2>&1 | egrep -v "(records in|records out|512 bytes)"
|
||||||
# fdisk -l $disk > /home/backup/partitions-$name
|
# fdisk -l $disk > ${LOCAL_BACKUP_DIR}/partitions-$name
|
||||||
#done
|
#done
|
||||||
#cat /home/backup/partitions-* > /home/backup/partitions
|
#cat ${LOCAL_BACKUP_DIR}/partitions-* > ${LOCAL_BACKUP_DIR}/partitions
|
||||||
## OpenBSD
|
## OpenBSD
|
||||||
# disklabel sd0 > /home/backup/partitions
|
# disklabel sd0 > ${LOCAL_BACKUP_DIR}/partitions
|
||||||
|
|
||||||
# backup MegaCli config
|
# backup MegaCli config
|
||||||
#megacli -CfgSave -f /home/backup/megacli_conf.dump -a0 >/dev/null
|
#megacli -CfgSave -f ${LOCAL_BACKUP_DIR}/megacli_conf.dump -a0 >/dev/null
|
||||||
|
|
||||||
## Dump system and kernel versions
|
## Dump system and kernel versions
|
||||||
uname -a > /home/backup/uname
|
uname -a > ${LOCAL_BACKUP_DIR}/uname
|
||||||
|
|
||||||
## Dump network routes with mtr and traceroute (warning: could be long with aggressive firewalls)
|
## 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
|
for addr in 8.8.8.8 www.evolix.fr travaux.evolix.net; do
|
||||||
mtr -r $addr > /home/backup/mtr-${addr}
|
mtr -r ${addr} > ${LOCAL_BACKUP_DIR}/mtr-${addr}
|
||||||
traceroute -n $addr > /home/backup/traceroute-${addr} 2>&1
|
traceroute -n ${addr} > ${LOCAL_BACKUP_DIR}/traceroute-${addr} 2>&1
|
||||||
done
|
done
|
||||||
|
|
||||||
## Dump process with ps
|
## Dump process with ps
|
||||||
ps auwwx >/home/backup/ps.out
|
ps auwwx >${LOCAL_BACKUP_DIR}/ps.out
|
||||||
|
|
||||||
if [ "$SYSTEM" = "linux" ]; then
|
if [ "${SYSTEM}" = "linux" ]; then
|
||||||
## Dump network connections with netstat
|
## Dump network connections with netstat
|
||||||
netstat -taupen >/home/backup/netstat.out
|
netstat -taupen > ${LOCAL_BACKUP_DIR}/netstat.out
|
||||||
|
|
||||||
## List Debian packages
|
## List Debian packages
|
||||||
dpkg -l >/home/backup/packages
|
dpkg -l > ${LOCAL_BACKUP_DIR}/packages
|
||||||
dpkg --get-selections >/home/backup/packages.getselections
|
dpkg --get-selections > ${LOCAL_BACKUP_DIR}/packages.getselections
|
||||||
apt-cache dumpavail >/home/backup/packages.available
|
apt-cache dumpavail > ${LOCAL_BACKUP_DIR}/packages.available
|
||||||
else
|
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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
##### REMOTE BACKUP ###################################################
|
##### REMOTE BACKUP ###################################################
|
||||||
|
@ -269,7 +272,7 @@ HOSTNAME=$(hostname)
|
||||||
|
|
||||||
BEGINNING=$(/bin/date +"%d-%m-%Y ; %H:%M")
|
BEGINNING=$(/bin/date +"%d-%m-%Y ; %H:%M")
|
||||||
|
|
||||||
if [ "$SYSTEM" = "linux" ]; then
|
if [ "${SYSTEM}" = "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"
|
||||||
|
@ -308,26 +311,26 @@ rsync -avzh --stats --delete --delete-excluded --force --ignore-errors --partial
|
||||||
--exclude "/var/lib/clamav/*.tmp" \
|
--exclude "/var/lib/clamav/*.tmp" \
|
||||||
--exclude "/home/mysqltmp" \
|
--exclude "/home/mysqltmp" \
|
||||||
--exclude "/var/lib/php/sessions" \
|
--exclude "/var/lib/php/sessions" \
|
||||||
$rep \
|
${rep} \
|
||||||
/etc \
|
/etc \
|
||||||
/root \
|
/root \
|
||||||
/var \
|
/var \
|
||||||
/home \
|
/home \
|
||||||
/srv \
|
/srv \
|
||||||
-e "ssh -p $SSH_PORT" \
|
-e "ssh -p ${SSH_PORT}" \
|
||||||
"root@$SSH_SERVER:/var/backup/" \
|
"root@${SSH_SERVER}:/var/backup/" \
|
||||||
| tail -30 >> /var/log/evobackup.log
|
| tail -30 >> /var/log/evobackup.log
|
||||||
|
|
||||||
END=$(/bin/date +"%d-%m-%Y ; %H:%M")
|
END=$(/bin/date +"%d-%m-%Y ; %H:%M")
|
||||||
|
|
||||||
##### REPORTING #######################################################
|
##### REPORTING #######################################################
|
||||||
|
|
||||||
echo "EvoBackup - $HOSTNAME - START $BEGINNING" \
|
echo "EvoBackup - ${HOSTNAME} - START ${BEGINNING}" \
|
||||||
>> /var/log/evobackup.log
|
>> /var/log/evobackup.log
|
||||||
|
|
||||||
echo "EvoBackup - $HOSTNAME - STOP $END" \
|
echo "EvoBackup - ${HOSTNAME} - STOP ${END}" \
|
||||||
>> /var/log/evobackup.log
|
>> /var/log/evobackup.log
|
||||||
|
|
||||||
tail -10 /var/log/evobackup.log | \
|
tail -10 /var/log/evobackup.log | \
|
||||||
mail -s "[info] EvoBackup - Client $HOSTNAME" \
|
mail -s "[info] EvoBackup - Client ${HOSTNAME}" \
|
||||||
$MAIL
|
${MAIL}
|
||||||
|
|
Loading…
Reference in a new issue