Customizing Windows Server Backup Schedule over the Command line front-end for Windows› Task Scheduler

von http://blogs.technet.com/b/filecab/archive/2009/04/13/customizing-windows-server-backup-schedule.aspx:

Windows Server Backup (WSB) is the built-in backup solution for Windows Server 2008 that replaces the venerable NT Backup from Windows Server 2003 and before. WSB protects the files and the server os/application binaries within itself as a single-server solution. To consolidate protection across multiple servers or applications like SQL Server, Exchange, SharePoint or Hyper-V, then Microsoft would recommend looking at System Center Data Protection Manager (DPM).

By design, WSB ensures that you have recent backups by performing its local backup operations at least once per day. While this is good and recommended there may be reasons specific to your environment where you may want to take backups at a lesser frequency or have multiple backup schedules (e.g. daily and weekly). For example, you may want to backup your files every day, while backing up the system state at lesser frequency say once a week.

You can extend the functionality of Windows Server Backup to meet all these advanced needs through simple scripts that uses Windows Server Backup Command Line Tool (WBADMIN) and the Windows Task Scheduler (SCHTASKS).

If you are not aware of Task Scheduler, it is a a management application provided in Windows operating systems that allows you to schedule any task for a given set of conditions. Task Scheduler also provides a command line interface (CLI) through the command SCHTASKS.

Samples

The samples here assume the following configuration of the system:

  • A single disk containing system drive (C:),
  • Two data volumes (D: and E:)
  • Dedicated backup volumes (H:, I: and J:).

These volume names and parameters are used as boldface in the samples below. Readers can customize them as per their requirements.

Sample 1: Daily Data Volume Backup

The following command will create a Task Scheduler task named DailyVolumeBackup with the start time of 23:00. This task will run DAILY with the HIGHEST privileges. It will run the Windows Server Backup CLI to backup volume E: to target volume H:.

 Syntax:

SCHTASKS /Create /SC DAILY /TN <TaskName> /RL HIGHEST /ST <StartTime> /TR <Windows Server Backup Command>

Example:

SCHTASKS /Create /SC DAILY /TN DailyVolumeBackup /RL HIGHEST /ST 23:00 /TR «WBADMIN START BACKUP -backupTarget:H: -include:e: -quiet >> C:\backupLogs.txt»

Sample 2 : Weekly Backup of System State

The following command will create a Task Scheduler task named WeeklySystemStateBackup that runs every Saturday (SAT) at 19:00. This task will run WEEKLY with the HIGHEST privileges. It will run the Windows Server Backup CLI to backup SYSTEMSTATEBACKUP to target volume I:.

Syntax:

SCHTASKS /Create /SC WEEKLY /D <Day Of Week>  /TN <TaskName> /RL HIGHEST /ST <StartTime> /TR <Windows Server Backup Command>

Example:

SCHTASKS /Create /SC WEEKLY /D SAT /TN WeeklySystemStateBackup /RL HIGHEST /ST 19:00  /TR «WBADMIN START SYSTEMSTATEBACKUP -backupTarget:I: -quiet  >> C:\backupLogs.txt «

Sample 3 : Complete System Backup Once in Two Weeks

The following  command will create a Task Scheduler task named OnceInTwoWeeksFullBackup that runs every Sunday (SUN) at 1:00 once every 2 weeks. This task will run WEEKLY with the HIGHEST privileges. It will run the Windows Server Backup CLI to backup allCritical volumes to target volume J:.

Syntax:

SCHTASKS /Create /SC WEEKLY /MO <WeekFrequency Modifier>  /D <Day Of Week>  /TN <TaskName> /RL HIGHEST /ST <StartTime> /TR <Windows Server Backup Command>

Example:

SCHTASKS /Create /SC WEEKLY /MO 2 /D SUN  /TN OnceInTwoWeeksFullBackup /RL HIGHEST /ST 01:00  /TR «WBADMIN START BACKUP -backupTarget:J: -allCritical -quiet  >> C:\backupLogs.txt «

