SQL Safe provides you with CLI commands to help you manually edit your restore policies.

Options to Edit Restore Policies

To edit restore policies with minimal required options use the following command:

  • SQLsafeCmd Create-Policy Restore <policy_name> -InstanceName <name> -DatabaseName <source_db_name> -SourceBackupPolicy <policy_name|GUID> -TargetInstance <name> -TargetDatabase <target_db_name> [options]


The following options can also be used to edit restore policies:

OptionDescription
-ActionType <action>

Specifies the policy action.

<action> - SqlAgent, SqlSafeBackupAgent, MonitorOnly.

Note: the default is the SqlAgent action.

-RestrictRun [on|off]    

[on|off] - Enable/Disable the policy.

-Description <description>     <description> - specifies the policy description.
-NewName <policy_name><policy_name> - specifies the new name of the policy.
-InstanceName <instance_name>

<instance_name> - specifies the source instance.

Note: this parameter is required.

-DatabaseName <db_name>      

<db_name> - specifies the database to restore.

Note: this parameter is required.

-Server <server_name>

<server_name> - specifies the source server.

Note: this parameter is optional.

-RetryWrites <interval> <retry_time> <total_time>

On a network file error, retry every <interval> seconds for up to <retry_time> seconds. Total retry time allowed is <total_time> minutes.

-SourceBackupPolicy <policy_name|GUID>

<policy_name|GUID> - specifies the backup policy for source database.

-BackupEncryptionPassword <pwd>

<pwd> - specifies the password for encrypted source backup file.

Account Options

The following account options help you edit restore policies:

OptionsDescription
-UseAgentAccount <yes|no>

Specifies the Agent account for accessing to files.

Note: by default, the policy uses Agent account.

This parameter is optional.

-WindowsUsername <domain\user>

<domain\user> - specifies the user name, used when writing/reading to files during restore.

-WindowsPassword <pwd><pwd> - specifies the password.

Target Options

The following target options help you edit restore policies:

OptionsDescription
 -TargetInstance <instance_name>

<instance_name> - specifies the target instance.

Note: this parameter is required.

-TargetDatabase <db_name>

<db_name> - specifies the new database.

Note: this parameter is required.

-TargetServer <server_name>

<server_name> - specifies the target server.

Note: this parameter is optional.

-LogLocation <path>

<path> - specifies where to store the database log files.

Note: the default value is the current target database log files location.

-DataLocation <path>

<path> - specifies where to store database data files.

Note: the default value is the current target database data files location.

-RecoveryMode <mode>

Specifies the database state after restore action.

<mode>  {NoRecovery, Standby, Recovery}.

-DisconnectUsers <yes|no>

Disconnects all users from the target database before the restore operation begins.

Note: this parameter is optional.

-ContinueAfterError <yes|no>

Instructs SQL Server to continue the operation despite encountering errors such as invalid checksums.

Note: For SQL 2005 and later only. 

This parameter is optional.

 

-IncludeLogins <yes|no>

For backup, includes the database logins in the backup file.

For restore, creates the logins from the backup file on the destination server.

Note: this parameter is optional.

-KeepReplication <yes|no>

Preserves replication settings when restoring a published database to a server other than that on which it was created.

Note: this parameter is optional.


Schedule Options

You can schedule the edition of restore policies by using the following options:

OptionsDescription

-Schedule <occurs_type>

Specifies the schedule type (occurs type).

<occurs_type> - OnDemand, Daily, Weekly, Monthly.

-Every <n>

Specifies how often the policy runs. It depends on the schedule type.

For Daily: every <n> day(s).

For Weekly: every <n> week(s).

For Monthly: every <n> month(s).

Note: the default value is "1".

-Day <day>

<day> - specifies a day of the week or a day of a month.

Note: it is valid only with Weekly, Monthly schedule types.

Valid values for Weekly: MON - SUN and * (every day). SUN is default.

Valid values for Monthly: MON - SUN, Weekday, WeekendDay, Day or number 1 - 31. Is required when -MonthDay option is used.

-MonthDay <month_day>

Specifies how often the policy runs.

<month_day> - FIRST, SECOND, THIRD, FOURTH, LAST use with -Day option. LASTDAY - the policy runs on the last day of the month.

-StartTime <time>

<time> - specifies the time of day that the policy runs.

Note: it is required with a "once" frequency.

The default value is the current local time when policy creates.

-EndTime <time>

<time> - specifies the time of day that the policy ends.

Note: it is is not valid in a "once" frequency.

The default value is the "23:59:59".

-Frequency <n><time_period>

Specifies daily frequency (how often the policy runs within a day).

<n> - amount of time.

<time_period> - {hour, minute}.

E.g., -Frequency 2hours.

Special keyword: Once. E.g., -Frequency Once.

-StartDate <date>

<date> - specifies the date that the policy starts.

Note: The default value is the current date.

This parameter is optional.

-EndDate <date>

<date> - specifies the last date that the policy is scheduled to run.

Note: by default, the schedules have no ending date.

This parameter is optional.

Note: you can optionally specify restore job occur schedule.

Email Options

You can set email notifications for your restore policy editions by using the following options:

OptionsDescription


-MailTo <email> [<email> ...] <on_event> [<on_event> ...] [<frequency>]

<email> - specifies where to send notification.

<on_event> - specifies the event on which send notification.

Valid events are: OnError, OnSkip, OnCancel, OnWarning, OnSuccess.

The default is no event.

<frequency> - specifies the notification frequency.

Valid values: Once, Always, Never.

The default is never.

Note: you can optionally specify email settings.

For detailed descriptions and available options, see the CLI Help (SQLsafeCmd help Edit-Policy).


  • No labels