This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| bareos_power_on_off_sd [2017/02/18 18:52] – herwarth | bareos_power_on_off_sd [2017/02/18 19:09] (current) – herwarth | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ======Bareos SD power on/ | ||
| =====Introduction===== | =====Introduction===== | ||
| - | I have a SAS tapedrive connected to a dedicated server for backups. On this machine bareos-sd is running. I do not want the bareos-sd server powered on all the time when it is only backup-ping a litte time of the day. So I have made some scripts to power on and off the server. | + | I have a SAS tapedrive connected to a dedicated server for backups. On this machine bareos-sd is running. I do not want the bareos-sd server powered on all the time when it is only backup-ping a litte time of the day. |
| + | |||
| + | So I have made some scripts to power on and off the server. | ||
| The server is a Supermicro machine with IPMI, so I am using ipmiutils to power on/off the machine. | The server is a Supermicro machine with IPMI, so I am using ipmiutils to power on/off the machine. | ||
| - | ;tag=linux | + | =====Powering off the SD===== |
| + | The catalog backup runs with a lower priority so shutting down the server after the catalog backup makes sense. In a schedule I always end with creating a catalog backup. When the SD is powered down, I do not want to power it down again. | ||
| + | |||
| + | =====Catalog backup===== | ||
| + | <code - / | ||
| + | Job { | ||
| + | Name = catalog | ||
| + | Client = backup-mngt-bh | ||
| + | Type = Backup | ||
| + | Level = Full | ||
| + | Storage = disk-bh | ||
| + | Pool = disk | ||
| + | Messages = Standard | ||
| + | FileSet = catalog | ||
| + | Schedule = catalog | ||
| + | |||
| + | # Default | ||
| + | # | ||
| + | # Helux | ||
| + | RunBeforeJob = / | ||
| + | # Default | ||
| + | # | ||
| + | # Helux | ||
| + | RunAfterJob | ||
| + | # Write Bootstrap = " | ||
| + | Priority = 11 | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | <code - / | ||
| + | #!/bin/sh | ||
| + | # | ||
| + | # BAREOS® - Backup Archiving REcovery Open Sourced | ||
| + | # | ||
| + | # Copyright (C) 2000-2011 Free Software Foundation Europe e.V. | ||
| + | # Copyright (C) 2013-2014 Bareos GmbH & Co. KG | ||
| + | # | ||
| + | # This program is Free Software; you can redistribute it and/or | ||
| + | # modify it under the terms of version three of the GNU Affero General Public | ||
| + | # License as published by the Free Software Foundation and included | ||
| + | # in the file LICENSE. | ||
| + | # | ||
| + | # This program is distributed in the hope that it will be useful, but | ||
| + | # WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| + | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| + | # Affero General Public License for more details. | ||
| + | # | ||
| + | # You should have received a copy of the GNU Affero General Public License | ||
| + | # along with this program; if not, write to the Free Software | ||
| + | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
| + | # 02110-1301, USA. | ||
| + | # | ||
| + | # This script deletes a catalog dump | ||
| + | # | ||
| + | |||
| + | # | ||
| + | # Source the Bareos config functions. | ||
| + | # | ||
| + | . / | ||
| + | |||
| + | db_name=" | ||
| + | working_dir=`get_working_dir` | ||
| + | |||
| + | rm -f ${working_dir}/ | ||
| + | |||
| + | # added by Helux | ||
| + | / | ||
| + | </ | ||
| + | <code - / | ||
| + | # | ||
| + | BAREOS_SD_IP=172.16.2.23 | ||
| + | BAREOS_SD_PORT=9103 | ||
| + | IPMI_IP=172.16.2.18 | ||
| + | IPMI_USER=USER | ||
| + | IPMI_PASS=PASSWORD | ||
| + | SLEEP=5 | ||
| + | NUM_TRIES=6 | ||
| + | |||
| + | function check_bareos_sd { | ||
| + | nc -w1 $BAREOS_SD_IP $BAREOS_SD_PORT < /dev/null 2>/ | ||
| + | if [ $? -eq 0 ]; then | ||
| + | # if return value is 0 then port is reachable so we can exit the function with value 0 | ||
| + | return 0 | ||
| + | else | ||
| + | return 1 | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | COUNT=0 | ||
| + | while true; do | ||
| + | check_bareos_sd | ||
| + | if [ $? -eq 0 ]; then | ||
| + | # We are online, so add 1 to counter, sleep for $SLEEP seconds and continue loop | ||
| + | # $COUNT=0 then we can power off the machine using ssh | ||
| + | if [ $COUNT -eq 0 ]; then | ||
| + | ssh -t $BAREOS_SD_IP sudo / | ||
| + | fi | ||
| + | let COUNT=$COUNT+1 | ||
| + | sleep $SLEEP | ||
| + | else | ||
| + | # We are offline, so we can exit the loop | ||
| + | exit 0 | ||
| + | fi | ||
| + | # check if $COUNT reaches $NUM_TRIES and when it does do a hard power down | ||
| + | if [ $COUNT -eq $NUM_TRIES ]; then | ||
| + | ireset -d -N $IPMI_IP -U $IPMI_USER -P $IPMI_PASS >/ | ||
| + | if [ $? -eq 0 ]; then | ||
| + | exit 0 | ||
| + | else | ||
| + | exit 1 | ||
| + | fi | ||
| + | fi | ||
| + | done | ||
| + | </ | ||
| + | =====Powering on the SD when running a job===== | ||
| + | When I need to write a backup to the bareos-sd server, I need to power it on. But I do not want to power it on when it is already on. It is possible a job will be triggered with another job still running. | ||
| + | <code - / | ||
| + | Job { | ||
| + | . | ||
| + | . | ||
| + | . | ||
| + | RunBeforeJob = / | ||
| + | } | ||
| + | </ | ||
| + | <code - / | ||
| + | # | ||
| + | BAREOS_SD_IP=172.16.2.23 | ||
| + | BAREOS_SD_PORT=9103 | ||
| + | IPMI_IP=172.16.2.18 | ||
| + | IPMI_USER=USER | ||
| + | IPMI_PASS=PASSWORD | ||
| + | SLEEP=5 | ||
| + | NUM_TRIES=24 | ||
| + | |||
| + | function check_bareos_sd { | ||
| + | nc -w1 $BAREOS_SD_IP $BAREOS_SD_PORT < /dev/null 2>/ | ||
| + | if [ $? -eq 0 ]; then | ||
| + | # if return value is 0 then port is reachable so we can exit the function with value 0 | ||
| + | return 0 | ||
| + | else | ||
| + | return 1 | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | COUNT=0 | ||
| + | while true; do | ||
| + | check_bareos_sd | ||
| + | if [ $? -eq 0 ]; then | ||
| + | # We are online, so exit loop | ||
| + | exit 0 | ||
| + | else | ||
| + | # We are offline, so add 1 to counter, sleep for $SLEEP seconds and continue loop | ||
| + | # $COUNT=0 then we can power on the machine using ireset (ipmiutil) | ||
| + | if [ $COUNT -eq 0 ]; then | ||
| + | ireset -u -N $IPMI_IP -U $IPMI_USER -P $IPMI_PASS >/ | ||
| + | fi | ||
| + | let COUNT=$COUNT+1 | ||
| + | sleep $SLEEP | ||
| + | fi | ||
| + | # check if $COUNT reaches $NUM_TRIES and when it does exit with value 1 | ||
| + | if [ $COUNT -eq $NUM_TRIES ]; then | ||
| + | exit 1 | ||
| + | fi | ||
| + | done | ||
| + | </ | ||
| + | |||
| + | {{tag>linux}} | ||
| + | |||