Notes:

  1. Above tasks needs to be ran with highest privileges as Windows Sever Backup requires administrative privileges to run. If you are using “Task Scheduler” UI to configure the jobs make sure you use the «[  ] Run with highest priviledges» UI option in the security options of the task.
  2. Since WBADMIN command will fail if any other backup job is already running, ensure that the backup jobs are scheduled with a sufficiently long time interval between two jobs.
  3. Backups scheduled using windows scheduler (SCHTASKS) will not appear in the Windows Server Backup application user interface.
  4. You can use a network location (i.e. \\servername\foldername) as a backup target in above commands. However, network backups will save only the latest version of the backup, deleting the previous version, as multiple versions on the network share are not supported.
  5. You can use other WBADMIN CLI options to customize the backup, such as the option vssFull. Please see Windows Server Backup CLI for more details on CLI options.
  6. You can use Task Scheduler advance functions  like setup  additional tasks to run before/after the above jobs.  Example of the pre-tasks are disabling an antivirus, closing a service etc. Example of the post-tasks are upload the logs, send an email etc.
  7. Since command line interface is interactive in nature and give error/completion information in the console itself, output of all the above invocation should be directed to a log file so that it can be referred in case of any error while running the backup.
  8. For optimal storage space utilization on the backup target you can modify the VSS shadow storage using the following command:
    vssadmin resize shadowstorage /for=<BackupTarget> /on=<BackupTarget> /maxsize=UNBOUNDED
    For example:
    vssadmin resize shadowstorage /for=H: /on=H: /maxsize=UNBOUNDED

 

und von http://www.robvanderwoude.com/schtasks.php :

 

Command line front-end for Windows› Task Scheduler

 

Note: This page shows the command line options for the Windows 7 version of SCHTASKS.
Click here for the Windows XP version of SCHTASKS.
Click

 

Syntax:

SCHTASKS /parameter [arguments]

Description:

Enables an administrator to create, delete, query, change, run and end scheduled tasks on a local or remote system.

Parameter List:

/Create Creates a new scheduled task.
/Delete Deletes the scheduled task(s).
/Query Displays all scheduled tasks.
/Change Changes the properties of scheduled task.
/Run Runs the scheduled task immediately.
/End Stops the currently running scheduled task.
/ShowSid Shows the security identifier corresponding to a scheduled task name.
/? Displays this help/usage.

Examples:

SCHTASKS
SCHTASKS /?
SCHTASKS /Run /?
SCHTASKS /End /?
SCHTASKS /Create /?
SCHTASKS /Delete /?
SCHTASKS /Query /?
SCHTASKS /Change /?
SCHTASKS /ShowSid /?

/RUN

SCHTASKS /Run [/S system [/U username [/P [password]]]] [/I] /TN taskname

Description:

Runs a scheduled task immediately.

Parameter List:

/S system Specifies the remote system to connect to.
/U username Specifies the user context under which the schtasks.exe should execute.
/P [password] Specifies the password for the given user context.
Prompts for input if omitted.
/I Runs the task immediately by ignoring any constraint.
/TN taskname Identifies the scheduled task to run now.
/? Displays this help message.

Examples:

SCHTASKS /Run /?
SCHTASKS /Run /TN «Start Backup»
SCHTASKS /Run /S system /U user /P password /I /TN «Backup and Restore»

/END

SCHTASKS /End [/S system [/U username [/P [password]]]] /TN taskname

Description:

Stops a running scheduled task.

Parameter List:

/S system Specifies the remote system to connect to.
/U username Specifies the user context under which the schtasks.exe should execute.
/P [password] Specifies the password for the given user context.
Prompts for input if omitted.
/TN taskname Specifies the scheduled task to terminate.
/? Displays this help/usage.

Examples:

SCHTASKS /End /?
SCHTASKS /End /TN «Start Backup»
SCHTASKS /End /S system /U user /P password /TN «Backup and Restore»

/CREATE

SCHTASKS /Create [/S system [/U username [/P [password]]]] [/RU username [/RP [password]]] /SC schedule [/MO modifier] [/D day] [/I idletime] /TN taskname /TR taskrun [/ST starttime] [/M months] [/SD startdate] [/RI interval] [ {/ET endtime | /DU duration} [/K] [/XML xmlfile] [/V1]] [/SD startdate] [/ED enddate] [/IT | /NP] [/Z] [/F]

Description:

Enables an administrator to create scheduled tasks on a local or remote systems.

