shellcheck fixes (#2)
This commit is contained in:
parent
cb42356bcd
commit
13e8b15ba3
11 changed files with 128 additions and 114 deletions
35
backupnaz.sh
35
backupnaz.sh
|
@ -1,19 +1,40 @@
|
||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
# Monthly backup script for my NAS
|
# Monthly backup script for my NAS
|
||||||
|
|
||||||
DEVICE=`readlink -f /dev/disk/by-id/usb-ST3000DM_001-1CH166_000000000000-0:0-part1`
|
#set -e
|
||||||
|
|
||||||
if grep $DEVICE /proc/mounts >/dev/null
|
DEVICE=/dev/sdb1
|
||||||
|
|
||||||
|
pass backups/disk | sudo /sbin/cryptsetup luksOpen $DEVICE backups "$@"
|
||||||
|
|
||||||
|
if grep /dev/mapper/backups /proc/mounts >/dev/null
|
||||||
then
|
then
|
||||||
echo "external drive ($DEVICE) seems to be mounted. good."
|
echo "external drive ($DEVICE) seems to be mounted. good."
|
||||||
else
|
else
|
||||||
if sudo mount $DEVICE /mnt/usb/
|
if sudo mount /dev/mapper/backups /mnt/backups/
|
||||||
then
|
then
|
||||||
echo "external drive ($DEVICE) successfuly mounted."
|
echo " * external drive ($DEVICE) successfuly mounted."
|
||||||
else
|
else
|
||||||
echo "FATAL: unable to mount"
|
echo " * FATAL: unable to mount"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
time ionice -c 2 sudo rsync --info=progress2 -av --delete --exclude-from /root/.backup_excludes naz:/mnt/md1/ /mnt/usb/
|
for slot in public private
|
||||||
|
do
|
||||||
|
echo
|
||||||
|
echo " * backing up $slot"
|
||||||
|
echo
|
||||||
|
time ionice -c 2 rsync --rsh='ssh -q -o RemoteCommand=none' --info=progress2 -av --delete --exclude-from ~/.backup_excludes naz:/nfs/$slot/ /mnt/backups/$slot/
|
||||||
|
done
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo " * unmounting"
|
||||||
|
echo
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
sync
|
||||||
|
|
||||||
|
sudo umount /dev/mapper/backups
|
||||||
|
sudo dmsetup remove /dev/mapper/backups
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
gpart destroy -F ada0
|
gpart destroy -F ada0
|
||||||
gpart create -s gpt ada0
|
gpart create -s gpt ada0
|
||||||
gpart add -s 222 -a 4k -t freebsd-boot -l boot0 ada0
|
gpart add -s 222 -a 4k -t freebsd-boot -l boot0 ada0
|
||||||
|
|
|
@ -12,13 +12,13 @@
|
||||||
# and maxdays is the maximum number of days before a message is deleted
|
# and maxdays is the maximum number of days before a message is deleted
|
||||||
#
|
#
|
||||||
# put it in the user's crontab:
|
# put it in the user's crontab:
|
||||||
# 50 * * * * /path/to/cleanmaildir.sh
|
# 50 * * * * /path/to/cleanmaildir
|
||||||
|
|
||||||
etcfile=/etc/cleanmaildir.conf
|
etcfile=/usr/local/etc/cleanmaildir.conf
|
||||||
|
|
||||||
for i in `cat $etcfile`
|
grep -v '^#' < $etcfile | while IFS= read -r i
|
||||||
do
|
do
|
||||||
dir=`echo $i | cut -f 1 -d ,`
|
dir=$(echo "$i" | cut -f 1 -d ,)
|
||||||
time=`echo $i | cut -f 2 -d ,`
|
time=$(echo "$i" | cut -f 2 -d ,)
|
||||||
find ~/Maildir/$dir/cur/* -mtime +`expr $time - 1` -exec rm '{}' \;
|
find "$HOME/Maildir/$dir/cur/" -type f -mtime +$(( time - 1)) -exec rm '{}' \;
|
||||||
done
|
done
|
||||||
|
|
2
dodo.sh
2
dodo.sh
|
@ -1 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
xset dpms force off
|
xset dpms force off
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
BACKUPDIR=/home/mysql_backup
|
BACKUPDIR=/home/backups/mysql
|
||||||
LOGFILE=${BACKUPDIR}/my_dump_mysql.log
|
LOGFILE=${BACKUPDIR}/my_dump_mysql.log
|
||||||
SENDNSCA=/usr/local/sbin/send_nsca\ -H\ <nagios_host>\ -d\ ';;'\ -c\ /usr/local/etc/nagios/send_nsca.cfg
|
SENDZABBIX="zabbix_sender --config /usr/local/etc/zabbix6/zabbix_agentd.conf --key mysql.backups"
|
||||||
HOSTNAME=`/bin/hostname -f | /usr/bin/cut -d '.' -f 1,2`
|
HOSTNAME=$(hostname -f | cut -d '.' -f 1,2)
|
||||||
backup_success=1
|
backup_success=1
|
||||||
|
|
||||||
mkdir -p ${BACKUPDIR}
|
mkdir -p ${BACKUPDIR}
|
||||||
rm -f ${LOGFILE};
|
rm -f ${LOGFILE};
|
||||||
|
|
||||||
for i in `echo 'show databases;' | mysql | grep -v Database`;
|
for i in $(mysql --skip-column-names --silent --raw --execute 'show databases;' | grep --invert-match Database);
|
||||||
do
|
do
|
||||||
echo -n " ---> backing up ${i}..." >> ${LOGFILE}
|
printf " ---> backing up %s..." "$i" >> ${LOGFILE}
|
||||||
mysqldump --add-drop-table --add-locks --create-options --disable-keys --extended-insert --single-transaction\
|
mysqldump --add-drop-table --add-locks --create-options --disable-keys --extended-insert --single-transaction\
|
||||||
--databases --lock-tables --quick --set-charset $i > ${BACKUPDIR}/$i.sql 2>> ${LOGFILE};
|
--databases --lock-tables --quick --set-charset "$i" | lbzip2 > "$BACKUPDIR/$i.sql.bz2" 2>> ${LOGFILE};
|
||||||
if [ $? -eq 0 ];
|
if [ $? ];
|
||||||
then
|
then
|
||||||
echo " OK" >> ${LOGFILE};
|
echo " OK" >> ${LOGFILE};
|
||||||
else
|
else
|
||||||
|
@ -24,7 +24,7 @@ done
|
||||||
|
|
||||||
if [ $backup_success -eq 1 ]
|
if [ $backup_success -eq 1 ]
|
||||||
then
|
then
|
||||||
echo "${HOSTNAME};;mysql_backups;;0;OK - backup succeeded at `date`" | ${SENDNSCA} >/dev/null
|
${SENDZABBIX} --value 0 >/dev/null
|
||||||
else
|
else
|
||||||
echo "${HOSTNAME};;mysql_backups;;2;CRITICAL - backup failed at `date`, please check ${LOGFILE} for complete report." | ${SENDNSCA} >/dev/null
|
${SENDZABBIX} --value 1 >/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -2,19 +2,19 @@
|
||||||
|
|
||||||
BACKUPDIR=/home/backups/postgresql
|
BACKUPDIR=/home/backups/postgresql
|
||||||
LOGFILE=${BACKUPDIR}/my_dump_postgresql.log
|
LOGFILE=${BACKUPDIR}/my_dump_postgresql.log
|
||||||
SENDNSCA=/usr/local/sbin/send_nsca\ -H\ <nagios_host>\ -d\ ';;'\ -c\ /usr/local/etc/nagios/send_nsca.cfg
|
SENDZABBIX="zabbix_sender --config /usr/local/etc/zabbix6/zabbix_agentd.conf --key pgsql.backups"
|
||||||
HOSTNAME=`/bin/hostname -f | /usr/bin/cut -d '.' -f 1,2`
|
HOSTNAME=$(/bin/hostname -f | /usr/bin/cut -d '.' -f 1,2)
|
||||||
backup_success=1
|
backup_success=1
|
||||||
|
|
||||||
mkdir -p ${BACKUPDIR}
|
mkdir -p ${BACKUPDIR}
|
||||||
rm -f ${LOGFILE}
|
rm -f ${LOGFILE}
|
||||||
cd ${BACKUPDIR}
|
cd ${BACKUPDIR} || backup_success=0
|
||||||
echo "start" >> ${LOGFILE}
|
echo "start" >> ${LOGFILE}
|
||||||
for i in `psql --list --tuples-only --port 6432 | grep -v template0 | grep -v template1 | cut -f 2 -d " " | sed '/^$/d' | tr "\n" " "`;
|
for i in $(psql --list --tuples-only --port 6432 | grep -v template0 | grep -v template1 | cut -f 2 -d " " | sed '/^$/d' | tr "\n" " ");
|
||||||
do
|
do
|
||||||
echo -n " ---> backing up ${i}..." >> ${LOGFILE}
|
printf " ---> backing up %s..." "$i" >> ${LOGFILE}
|
||||||
pg_dump --port 5432 ${i} > ${i}.sql && rm -f ${i}.sql.bz2 && bzip2 ${i}.sql >> ${LOGFILE};
|
pg_dump --port 6432 --format c "${i}" > "${i}".dump 2>> ${LOGFILE} 2>&1;
|
||||||
if [ $? -eq 0 ];
|
if [ $? ];
|
||||||
then
|
then
|
||||||
echo " OK" >> ${LOGFILE};
|
echo " OK" >> ${LOGFILE};
|
||||||
else
|
else
|
||||||
|
@ -24,8 +24,8 @@ done
|
||||||
|
|
||||||
if [ $backup_success -eq 1 ]
|
if [ $backup_success -eq 1 ]
|
||||||
then
|
then
|
||||||
echo "${HOSTNAME};;postgresql_backups;;0;OK - backup succeeded at `date`" | ${SENDNSCA} >/dev/null
|
${SENDZABBIX} --value 0 >/dev/null
|
||||||
else
|
else
|
||||||
echo "${HOSTNAME};;postgresql_backups;;2;CRITICAL - backup failed at `date`, please check ${LOGFILE} for complete report." | ${SENDNSCA} >/dev/null
|
${SENDZABBIX} --value 1 >/dev/null
|
||||||
fi
|
fi
|
||||||
echo "end" >> ${LOGFILE}
|
echo "end" >> ${LOGFILE}
|
||||||
|
|
10
pivotroot.sh
10
pivotroot.sh
|
@ -45,16 +45,18 @@ cp -vrp /etc/* ${CHROOTDIR}/etc/
|
||||||
chmod g+w ${CHROOTDIR}/run
|
chmod g+w ${CHROOTDIR}/run
|
||||||
|
|
||||||
echo "" > ${CHROOTDIR}/root/.bash_history
|
echo "" > ${CHROOTDIR}/root/.bash_history
|
||||||
echo "TERM=xterm-16color" >>${CHROOTDIR}/root/.profile #necessary for tmux/screen to work
|
{
|
||||||
echo "alias halt=\"echo 'o' > /proc/sysrq-trigger\"" >>${CHROOTDIR}/root/.profile
|
echo "TERM=xterm-16color" #necessary for tmux/screen to work
|
||||||
echo "alias reboot=\"echo 'b' > /proc/sysrq-trigger\"" >>${CHROOTDIR}/root/.profile
|
echo "alias halt=\"echo 'o' > /proc/sysrq-trigger\""
|
||||||
|
echo "alias reboot=\"echo 'b' > /proc/sysrq-trigger\""
|
||||||
|
} >> ${CHROOTDIR}/root/.profile
|
||||||
|
|
||||||
pivot_root ${CHROOTDIR} ${CHROOTDIR}/oldroot
|
pivot_root ${CHROOTDIR} ${CHROOTDIR}/oldroot
|
||||||
/sbin/dropbear -p ${CHROOTPORT}
|
/sbin/dropbear -p ${CHROOTPORT}
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "system pivot-rooted."
|
echo "system pivot-rooted."
|
||||||
echo "you can now connect with ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p ${CHROOTPORT} root@`hostname`, launch screen/tmux and shred"
|
echo "you can now connect with ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p ${CHROOTPORT} root@$(hostname), launch screen/tmux and shred"
|
||||||
echo "and finaly use reboot or halt commands (warning: they are not the real thing...)"
|
echo "and finaly use reboot or halt commands (warning: they are not the real thing...)"
|
||||||
echo
|
echo
|
||||||
echo "happy wiping!"
|
echo "happy wiping!"
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
|
|
||||||
#export DISPLAY=:0.0
|
|
||||||
echo "DISPLAY:$DISPLAY"
|
echo "DISPLAY:$DISPLAY"
|
||||||
|
|
||||||
Dir="~/img/wallpap/1920x1200/"
|
Dir="/home/n/img/wallpap/2560x1440/"
|
||||||
wallpaplist="~/.wallpaplist"
|
wallpaplist="/home/n/.cache/wallpaplist"
|
||||||
contact="n@tourmentine.com"
|
contact="n@tourmentine.com"
|
||||||
|
|
||||||
if [ ! -d "$Dir" ];
|
if [ ! -d "$Dir" ];
|
||||||
|
@ -19,47 +18,41 @@ then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
AvailableFiles=`ls -1 ${Dir} | wc -l`
|
AvailableFiles=$(find ${Dir} | wc -l)
|
||||||
AlreadyViewedFiles=`cat ${wallpaplist} | wc -l`
|
AlreadyViewedFiles=$(cat ${wallpaplist} | wc -l)
|
||||||
|
|
||||||
TotalFiles=`expr $AvailableFiles - $AlreadyViewedFiles`
|
TotalFiles=$((AvailableFiles-AlreadyViewedFiles))
|
||||||
|
|
||||||
if [ $TotalFiles -lt 1 ];
|
if [ "$TotalFiles" -lt 1 ];
|
||||||
then
|
then
|
||||||
echo "*** Seems we have displayed all available wallpapers; let's do the time warp...again. ***"
|
echo "*** Seems we have displayed all available wallpapers; let's do the time warp...again. ***"
|
||||||
echo ""> ${wallpaplist}
|
printf ""> ${wallpaplist}
|
||||||
echo "" | /usr/bin/mail -s "Seems we have displayed all available wallpapers; let's do the time warp...again." ${contact}
|
echo "" | /usr/bin/mail -s "Seems we have displayed all available wallpapers; let's do the time warp...again." ${contact}
|
||||||
TotalFiles=$AvailableFiles
|
TotalFiles=$AvailableFiles
|
||||||
fi
|
fi
|
||||||
|
|
||||||
RandomNumber=$(( $RANDOM % $TotalFiles ))
|
RandomNumber=$(shuf --input-range=1-"$TotalFiles" --head-count=1)
|
||||||
test ! $RandomNumber = 0 || RandomNumber=1
|
test ! "$RandomNumber" = 0 || RandomNumber=1
|
||||||
|
|
||||||
RandomFile="$( ls -1 ${Dir} | grep -w -v -F -f ${wallpaplist} | head -n $RandomNumber | tail -n 1)"
|
RandomFile="$(find ${Dir} -type f -printf '%f\n' | sort | grep -w -v -F -f ${wallpaplist} | head -n "$RandomNumber" | tail -n 1)"
|
||||||
if [[ ${RandomFile} == "" ]];
|
if [ "${RandomFile}" = "" ];
|
||||||
then
|
then
|
||||||
echo "*** Oops, something went wrong. erasing cache for security ***"
|
echo "*** Oops, something went wrong. erasing cache for security ***"
|
||||||
echo ""> ${wallpaplist}
|
printf ""> ${wallpaplist}
|
||||||
echo "" | /usr/bin/mail -s "Oops, something went wrong. erasing cache for security" ${contact}
|
echo "" | /usr/bin/mail -s "Oops, something went wrong. erasing cache for security" ${contact}
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
echo "${RandomFile}" >> ${wallpaplist}
|
echo "${RandomFile}" >> ${wallpaplist}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "${DBUS_SESSION_BUS_ADDRESS}" ] ; then
|
|
||||||
. ${HOME}/.dbus/session-bus/`ls -rt ${HOME}/.dbus/session-bus/ | tail -1`
|
|
||||||
export DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID
|
export DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID
|
||||||
fi
|
|
||||||
|
|
||||||
#echo ${DBUS_SESSION_BUS_ADDRESS}
|
AlreadyViewedFiles=$(cat ${wallpaplist} | wc -l)
|
||||||
|
echo "" | /usr/bin/mail -s "New wallpaper: ${RandomFile} (${AlreadyViewedFiles}/${AvailableFiles})" ${contact}
|
||||||
echo "" | /usr/bin/mail -s "New wallpaper: ${RandomFile}" ${contact}
|
echo "Selected File: $RandomFile, which is the ${AlreadyViewedFiles}th out of ${AvailableFiles}"
|
||||||
echo "Selected File: $RandomFile"
|
for workspace in 1 2 3 4
|
||||||
xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -s "${Dir%/}/${RandomFile}"
|
do
|
||||||
xfconf-query -c xfce4-desktop -v -p /backdrop/screen0/monitor0/last-image -s "${Dir%/}/${RandomFile}"
|
xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitorDisplayPort-${workspace}/workspace0/last-image -s "${Dir%/}/${RandomFile}" 2>/dev/null
|
||||||
xfconf-query -c xfce4-desktop -v -p /backdrop/screen0/monitorVGA1/workspace0/last-image -s "${Dir%/}/${RandomFile}"
|
done
|
||||||
xfconf-query -c xfce4-desktop -v -p /backdrop/screen0/monitor0/workspace0/last-image -s "${Dir%/}/${RandomFile}"
|
sleep 3h
|
||||||
pkill gkrellm && gkrellm &
|
|
||||||
# 3 hours
|
|
||||||
sleep 10800
|
|
||||||
done
|
done
|
||||||
|
|
10
superscreen
10
superscreen
|
@ -16,20 +16,20 @@ then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# main screen (physical host)
|
# main screen (physical host)
|
||||||
screen -d -m -S $session -t `hostname -s`
|
screen -d -m -S "$session" -t "$(hostname -s)"
|
||||||
|
|
||||||
# servers' screens : open a ssh connexion from the host to them, then rename it
|
# servers' screens : open a ssh connexion from the host to them, then rename it
|
||||||
for server in $servers
|
for server in $servers
|
||||||
do
|
do
|
||||||
window=$(( window + 1 ))
|
window=$(( window + 1 ))
|
||||||
screen -S $session -X screen ssh $server
|
screen -S "$session" -X screen ssh "$server"
|
||||||
screen -S $session -p $window -X title $server
|
screen -S "$session" -p "$window" -X title "$server"
|
||||||
done
|
done
|
||||||
|
|
||||||
# do not attach screen if "-d" option is set
|
# do not attach screen if "-d" option is set
|
||||||
if [ ! -z "$1" ]
|
if [ -n "$1" ]
|
||||||
then
|
then
|
||||||
if [ $1 == "-d" ]
|
if [ "$1" = "-d" ]
|
||||||
then
|
then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
25
supertmux
25
supertmux
|
@ -1,28 +1,25 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# supertmux: open a tmux session with ssh connections to some servers
|
# supertmux: open a tmux session with ssh connections to some servers
|
||||||
|
|
||||||
session=`hostname -s`
|
session=$(hostname -s)
|
||||||
servers="db dns ftp mail web"
|
servers="db dns ftp mail web"
|
||||||
|
|
||||||
tmux kill-server
|
tmux kill-server
|
||||||
tmux start-server
|
tmux start-server
|
||||||
|
|
||||||
tmux new-session -d -s $session;
|
tmux new-session -d -s "$session";
|
||||||
tmux rename-window $session
|
tmux rename-window hv
|
||||||
|
|
||||||
tmux set-option status-style fg=white,bg=black
|
|
||||||
tmux set-option -g status-right "[%D %H:%M]"
|
|
||||||
tmux set-option -g status-justify centre
|
|
||||||
|
|
||||||
counter=1
|
counter=1
|
||||||
for server in $servers
|
for server in $servers
|
||||||
do
|
do
|
||||||
tmux new-window -t $session:$counter
|
tmux new-window -t "$session":"$counter"
|
||||||
tmux select-window -t $session:$counter
|
tmux select-window -t "$session":"$counter"
|
||||||
tmux rename-window $server
|
tmux rename-window "$server"
|
||||||
tmux send -t $session:$counter "ssh $server" ENTER
|
tmux send -t "$session":"$counter" "ssh $server" ENTER
|
||||||
let counter=$counter+1 >/dev/null
|
counter=$(( counter + 1 ))
|
||||||
done
|
done
|
||||||
|
|
||||||
tmux select-window -t $session:0
|
tmux select-window -t "$session":0
|
||||||
tmux attach-session -t $session
|
tmux attach-session -t "$session"
|
||||||
|
|
57
zfsync.sh
57
zfsync.sh
|
@ -8,52 +8,49 @@
|
||||||
#
|
#
|
||||||
# or manually:
|
# or manually:
|
||||||
#
|
#
|
||||||
# - destroy all snapshots on both local & ${bro}
|
# - destroy all snapshots on both local & $bro
|
||||||
# - for i in ftp web mail; do zfs snapshot servers/$i/home@newsync ;done
|
# - for i in ftp web mail; do zfs snapshot servers/$i/home@newsync ;done
|
||||||
# - for i in ftp web mail; do zfs send servers/$i/home@newsync | ssh ${bro} zfs receive -vFd servers ;done
|
# - for i in ftp web mail; do zfs send servers/$i/home@newsync | ssh "$bro" zfs receive -vFd servers ;done
|
||||||
# - for i in ftp web mail; do zfs rename servers/$i/home@newsync servers/$i/home@prevsync ;done
|
# - for i in ftp web mail; do zfs rename servers/$i/home@newsync servers/$i/home@prevsync ;done
|
||||||
# - ssh ${bro} 'for i in ftp web mail; do zfs rename servers/$i/home@newsync servers/$i/home@prevsync ;done'
|
# - ssh "$bro" 'for i in ftp web mail; do zfs rename servers/$i/home@newsync servers/$i/home@prevsync ;done'
|
||||||
|
|
||||||
|
|
||||||
bro="small"
|
bro="{{ bro }}"
|
||||||
pools="ftp mail web"
|
pools="ftp mail web"
|
||||||
|
|
||||||
SENDNSCA=/usr/local/sbin/send_nsca\ -H\ 192.168.X.X\ -d\ ';;'\ -c\ /usr/local/etc/nagios/send_nsca.cfg
|
SENDZABBIX="zabbix_sender --config /usr/local/etc/zabbix6/zabbix_agentd.conf --key check.zfsync"
|
||||||
HOSTNAME=`/bin/hostname -f | /usr/bin/cut -d '.' -f 1,1`
|
HOSTNAME=$(/bin/hostname -f | /usr/bin/cut -d '.' -f 1,1)
|
||||||
SERVICENAME=zfsync
|
|
||||||
LOGFILE=/tmp/zfsync.log
|
|
||||||
LOCKFILE=/tmp/zfsync.lock
|
LOCKFILE=/tmp/zfsync.lock
|
||||||
ZROOT=zdata/servers
|
ZROOT=zdata/servers
|
||||||
sync_success=1
|
|
||||||
|
|
||||||
echo "`date`: ZFSync starting."
|
echo "$(date): ZFSync starting."
|
||||||
if [ -e $LOCKFILE ]
|
if [ -e "$LOCKFILE" ]
|
||||||
then
|
then
|
||||||
echo "ERROR: $0 is already running with pid `cat $LOCKFILE`, check $LOCKFILE"
|
echo "ERROR: $0 is already running with pid $(cat $LOCKFILE), check $LOCKFILE"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo ${$}>$LOCKFILE
|
echo ${$}>$LOCKFILE
|
||||||
|
|
||||||
alert()
|
alert()
|
||||||
{
|
{
|
||||||
echo "${HOSTNAME};;${SERVICENAME};;2;CRITICAL - ZFS Sync failed at `date`, please check ${LOGFILE} for complete report." | ${SENDNSCA} >/dev/null
|
${SENDZABBIX} --value 1 >/dev/null
|
||||||
exit $?
|
exit $?
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ $1 ]
|
if [ "$1" ]
|
||||||
then
|
then
|
||||||
if [ $1 = "init" ]
|
if [ "$1" = "init" ]
|
||||||
then
|
then
|
||||||
echo "wiping previous syncs"
|
echo "wiping previous syncs"
|
||||||
for snapshot in `zfs list -t snapshot -o name | grep -e prevsync -e newsync`; do zfs destroy $snapshot ; done
|
for snapshot in $(zfs list -t snapshot -o name | grep -e prevsync -e newsync); do zfs destroy "$snapshot" ; done
|
||||||
ssh -q ${bro} 'for snapshot in `zfs list -t snapshot -o name | grep -e prevsync -e newsync`; do zfs destroy $snapshot ; done'
|
ssh -q "$bro" 'for snapshot in $(zfs list -t snapshot -o name | grep -e prevsync -e newsync); do zfs destroy $snapshot ; done'
|
||||||
echo "making full snapshots"
|
echo "making full snapshots"
|
||||||
for jail in $pools; do zfs snapshot $ZROOT/$jail/home@newsync;done
|
for jail in $pools; do zfs snapshot "$ZROOT/$jail/home@newsync";done
|
||||||
echo "sending full snapshots"
|
echo "sending full snapshots"
|
||||||
for jail in $pools; do zfs send $ZROOT/$jail/home@newsync | ssh -q ${bro} 'zfs receive -vFdu zdata' ;done
|
for jail in $pools; do zfs send "$ZROOT/$jail/home@newsync" | ssh -q "$bro" 'zfs receive -vFdu zdata' ;done
|
||||||
echo "renaming them to use them as a base for diff snapshots"
|
echo "renaming them to use them as a base for diff snapshots"
|
||||||
for jail in $pools; do zfs rename $ZROOT/$jail/home@newsync $ZROOT/$jail/home@prevsync ;done
|
for jail in $pools; do zfs rename "$ZROOT/$jail/home@newsync" "$ZROOT/$jail/home@prevsync" ;done
|
||||||
ssh -q ${bro} 'for jail in ftp mail web; do zfs rename zdata/servers/$jail/home@newsync zdata/servers/$jail/home@prevsync ;done'
|
ssh -q "$bro" 'for jail in ftp mail web; do zfs rename zdata/servers/$jail/home@newsync zdata/servers/$jail/home@prevsync ;done'
|
||||||
exit $?
|
exit $?
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -62,20 +59,20 @@ for pool in $pools
|
||||||
do
|
do
|
||||||
dataset="$ZROOT/${pool}/home"
|
dataset="$ZROOT/${pool}/home"
|
||||||
echo "making new snapshot for ${pool}"
|
echo "making new snapshot for ${pool}"
|
||||||
zfs snapshot ${dataset}@newsync || alert
|
zfs snapshot "${dataset}@newsync" || alert
|
||||||
echo "sending snapshot"
|
echo "sending snapshot"
|
||||||
ssh -q ${bro} "zfs set readonly=on ${dataset}" || alert
|
ssh -q "$bro" "zfs set readonly=on ${dataset}" || alert
|
||||||
sleep 2
|
sleep 2
|
||||||
zfs send -i @prevsync ${dataset}@newsync | ssh -q ${bro} "zfs receive -vFdu zdata" || alert
|
zfs send -i @prevsync "${dataset}@newsync" | ssh -q "$bro" "zfs receive -vFdu zdata" || alert
|
||||||
ssh -q ${bro} "zfs set readonly=off ${dataset}" || alert
|
ssh -q "$bro" "zfs set readonly=off ${dataset}" || alert
|
||||||
echo "cleaning"
|
echo "cleaning"
|
||||||
zfs destroy ${dataset}@prevsync || alert
|
zfs destroy "${dataset}@prevsync" || alert
|
||||||
zfs rename ${dataset}@newsync ${dataset}@prevsync || alert
|
zfs rename "${dataset}@newsync" "${dataset}@prevsync" || alert
|
||||||
ssh -q ${bro} "zfs destroy ${dataset}@prevsync && zfs rename ${dataset}@newsync ${dataset}@prevsync" || alert
|
ssh -q "$bro" "zfs destroy ${dataset}@prevsync && zfs rename ${dataset}@newsync ${dataset}@prevsync" || alert
|
||||||
done
|
done
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "${HOSTNAME};;${SERVICENAME};;0;OK - ZFS Sync succeeded at `date`" | ${SENDNSCA} >/dev/null
|
${SENDZABBIX} --value 0 >/dev/null
|
||||||
|
|
||||||
rm -f $LOCKFILE
|
rm -f $LOCKFILE
|
||||||
echo "`date`: ZFSync ending."
|
echo "$(date): ZFSync ending."
|
||||||
|
|
Loading…
Reference in a new issue