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 19:01] – herwarth | bareos_power_on_off_sd [2017/02/18 19:09] (current) – herwarth | ||
|---|---|---|---|
| Line 6: | Line 6: | ||
| 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. | ||
| - | =====Philosophy===== | + | =====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 | + | 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 - / | <code - / | ||
| Job { | Job { | ||
| Line 119: | Line 120: | ||
| done | 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 - / | ||
| + | #!/bin/bash | ||
| + | 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> | {{tag> | ||