Parameter List:

/S system Specifies the remote system to connect to.
If omitted the system parameter defaults to the local system.
/U username Specifies the user context under which the schtasks.exe should execute.
/P [password] Specifies the password for the given user context.
Prompts for input if omitted.
/RU username Specifies the «run as» user account (user context) under which the task runs.
For the system account, valid values are «», «NT AUTHORITY\SYSTEM» or «SYSTEM».
For v2 tasks, «NT AUTHORITY\LOCALSERVICE» and «NT AUTHORITY\NETWORKSERVICE» are also available as well as the well known SIDs for all three.
/RP [password] Specifies the password for the «run as» user.
To prompt for the password, the value must be either «*» or none.
This password is ignored for the system account.
Must be combined with either /RU or /XML switch.
/SC schedule Specifies the schedule frequency.
Valid schedule types: MINUTE, HOURLY, DAILY, WEEKLY, MONTHLY, ONCE, ONSTART, ONLOGON, ONIDLE, ONEVENT.
/MO modifier Refines the schedule type to allow finer control over schedule recurrence.
Valid values are listed in the «Modifiers» section below.
/D days Specifies the day of the week to run the task.
Valid values: MON, TUE, WED, THU, FRI, SAT, SUN and for MONTHLY schedules 1 – 31 (days of the month).
Wildcard «*» specifies all days.
/M months Specifies month(s) of the year.
Defaults to the first day of the month.
Valid values: JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC.
Wildcard «*» specifies all months.
/I idletime Specifies the amount of idle time to wait before running a scheduled ONIDLE task.
Valid range: 1 – 999 minutes.
/TN taskname Specifies a name which uniquely identifies this scheduled task.
/TR taskrun Specifies the path and file name of the program to be run at the scheduled time.
Example: C:\windows\system32\calc.exe
/ST starttime Specifies the time to run the task.
The time format is HH:MM:SS (24 hour time) for example, 14:30:00 for 2:30 PM.
Defaults to current time if /ST is not specified.
This option is required with /SC ONCE.
/SD startdate Specifies the first date on which the task runs.
The format is «dd/mm/yyyy».
/RI interval Specifies the repetition interval in minutes.
This is not applicable for schedule types: MINUTE, HOURLY, ONSTART, ONLOGON, ONIDLE, ONEVENT.
Valid range: 1 – 599940 minutes.
If either /ET or /DU is specified, then it defaults to 10 minutes.
/ET endtime Specifies the end time to run the task.
The time format is HH:mm (24 hour time) for example, 14:50 for 2:50 PM.
This is not applicable for schedule types: ONSTART, ONLOGON, ONIDLE, ONEVENT.
/DU duration Specifies the duration to run the task.
The time format is HH:mm.
This is not applicable with /ET and for schedule types: ONSTART, ONLOGON, ONIDLE, ONEVENT.
For /V1 tasks, if /RI is specified, duration defaults to 1 hour.
/K Terminates the task at the endtime or duration time.
This is not applicable for schedule types: ONSTART, ONLOGON, ONIDLE, ONEVENT.
Either /ET or /DU must be specified.
/SD startdate Specifies the first date on which the task runs.
The format is dd/mm/yyyy.
Defaults to the current date.
This is not applicable for schedule types: ONCE, ONSTART, ONLOGON, ONIDLE, ONEVENT.
/ED enddate Specifies the last date when the task should run.
The format is «dd/mm/yyyy».
/EC ChannelName Specifies the event channel for OnEvent triggers.
/IT Enables the task to run interactively only if the /RU user is currently logged on at the time the job runs.
This task runs only if the user is logged in.
/NP No password is stored.
The task runs non-interactively as the given user.
Only local resources are available.
/Z Marks the task for deletion after its final run.
/XML xmlfile Creates a task from the task XML specified in a file.
Can be combined with /RU and /RP switches, or with /RP alone, when task XML already contains the principal.
/V1 Creates a task visible to pre-Vista platforms.
Not compatible with /XML.
/F Forcefully creates the task and suppresses warnings if the specified task already exists.
/RL level Sets the Run Level for the job.
Valid values are LIMITED and HIGHEST. The default is LIMITED.
/DELAY delaytime Specifies the wait time to delay the running of the task after the trigger is fired.
The time format is mmmm:ss.
This option is only valid for schedule types ONSTART, ONLOGON, ONEVENT.
/? Displays this help/usage.

