Is there a way I can generate .job files from a script. So I if I want to deploy the same job to a bunch of desktops, I might want to change say the time and folder that is backed up. Right now the best way I know is to go to the \\computer share, scheduled tasks, double click and edit it.

Note: This is ntbackup (built in to XP), not netbackup.

I am also wondering how setting the password would work for this. I want to backup open files, so I need an administrator account I think to use the Volume Shadow Copy service.

link|improve this question

78% accept rate
feedback

2 Answers

up vote 2 down vote accepted

I'm having a little trouble parsing you. I think you're talking about Scheduled Task ".JOB" files to fire off NTBACKUP.

Have a look at the SchTasks.EXE tool. It will allow you to script the creation, deletion, modification, etc of Scheduled Tasks on local and remote computers. I'd guess that you can get the functionality you're looking for there.

NTBACKUP uses the Windows BackupFile APIs, so you can get away w/ using an account that is a member of the "BUILTIN\Backup Operators" group. If the PCs are domain members and you're not squeamish about using the same account on all of them, I'd create a domain account and nest it into the "Backup Operators" group on each PC using the "Restricted Groups" functionality of Group Policy. Then, I'd use a startup script to query for and, if not present, deploy a scheduled task with the desired backup parameters onto that computer. The deployment script will need the plaintext password of the backup account in it, so I'd make the startup script readable only by "Domain Computers" (and not "Authenticated Users" as it is by default).

Edit:

I'd just create the task on the remote computer w/ SchTasks.Exe-- I wouldn't bother trying to copy the .JOB files around at all. That's probably asking for trouble, actually.

You could write a startup script that would do something like:

@echo off
SET TASK_NAME=Task name
SET TASK_USER=User_for_task_to_run_under
SET TASK_USER_PW=Password_for_user_to_run_task_under

rem Escape any quotes in the task command with slashes (i.e. \")
SET TASK_CMD=%SystemRoot%\System32\ntbackup.exe backup @Selection_List_Name.bks \"Job Description\" /F C:\Backup_Set.bkf

schtasks /query /fo LIST | find "%TASK_NAME%" >NUL 2>NUL
if errorlevel 1 goto create_task
goto end

:create_task
schtasks /create /RU %TASK_USER% /RP %TASK_USER_PW% /SC WEEKLY /D MON,TUE,WED,THU,FRI /ST 02:00:00 /TN "%TASK_NAME%" /TR "%TASK_CMD%"

:end

That should give you a good start. You'll still want to get your backup selection lists out to the clients (or specify the selections on the NtBackup command line).

re: Adding a user to "Backup Operators" on groups of computers - You should read-up on the "Restricted Groups" functionality in Group Policy. The functionality was originally meant to control the membership of "sensitive" groups, but it's been used frequently to automate group membership. Do some seraching on Microsoft's site for docs and setup a test OU and a test computer to play with it. You'll be glad you did.

link|improve this answer
So I see the ntbackup command line in the job file. Windows lets me copy that JOB file to my desktop, and then to the scheduled task of another computer. Will that work? Then I can modify them with SchTasks.exe ? – Kyle Brandt Aug 25 '09 at 17:31
Can I add a user to the Backup Operators group via AD, or does it need to be done on each workstation? – Kyle Brandt Aug 25 '09 at 17:34
feedback

I built a tool a while back that may be useful for you, basically, instead of scheduling a task that points at NTbackup, you schedule a task that runs a python script that consults a XML document that has the backup schedules. The python script determines what to backup, and then runs ntbackup with the configuration described in the document.

The great advantage of this, is that once you have things setup, you can simply adjust the backup selections by editing the xml document you have stored on some central server.

Even if you don't want to use the script, you can use it as an example for how to programatically create the backup selection files (bks). The BKS files are basically just a unicode text file without the BOM.


Updated to address comment

Is there an editor that will let me just edit the bkf file, opening with notepad and doing save as with unicode doesn't seem to cut it, ntbackup just crashes.

I am not aware of any text editors that would work, and I tried several. I hacked together a quick script for that should convert a text file with selections in it to a working bks.

link|improve this answer
Is there an editor that will let me just edit the bkf file, opening with notepad and doing save as with unicode doesn't seem to cut it, ntbackup just crashes. – Kyle Brandt Aug 26 '09 at 14:49
Linux or Windows would be fine – Kyle Brandt Aug 26 '09 at 14:50
Updated with a converter script. If you have more questions, I am regularly in the #serverfault channel on freenode. – Zoredache Aug 27 '09 at 8:09
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.