How to set a machine to switch on and off for scheduled backups

1. Introduction

To reduce energy consumption you may wish to set your machine to wake from sleep just before your scheduled backup is due to run. You can then either allow it to return to sleep automatically afterwards or force it to sleep when the backup completes. Alternatively if you leave your machine on for the backup you may wish to get it to shutdown automatically when the backup completes.

Note: it used to be possible to have your machine woken for backup but the Energy Efficiency and Monitoring (EEM) service we used to do this was withdrawn at the end of August 2017 so this is no longer possible.

If your computer is a Mac we recommend that you leave your machine to go to sleep, put it to sleep when you go home. It should then wake itself automatically for backup and return to sleep afterwards. This facility is available from TSM 6.4.1.5 onwards (if you need to upgrade TSM please see our page on downloading the TSM client for the Mac).

2. Setting a machine to wake from sleep before scheduled backups

This is not necessary on Mac computers which will wake automatically. For Windows and Linux computers you must first know when your backup is scheduled - consult the HFS Backup & Archive services portal to obtain this information.

2.1 Windows

  1. Start the Task Scheduler (from Administrativr Tools, or search for Task Scheduler in the Start Menu)
  2. From the Actions pane on the right hand side select Create Task.
  3. A new window will open. Under the General tab fill in the Name (e.g. Wake for backup),  and select Run with highest privileges.
  4. On the Triggers tab click New. The New Trigger window will open. Select Weekly, the day of your scheduled backup, and the time to wake - we recommend a couple of minutes before your backup is scheduled to start and OK.
  5. On the Actions tab click New. Here you need to select something that will be done. It doesn't matter what as the scheduler is waking the computer to run the task, the task itself doesn't matter. A good choice is to put as  Program/script cmd /c exit. 
  6. On the Conditions tab select Wake the computer to run this task.
  7. Click OK and close the Task Scheduler. 

2.2 Linux

It's not quite as straightforward on Linux but you may be able to use the rtcwake command (see man rtcwake for details). For example

rtcwake -m no -u -t $(date +%s -d 'tomorrow 01:30')

would schedule a wake up at 01:30 tomorrow (-m no means don't put the machine to sleep now, -u means the real time clock is using UTC). You could schedule such a command with cron if you wished. Schedule the command to run at a time when the machine won't be asleep.

3. Setting a machine to sleep after scheduled backups

If your machine is configured to sleep after a period of inactivity this is not really necessary as it will go to sleep automatically after the backup is completed. However if you prefer to have your machine sleep only when you tell it you may wish to put it to sleep after a backup has completed.

3.1. Windows

  1. You need to edit the file dsm.opt, which is to be found in C:\Program Files\Tivoli\TSM\baclient. Permissions to edit the contents of C:\Program Files are limited. We therefore recommend that you move dsm.opt to the desktop before you open it for editing by dragging dsm.opt to the desktop. (An alternative is to run your text editor as administrator before using it to open dsm.opt.)
  2. Now double-click on dsm.opt to edit it. You can use Notepad or Wordpad as editor, if Windows asks which program you wish to use. Add the line:
    PostNScheduleCmd 'rundll32.exe powrprof.dll,SetSuspendState 0,1,0'                        
    
  3. Save dsm.opt. If you moved it from C:\Program Files to your desktop in order to edit it, now move it back.
  4. The TSM scheduler now needs to be restarted in order for it to see the changes that you have made. If you will be restarting your computer before the next scheduled backup, then the scheduler restart will happen automatically; if not, you do need to do this manually, on which please see our page on restarting the TSM scheduler in Windows.

3.2 Linux

  1. Edit the file /opt/tivoli/tsm/client/ba/bin/dsm.sys and add the line:
    PostNScheduleCmd "rtcwake -m mem -s 864000"                        

This will put the system to sleep when the backup completes. The rtcwake command requires a time to reawaken the computer in this example it is in ten days time. Alternatively using systemctl suspend as the command may work better on systems that have systemd.

4. Setting a machine to switch off after scheduled backups

This section details the simple steps needed for users of desktop/laptop systems who wish to power off their machines after the HFS Scheduled backup completes.

Please ensure that your machine's 'Sleep mode' delay is set to at least three minutes so that it is still active when the shutdown request takes place. You can check the Power Management settings on your machine via Control Panel (Windows) or System Preferences (Mac).

4.1. Windows

  1. Right-click on an empty area of your desktop and select New > Text Document.
  2. Windows will create a new file for you, probably called New Text Document.txt. Rename it and make sure to give the file a name ending in .bat, e.g. myshutdown.bat, instead of .txt. If, when you change the name, you are asked, 'If you change a file name extension, the file might become unusable. Are you sure you want to change it?', click Yes.
  3. Now right-click the file, choose 'Edit', add the following line in it:
    shutdown.exe -s -f -t 120 -c "Post TSM Backup Shutdown"                           

    and save the file.

  4. Open the folder C:\Program Files\Tivoli\TSM\baclient and drag your .bat file into it.
  5. You now need to edit the file dsm.opt, which is also to be found in C:\Program Files\Tivoli\TSM\baclient. Permissions to edit the contents of C:\Program Files are limited. We therefore recommend that you move dsm.opt to the desktop before you open it for editing by dragging dsm.opt to the desktop. (An alternative is to run your text editor as administrator before using it to open dsm.opt.)
  6. Now double-click on dsm.opt to edit it. You can use Notepad or Wordpad as editor, if Windows asks which program you wish to use. Add the line:
    PostNScheduleCmd '"C:\Program Files\Tivoli\TSM\baclient\myshutdown.bat"'                        

    The argument to the PostNScheduleCmd option is the full pathname to the .bat that you just created. Ensure that you include both sets of quotes. (The inner quotes are required due to there being a space in the path name).

  7. Save dsm.opt. If you moved it from C:\Program Files to your desktop in order to edit it, now move it back.
  8. The TSM scheduler now needs to be restarted in order for it to see the changes that you have made. If you will be restarting your computer before the next scheduled backup, then the scheduler restart will happen automatically; if not, you do need to do this manually, on which please see our page on restarting the TSM scheduler in Windows.

Now each time the TSM scheduler subsequently completes a scheduled backup it will (-s) shutdown the local machine, (-f) forcing any open applications to close, (-t 120) waiting 120 seconds before commencing shutdown (see note below) and (-c) writing a message to both screen and Event Log. Here is one source for further information on Windows shutdown syntax among many others online.

Note that a delay of 120 seconds should be sufficient for the TSM scheduler to complete its session and sign off from the backup server having received a return code from it indicating success or failure of the scheduled backup. Shortening this delay by a considerable amount is not recommended.

Try not to leave files and/or applications open overnight. The -f option will not prompt for File-Save in any open applications so will result in a loss of all unsaved data. Without this option, the shutdown may not proceed if there are any open applications or files.

To disable the shutdown, just edit the dsm.opt file and remove the PostNScheduleCmd line.

4.2. macOS/OS X

  1. To set your Mac to switch off immediately after a backup has completed, copy the following script to a file 'myshutdown.sh' in the IBM Spectrum Protect or Tivoli Storage Manager folder under Applications:
    #!/bin/sh
    #
    #
    # myshutdown - shutdown using osascript to bypass the sudo requirement of
    #              /sbin/shutdown
    #
    # Note: DELAY is in seconds. Do not set to less than 120.
    #
    ##############################################################################
                               
    DELAY=180
                               
    /usr/bin/osascript <<END
    delay $DELAY
    tell app "System Events"
    shut down
    end
    END
    
  2. Now edit the file /Library/Preferences/Tivoli Storage Manager/dsm.sys and add one of the following lines depending on where you have written the previous script:
    PostNScheduleCmd '"/Applications/Tivoli Storage Manager/myshutdown.sh"' 

    ... or ...

    PostNScheduleCmd '"/Applications/IBM Spectrum Protect/myshutdown.sh"'                        

    The argument to the PostNScheduleCmd option is the full pathname to the file you have just created. Ensure that you include both sets of quotes. Note also that the precise text inside the quotes will vary according to the version of Tivoli Storage Manager installed on your machine and hence the name of the folder.

Now each time the TSM Scheduler subsequently completes a scheduled backup it will shutdown the local machine after a delay of 180 seconds. This delay should be sufficient for the TSM scheduler to complete its session and sign off from the backup server having received a return code from it indicating success or failure of the scheduled backup. Shortening this delay by a considerable amount is not recommended.

To disable the shutdown, just edit the /Library/Preferences/Tivoli Storage Manager/dsm.sys file and remove the PostNScheduleCmd line.

4.3. Linux

  1. Edit the file /opt/tivoli/tsm/client/ba/bin/dsm.sys and add the line:
    PostNScheduleCmd "shutdown -P +3"                        

Now each time the TSM Scheduler subsequently completes a scheduled backup it will shutdown the local machine after a delay of 3 minutes. This delay should be sufficient for the TSM scheduler to complete its session and sign off from the backup server having received a return code from it indicating success or failure of the scheduled backup. Shortening this delay by a considerable amount is not recommended.

To disable the shutdown, just edit the /opt/tivoli/tsm/client/ba/bin/dsm.sys file and remove the PostNScheduleCmd line.

Written by IT Services. Latest revision 29 August 2017