Modifiers:

Valid values for the /MO switch per schedule type:

MINUTE: 1 – 1439 minutes.
HOURLY: 1 – 23 hours.
DAILY: 1 – 365 days.
WEEKLY: weeks 1 – 52.
ONCE: No modifiers.
ONSTART: No modifiers.
ONLOGON: No modifiers.
ONIDLE: No modifiers.
MONTHLY: 1 – 12, or FIRST, SECOND, THIRD, FOURTH, LAST, LASTDAY.
ONEVENT: XPath event query string.

Examples:

Creates a scheduled task «doc» on the remote machine «ABC» which runs notepad.exe every hour under user «runasuser».
SCHTASKS /Create /S ABC /U user /P password /RU runasuser /RP runaspassword /SC HOURLY /TN doc /TR notepad
Creates a scheduled task «accountant» on the remote machine «ABC» to run calc.exe every five minutes from the specified start time to end time between the start date and end date.
SCHTASKS /Create /S ABC /U domain\user /P password /SC MINUTE /MO 5 /TN accountant /TR calc.exe /ST 12:00 /ET 14:00 /SD 06/06/2006 /ED 06/06/2006 /RU runasuser /RP userpassword
Creates a scheduled task «gametime» to run freecell on the first Sunday of every month.
SCHTASKS /Create /SC MONTHLY /MO first /D SUN /TN gametime /TR c:\windows\system32\freecell
Creates a scheduled task «report» on remote machine «ABC» to run notepad.exe every week.
SCHTASKS /Create /S ABC /U user /P password /RU runasuser /RP runaspassword /SC WEEKLY /TN report /TR notepad.exe
Creates a scheduled task «logtracker» on remote machine «ABC» to run notepad.exe every five minutes starting from the specified start time with no end time.
The /RP password will be prompted for.
SCHTASKS /Create /S ABC /U domain\user /P password /SC MINUTE /MO 5 /TN logtracker /TR c:\windows\system32\notepad.exe /ST 18:30 /RU runasuser /RP
Creates a scheduled task «gaming» to run freecell.exe starting at 12:00 and automatically terminating at 14:00 hours every day
SCHTASKS /Create /SC DAILY /TN gaming /TR c:\freecell /ST 12:00 /ET 14:00 /K
Creates a scheduled task «EventLog» to run wevtvwr.msc starting whenever event 101 is published in the System channel
SCHTASKS /Create /TN EventLog /TR wevtvwr.msc /SC ONEVENT /EC System /MO *[System/EventID=101]
Spaces in file paths can be used by using two sets of quotes, one set for CMD.EXE and one for SCHTASKS.EXE.
The outer quotes for CMD need to be double quotes; the inner quotes can be single quotes or escaped double quotes:
SCHTASKS /Create /TR «‹C:\Program Files\Internet Explorer\iexplorer.exe› \»C:\Log Data\today.xml\»» …

/DELETE

SCHTASKS /Delete [/S system [/U username [/P [password]]]] /TN taskname [/F]

Description:

Deletes one or more scheduled tasks.

Parameter List:

/S system Specifies the remote system to connect to.
/U username Specifies the user context under which the schtasks.exe should execute.
/P [password] Specifies the password for the given user context.
Prompts for input if omitted.
/TN taskname Specifies the name of the scheduled task to delete.
Wildcard «*» may be used to delete all tasks.
/F Forcefully deletes the task and suppresses warnings if the specified task is currently running.
/? Displays this help/usage.

Examples:

SCHTASKS /Delete /TN * /F
SCHTASKS /Delete /TN «Backup and Restore»
SCHTASKS /Delete /S system /U user /P password /TN «Start Restore»
SCHTASKS /Delete /S system /U user /P password /TN «Start Backup» /F

/QUERY

SCHTASKS /Query [/S system [/U username [/P [password]]]] [/FO format | /XML [xml_type]] [/NH] [/V] [/TN taskname] [/?]

Description:

Enables an administrator to display the scheduled tasks on the local or remote system.

Parameter List:

/S system Specifies the remote system to connect to.
/U username Specifies the user context under which the schtasks.exe should execute.
/P [password] Specifies the password for the given user context.
Prompts for input if omitted.
/FO format Specifies the output format to be displayed.
Valid values: TABLE, LIST, CSV.
/NH Specifies that the column header should not be displayed in the output.
Valid only for TABLE and CSV formats.
/V Specifies additional output to be displayed.
/TN taskname Specifies the task name for which to retrieve the information, else all of them.
/XML [xml_type] Displays task definitions in XML format.
If xml_type is ONE then the output will be one valid XML file.
If xml_type is not present then the output will be the concatenation of all XML task definitions.
/? Displays this help/usage.

Examples:

SCHTASKS /Query
SCHTASKS /Query /?
SCHTASKS /Query /S system /U user /P password
SCHTASKS /Query /FO LIST /V /S system /U user /P password
SCHTASKS /Query /FO TABLE /NH /V

/CHANGE

SCHTASKS /Change [/S system [/U username [/P [password]]]] /TN taskname { [/RU runasuser] [/RP runaspassword] [/TR taskrun] [/ST starttime] [/RI interval] [ { /ET endtime | /DU duration } [/K] ] [/SD startdate] [/ED enddate] [/ENABLE | /DISABLE] [/IT] [/Z] }

Description:

Changes the program to run, or user account and password used by a scheduled task.

Parameter List:

/S system Specifies the remote system to connect to.
/U username Specifies the user context under which the schtasks.exe should execute.
/P [password] Specifies the password for the given user context.
Prompts for input if omitted.
/RU username Changes the user name (user context) under which the scheduled task has to run.
For the system account, valid values are «», «NT AUTHORITY\SYSTEM» or «SYSTEM».
/RP password Specifies a new password for the existing user context or the password for a new user account.
Password will not effect for the system account.
/TR taskrun Specifies a new program that the scheduled task runs. Type the path and file name of the program.
/TN taskname Specifies which scheduled task to change.
/ST starttime Specifies the start time to run the task.
The time format is HH:mm (24 hour time) for example, 14:30 for 2:30 PM.
/RI interval Specifies the repetition interval in minutes.
Valid range: 1 – 599940 minutes.
/ET endtime Specifies the end time to run the task.
The time format is HH:mm (24 hour time) for example, 14:50 for 2:50 PM.
/DU duration Specifies the duration to run the task.
The time format is HH:mm. This is not applicable with /ET.
/K Terminates the task at the endtime or duration time.
/SD startdate Specifies the first date on which the task runs.
The format is dd/mm/yyyy.
/ED enddate Specifies the last date when the task should run.
The format is dd/mm/yyyy.
/IT Enables the task to run interactively only if the /RU user is currently logged on at the time the job runs.
This task runs only if the user is logged in.
/RL level Sets the Run Level for the job.
Valid values are LIMITED and HIGHEST.
The default is to not change it.
/ENABLE Enables the scheduled task.
/DISABLE Disables the scheduled task.
/Z Marks the task for deletion after its final run.
/DELAY delaytime Specifies the wait time to delay the running of the task after the trigger is fired.
The time format is mmmm:ss.
This option is only valid for schedule types ONSTART, ONLOGON, ONEVENT.
/? Displays this help/usage.

Examples:

SCHTASKS /Change /RP password /TN «Backup and Restore»
SCHTASKS /Change /TR restore.exe /TN «Start Restore»
SCHTASKS /Change /S system /U user /P password /RU newuser /TN «Start Backup» /IT

/SHOWSID

SCHTASKS /ShowSid /TN taskname

Description:

Shows the SID for the task’s dedicated user.

Parameter List:

/TN taskname Specifies the scheduled task name.
Dashes are not allowed in the name.
/? Displays this help/usage.

Examples:

SCHTASKS /ShowSid /?
SCHTASKS /ShowSid /TN «\Microsoft\Windows\RAC\RACTask»

 

29. Oktober 2015 7379 webadmin  General
Total 1 Votes:
0

Tell us how can we improve this post?

+ = Verify Human or Spambot ?

Add A Knowledge Base Question !

+ = Verify Human or Spambot ?

Add A Knowledge Base Question !

+ = Verify Human or Spambot ?