Automatic poweroff and poweron to save energy

Alfons

Active Member
Sep 2, 2018
3
0
41
41
Hello,

I am running a dedicated proxmox backup server. All backup clients are configured to run their backups once per week at around 11am of sunday as this is the time, where almost no user activity is active. Consequently the backup server does not need to run during the week between Monday and Saturday. I try to configure the backup server to automatically start on sunday morning at 10am and stop after all backup activity is finished. It turned out that this is not as easy as I thought. My server cannot start automatically on every sunday. At least I did not find any way to achieve this. But I came up with a solution to start automatically every day at a given time with this script:

Code:
#!/bin/bash

# uncomment for debugging
#set -x

# get day of tomorrow
tomorrow=$(date -d"+1 day $1" "+%Y%m%d")
start_time="100000"
start_at=$tomorrow$start_time

# stop pc and start it next day at 10am
rtcwake -m off --date $start_at

My intention is to run this script every hour by cron. If there is no backup activity going on the pc will power down and is waking up automatically the next day.

There are some problems I could not resolve yet

1. The above script does not work when I run it from cron. I have to run it by hand on the console. Could someone explain how to make it work from cron.
2. I would like to check if there is some backup activity running to prevent the backup server to stop before all activity is done. How could I achieve this?

many thanks for all comments
 
a) Maybe you can boot up the backup server by means of "wake-on-LAN" from one of the running servers.

b) As for 1.: cron may require setting the PATH variable in the beginning of the script so that the particular commands in the script could be found. If that doesn't help you can insert some debugging commands to log the output to a file or mail the results. Does any entries from cron exist in syslog or in journalctl? You can check the local mailbox as well, as cron jobs usually send results or errors by mail to the owner of the job.

c) About 2.: Unfortunately I have no ready answer.
 
a) Maybe you can boot up the backup server by means of "wake-on-LAN" from one of the running servers.
I was thinking about that too as it would allow to keep the backup server switched off. It would automatically start whenever a client wants to run a backup. Unfortunately I did not manage to get the wol added to the backup functionality of the proxmox nodes and proxmox backup clients. Thats why I chose the method to start the backup server with the realtime clock.
b) As for 1.: cron may require setting the PATH variable in the beginning of the script so that the particular commands in the script could be found. If that doesn't help you can insert some debugging commands to log the output to a file or mail the results. Does any entries from cron exist in syslog or in journalctl? You can check the local mailbox as well, as cron jobs usually send results or errors by mail to the owner of the job.
I tried to run the commands in the script with the full path to avoid that. But it did not help
 
Last edited:
Unfortunately I did not manage to get the wol added to the backup functionality of the proxmox nodes and proxmox backup clients.
You wrote: "All backup clients are configured to run their backups once per week at around 11am of sunday".
So you need not to add WOL to backup functionality nor backup clients. It would be enough to issue WOL from a cron in one of the machines on Sunday about 10:50. But maybe I'm misunderstanding the situation :-).
I tried to run the commands in the script with the full path to avoid that. But it did not help
Anything in the syslog or journalctl or in the mailbox?
 
You wrote: "All backup clients are configured to run their backups once per week at around 11am of sunday".
So you need not to add WOL to backup functionality nor backup clients. It would be enough to issue WOL from a cron in one of the machines on Sunday about 10:50. But maybe I'm misunderstanding the situation :-).
Actually you are right. I was thinking to keep the startup and shutdown together at one place. But using wol and starting the server from a client is actually easier. And it allows to only startup once a week instead of every day. It has the disadvantage that it requires all backup clients to run at the same day and time. But this is the case for me anyway.
Anything in the syslog or journalctl or in the mailbox?
It did not note anything. Nevermind, I just checked that wol works correctly. So I will switch from rtcwake to wol. Now I only need to figure out how to determine if a backup process is running. When knowing how to do that I can run a cronjob every hour which checks if the backup server is idle and if so will shut it down.
 
Last edited: