Pre populate the Primary contact field on Activity when created from an opp
Is there a way to auto populate the Primary contact field when a task is created from an opportunity with a primary contact? Can it be done thru a custom weblink? I think Bob B. may have had some weblink documentation?
There are a couple of options to solve this issue. One option would be to use a post-default to set the value. This option would allow you the ability to use logic to determine whether it is populated or not. The other option would be to use a custom weblink that populates the value, but I don't know that you would be able to use logic in the weblink option. I have docs on these options, so you can contact me via email and I send you what I have.
Good luck,
Thom
Similar Messages
-
I have a site with the default document library.
I add views to the library, some ask for the items to be shown in folders, some not.
I create a site template via the SharePoint UI.
I create a new site.
In the new site, the library exists, the views exist, but all the views are set to show the items in folders.
Does anyone else have this problem? Is there a patch or any workaround?Hi ,
According to your description, my understanding is that view property "show all items without folders" is not preserved in packaging and is lost after we create a site using the saved site template.
For your issue, I can reproduce your scenario in my environment. It should be caused by the scope attribute is missing. For a workaround, you can try to crack the site template wsp, add the missing scope
attribute to the View schema in the list schema.xml.
Also, I recommend you open up a ticket for deep investigation.
Thanks,
Eric
Forum Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
[email protected]
Eric Tao
TechNet Community Support -
Primary contact and contact field in activity
Hi all,
I am trying to create few contacts under an account and set one contact as primary contact.
Then i am trying to craete an activity for that account.In that Activity there are two fields "Contact" and "Primary Contact".But when I try to pick up a contact and save the Activity record I see that the primary contact is not updated properly.(which means the primary contact is different from the one I selected in the account detail page).
I also found that if the contact's primary account is not the account to which i am adding the activity then the contact name is not coming in the drop down to select for an activity.(in the "contact" and "primary contact" look up field of activity)
Is there some reason for this??or am trying to overlook something..
kindly help..
Thanks in advance,
Ashan.Hello Ashan,
I tried the same thing, creating 2 Contacts under Account then making one primary, then created the activity and select the contact under Contact Look up and it successfully updated the primary contact field.
There seems to be a problem with your pod, Have you tried raising an SR with oracle regarding this? -
How to display the related Contacts for an Activity
From the configuration, the user could select mutliple Contacts per one Activity record.
In the analytics report, I would like to fetch ALL of these contacts (*NOT only the primary contact*). I cannot see any subject area from the "Design Analyses" could serve this purpose.
Does anyone have solution about this ? Thanks.Hi,
in the reporting section try "Shared Activities".
BR
Michael -
How to Pre-Populate the user information during Assign Task operation
Hi ,
I have a requrirement to Pre-Populate the form fields (Name, Email, Phone etc...) when a task is assigned to a user. The users are dynamically assiged, so I am using the Find User and the Assign Task services to locate and assign the task to the user. Since I have a User variable that is a result from the Find User operation, I was hoping to retrieve the user information with the attributes of the User type.
I tried to use the Set Value service to set the form field (Email) with the email attribute of the User object type i.e.
/process_data/MyForm/object/data/xdp/datasets/data/Form/User/Email -> /process_data/facilityAuthority/object/@email
However I get the following error when I try to do this - com.adobe.idp.dsc.util.InvalidCoercionException: Cannot coerce object: [B@335d of type: [B to type: interface org.w3c.dom.Document.
Is it possible to retrieve the user information from the User object? If so how do I get the values for the User attributes (Name, Email & Phone etc...) so that I can populate them in the form?
Thanks,
SamanthapudiHi Han Dao,
If you are facing an exception of the form "com.adobe.idp.dsc.util.InvalidCoercionException: Cannot coerce object: [B@335d of type: [B to type: interface org.w3c.dom.Document.", It is because the system is trying to cast a Byte Stream into w3c Document and failing. To resolve this we can explicitly cast this byte stream to appropriate data type (String in previous example). To do so we can use a SetValue operation.
As an example
Setting
/process_data/MyForm/object/data/xdp/datasets/data/Form/User/Email -> /process_data/facilityAuthority/object/@email
results in the exception
so we can modify it to
/process_data/MyForm/object/data/xdp/datasets/data/Form/User/Email -> string(/process_data/facilityAuthority/object/@email)
Please let me know if this does not resolve your issue.
Thanks -
Using a custom PL/SQL to populate the primary key in a tabular form
I want to use a Custom PL/SQL Function to populate the primary key when I insert a new record into a tabular form. I want to get the value from a hidden page Item. The code I am using for the primary key source is:
BEGIN
INSERT INTO TEAM_MEMBERS(TEAM_ID)
VALUES(:P75_TEAM_ID);
END;
When I try to insert a new record I get the following error:
Error ERR-1904 Unable to compute item default: type = Function Body computation_type= BEGIN INSERT INTO TEAM_MEMBERS(TEAM_ID) VALUES(:P75_TEAM_ID); END; .
ORA-06550: line 5, column 2: PLS-00103: Encountered the symbol ";" when expecting one of the following: begin case declare end exception exit for goto if loop mod null pragma raise return select update while with << close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe The symbol "exit" was substit
Any ideas what I am doing wrong?
Thanks!Brian - Sometimes whitespace at the end of the block causes this. Be sure to trim everything after the last semicolon including tabs and newlines.
Scott -
Requirement to populate the Profit center field of Vendor line item thru...
Hi,
My requirement is to populate the Profit center field of Vendor line item.
For this, I want to write a substitution where based on the Business Area of Vendor line item, the system should populate the Profit center while saving.
Is it possible thru Validation & Substitutions...
Plz guide me in writing this
Points will be suitable rewarded for replies.
regards
AVMTcode: GGB1
An example shows how to make a G/L account available for line item substitution.
GGB1
Click FA Doc Header
Click Create Substitution icon
Enter the Text
Click Create Step icon
Click the field u want Say - BKPF- BKTXT
Choose the option Say :Constant value
Give description of ur step
Click Prerequisite
Double Click Structure BKPF
Double Click BKPF-AWKEY
Click Constant button
Enter the Text u want to make it appler in the Reference key
Click Substitution and enter the constant value u want
Go to Tcode: GGB4
Click Substituted Fields
Give ur table and field (Here - BKPF- BKTXT)
Do it in a similar way..if u cannot proceed, let me know the exact field values..and i can take screenshots and send u across
Thanks,
Sridevi -
Creating a row trigger to populate the primary key
to populate the primary key of a table automatically, i created a sequence named rule_id
using the following statement:
create sequence rule_id;
and then i created a trigger to populate the primary key using the statements below:
CREATE OR REPLACE
TRIGGER RULE_ID BEFORE INSERT ON DOC_CATS_RULE_BASED_CLASS
FOR EACH ROW
BEGIN
SELECT SEQ_RULE_BASED_CLASS.NEXTVAL
INTO :new.id FROM DUAL;
END;
i took this from a books example. but it gives and error called:
Error(3,8): PLS-00049: bad bind variable 'NEW.ID'
What is wrong and what is the current way to do it?
Please help!Hi ,
The new denotes the new data values for the table relative column.....
As regards the dual is a small table in the data dictionary that Oracle and user-written programs can reference to guarantee a known result. This table has one column called DUMMY and one row containing the value X.
Regards,
Simon -
To Populate the profit center field in the sales order by user Exit.
Hi All,
Please let me know :
How the user exit is used to populate the Profit center field in the Sales order?
Please gurus answer as quickly as possible as I require this urgently.If you want to overwrite the profit center in sale order (determined from the materail master) with a different profit center based some other criterion you can use profit center substitution rules. Check the wiki:
[Profit Center Substitution in Sales Orders|https://www.sdn.sap.com/irj/sdn/wiki?path=/display/erplo/profitCenterSubstitutioninSales+Orders]
Regards,
GSL. -
Pre-populate the Public Holiday hours in CATS with A/A Type
Hi Experts
Please let me know if there is anyway for us to pre-populate the Public Holiday hours in CATS with A/A Type for all employees.
Our Client would like automatically populate Holiday hours with A/A type 2000 in CATS for all eligible employees, based on whatever amount of hours they are scheduled to work on the specified days.
Basicall client dont want employee to enter A/A with Public Holiday Hours, they want it to be automatically exist in CATS timesheet
If you have any other ideas about how to accomplish this please let me know.
Regards,
Koutilya A.KHello Koutilya,
I got the same requirement as yours. Can you please suggest me how to achieve this one.
Thanks,
R V Narayana. -
gurus,
i'm using following -
Database --> Oracle 9i
Portal --> Oracle Portal 9iAS Release 2
there are about 10,000 portal users. i would like to pre-populate the OID from the existing employee repository (employee repository is a custom Oracle database).
question - is there a white paper that gives u all the api's required to do so. i've to accomplish the following tasks -
1. create users
2. give them privileges
3. assign them to groups
4. assign a default groups to users
i need to achieve above as part of pre-populating the OID.
ideas anyone ....?
thanx a bunch.Hero,
You want to ...
1. create users
2. give them privileges
3. assign them to groups
4. assign a default groups to users
You will need to do this in the following sequence of steps...
1. Populate the user entries in OID, and assign the default group
2. Create the groups in OID and assign the users to them
3. Assign the appropriate portal privileges to the groups
For step 1 and 2, I'll have to refer you to the OID Administrator's Guide for Release 9.0.2.
This document contains a lot of good information, but in particular, you'll want to review Appendix I ...
"Migrating User Data from Application-Specific Repositories". This addresses the LDIF migration tool
and describes the schema elements needed for the IAS user accounts.
For step 3, the easiest way would be to assign the privileges to the groups through the user interface. Once the groups are defined
in OID, you can select them via the Portal UI to assign the portal privileges to them.
The proper place to locate portal instance-specific groups is under the portal instance group base, which is
cn=portal_groups, cn=groups, <subscriber_base>. The following white paper
may be helpful to understand the organization of the directory information tree. -
Want to populate the House Bank field in the MIRO
Hi All,
I want to populate the House Bank field in the MIRO.
I have tried with the user exit EXIT_SAPLMRMP_010. I am not populate the House Bank Id as it is not the exporting parameter.
Please help me regarding this.
Regards
KumarKumar,
It looks like there is a BADI that may give you what you need. The BADI definition (transaction SE18) is INVOICE_UPDATE. There are three methods available (in 4.6C):
CHANGE_AT_SAVE Invoice Document at Save
CHANGE_BEFORE_UPDATE Invoice Document Before Update
CHANGE_IN_UPDATE Invoice Document During Update
Each of these methods allow you to pass "old" and "new" RBKP values. In the SE18 screen there is a function (toolbar button) "Documentation" that has some additional information.
The BADI is used in several function modules: MRM_INVOICE_DOCUMENT_POST, MRM_INVOICE_PREPARE_AND_POST, and MRM_BADI_INVOICE_CHECK.
You should be able to move the House Bank value by creating an implementation of this BADI.
I hope this works for you.
Regards,
James G. -
How user exit is used to populate the Profit center field in Sales order?
Hi All,
Please let me know :
How the user exit is used to populate the Profit center field in the Sales order?
Please gurus answer as quickly as possible as I require this urgently.Hi,
To derive the correct profit center in the Sales Order, you customize in 0KEM.
Trust this helps much and do encourage our efforts!
Cheers! -
Exception: non-read-only mapping defined for the primary key field
Hello.
I'm new to Oracle and I created Java EE Web Project.
And I created entities from tableA, tableB, tableC from my database.
tableA has foreign key to tableB and has unidirectional Many-to-One relationship. tableC has two primary keys and one of these is foreign key to primary key in tableA. tableC also has unidirection Many-to-One relationship to tableA.
Then I created session bean and data control from it, in design window, created read-only table from tableA.
And I selected columns in tableA and also in tableB.
I ran the application and saw the following exception in log window.
Local Exception Stack:
Exception [EclipseLink-46] (Eclipse Persistence Services - 2.1.3.v20110304-r9073): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: There should be one non-read-only mapping defined for the primary key field [tableC.tableA_ID].
Descriptor: RelationalDescriptor(mypack.tableC --> [DatabaseTable(tableC)])
tableA_ID is a primary key in tableA.
How can I solve this error?
Please help me.
Edited by: 900471 on 2011. 12. 3 오전 5:32
Edited by: 900471 on 2011. 12. 3 오전 5:33
Edited by: 900471 on 2011. 12. 3 오전 5:33
Edited by: 900471 on 2011. 12. 3 오전 5:34There are not enough details to be sure since you have not provided the mappings. From just the error, it looks like you are using the tableC.tableA_ID field as the foreign key in the ManyToOne relationship to A, but have marked it as insertable=false, writeable=false, meaning that it cannot be updated or used for inserts.
Either make it writable (set the settings to true), or add another basic mapping/attribute in the entity for TableC that maps to the field which you can use to set when you insert a new tableC entity. A simple example is available at
http://wiki.eclipse.org/EclipseLink/Examples/JPA/2.0/DerivedIdentifiers
Best Regards,
Chris -
I have AlwaysOn SQL 2012 Enterprise set-up using Windows Failover Clustering Services (not FCI), and have 1 Primary node (P), 1 Synchronous Commit Auto Failover (SC), and 1 Asynchronous Commit Manual Failover (AC) node. It is set up to prefer secondary,
with the highest priority given to AC node.
I am using Ola Hollengren's scripts for Database Maintenance jobs, including a native BACKUP LOG job for the transaction logs of all user databases on a 1 minute schedule. His scripts already consider AlwaysOn, and although the job is set-up on all
3 nodes, only ever runs on AC node.
The job has been running successfully since initial set-up almost 1 year ago, but suddenly yesterday morning started to fail with the following error, only on 1 of the 13 databases in my availability group:
Date and time: 2014-06-08 09:36:11
Command: BACKUP LOG [my_db] TO DISK = N'E:\MSSQL\\Transaction Dumps\my_db\MySQLCL$MySQLAG_my_db_20140608_093610_U_LOG.trn' WITH CHECKSUM, COMPRESSION
Msg 35250, Level 16, State 11, Server AC, Line 1
The connection to the primary replica is not active. The command cannot be processed.
Msg 3013, Level 16, State 1, Server AC, Line 1
BACKUP LOG is terminating abnormally.
Outcome: Failed
Duration: 00:01:00
The other 12 databases continued to backup successfully.
Checking the Availability Group dashboard, windows event logs, and SQL Server error logs, including Failover Cluster events showed no issues.
However, monitoring software (Idera SQLdm) showed blocked sessions on P node. When I ran sp_who2, it showed that a background process was being blocked by another background process with an HADR BACKUP LOCK.
Since both processes were background processes, I was unable to kill either process. I temporarily disabled the transaction log backup job, but the blocked process was still active.
I ran DBCC CHECKDB (my_db) WITH all_errormsgs, no_infomsgs, data_purity on both P and AC nodes, with no errors. However, on AC node, it also showed 1 transaction rolled forward and 0 transactions rolled back. This also had the effect of releasing
the blocked background process, but another background process was now blocking with the same HADR BACKUP LOCK.
I tried to restart SQL Server Agent on AC node, which did not immediately seem to work. However, after a few minutes, I noticed that the block had disappeared. I re-enabled the transaction log backup job on AC and it started working normally
again. The error has not occurred again, but I am at a loss as to what happened, and how to prevent it from happening again.
Any help would be greatly appreciated.
DianeAnd here is part 2 of the stored procedure:
--// Execute backup commands //--
WHILE EXISTS (SELECT * FROM @tmpDatabases WHERE Selected = 1 AND Completed = 0)
BEGIN
SELECT TOP 1 @CurrentDBID = ID,
@CurrentDatabaseName = DatabaseName,
@CurrentDatabaseNameFS = DatabaseNameFS,
@CurrentDatabaseType = DatabaseType
FROM @tmpDatabases
WHERE Selected = 1
AND Completed = 0
ORDER BY ID ASC
SET @CurrentDatabaseID = DB_ID(@CurrentDatabaseName)
IF DATABASEPROPERTYEX(@CurrentDatabaseName,'Status') = 'ONLINE'
BEGIN
IF EXISTS (SELECT * FROM sys.database_recovery_status WHERE database_id = @CurrentDatabaseID AND database_guid IS NOT NULL)
BEGIN
SET @CurrentIsDatabaseAccessible = 1
END
ELSE
BEGIN
SET @CurrentIsDatabaseAccessible = 0
END
END
ELSE
BEGIN
SET @CurrentIsDatabaseAccessible = 0
END
SELECT @CurrentDifferentialBaseLSN = differential_base_lsn
FROM sys.master_files
WHERE database_id = @CurrentDatabaseID
AND [type] = 0
AND [file_id] = 1
-- Workaround for a bug in SQL Server 2005
IF @Version >= 9 AND @Version < 10
AND EXISTS(SELECT * FROM sys.master_files WHERE database_id = @CurrentDatabaseID AND [type] = 0 AND [file_id] = 1 AND differential_base_lsn IS NOT NULL AND differential_base_guid IS NOT NULL AND differential_base_time IS NULL)
BEGIN
SET @CurrentDifferentialBaseLSN = NULL
END
SELECT @CurrentDifferentialBaseIsSnapshot = is_snapshot
FROM msdb.dbo.backupset
WHERE database_name = @CurrentDatabaseName
AND [type] = 'D'
AND checkpoint_lsn = @CurrentDifferentialBaseLSN
IF DATABASEPROPERTYEX(@CurrentDatabaseName,'Status') = 'ONLINE'
BEGIN
SELECT @CurrentLogLSN = last_log_backup_lsn
FROM sys.database_recovery_status
WHERE database_id = @CurrentDatabaseID
END
SET @CurrentBackupType = @BackupType
IF @ChangeBackupType = 'Y'
BEGIN
IF @CurrentBackupType = 'LOG' AND DATABASEPROPERTYEX(@CurrentDatabaseName,'Recovery') <> 'SIMPLE' AND @CurrentLogLSN IS NULL AND @CurrentDatabaseName <> 'master'
BEGIN
SET @CurrentBackupType = 'DIFF'
END
IF @CurrentBackupType = 'DIFF' AND @CurrentDifferentialBaseLSN IS NULL AND @CurrentDatabaseName <> 'master'
BEGIN
SET @CurrentBackupType = 'FULL'
END
END
IF @CurrentBackupType = 'LOG'
BEGIN
SELECT @CurrentLatestBackup = MAX(backup_finish_date)
FROM msdb.dbo.backupset
WHERE [type] IN('D','I')
AND is_damaged = 0
AND database_name = @CurrentDatabaseName
END
IF @Version >= 11 AND @Cluster IS NOT NULL
BEGIN
SELECT @CurrentAvailabilityGroup = availability_groups.name,
@CurrentAvailabilityGroupRole = dm_hadr_availability_replica_states.role_desc
FROM sys.databases databases
INNER JOIN sys.availability_databases_cluster availability_databases_cluster ON databases.group_database_id = availability_databases_cluster.group_database_id
INNER JOIN sys.availability_groups availability_groups ON availability_databases_cluster.group_id = availability_groups.group_id
INNER JOIN sys.dm_hadr_availability_replica_states dm_hadr_availability_replica_states ON availability_groups.group_id = dm_hadr_availability_replica_states.group_id AND databases.replica_id = dm_hadr_availability_replica_states.replica_id
WHERE databases.name = @CurrentDatabaseName
END
IF @Version >= 11 AND @Cluster IS NOT NULL AND @CurrentAvailabilityGroup IS NOT NULL
BEGIN
SELECT @CurrentIsPreferredBackupReplica = sys.fn_hadr_backup_is_preferred_replica(@CurrentDatabaseName)
END
SELECT @CurrentDatabaseMirroringRole = UPPER(mirroring_role_desc)
FROM sys.database_mirroring
WHERE database_id = @CurrentDatabaseID
IF EXISTS (SELECT * FROM msdb.dbo.log_shipping_primary_databases WHERE primary_database = @CurrentDatabaseName)
BEGIN
SET @CurrentLogShippingRole = 'PRIMARY'
END
ELSE
IF EXISTS (SELECT * FROM msdb.dbo.log_shipping_secondary_databases WHERE secondary_database = @CurrentDatabaseName)
BEGIN
SET @CurrentLogShippingRole = 'SECONDARY'
END
-- Set database message
SET @DatabaseMessage = 'Date and time: ' + CONVERT(nvarchar,GETDATE(),120) + CHAR(13) + CHAR(10)
SET @DatabaseMessage = @DatabaseMessage + 'Database: ' + QUOTENAME(@CurrentDatabaseName) + CHAR(13) + CHAR(10)
SET @DatabaseMessage = @DatabaseMessage + 'Status: ' + CAST(DATABASEPROPERTYEX(@CurrentDatabaseName,'Status') AS nvarchar) + CHAR(13) + CHAR(10)
SET @DatabaseMessage = @DatabaseMessage + 'Standby: ' + CASE WHEN DATABASEPROPERTYEX(@CurrentDatabaseName,'IsInStandBy') = 1 THEN 'Yes' ELSE 'No' END + CHAR(13) + CHAR(10)
SET @DatabaseMessage = @DatabaseMessage + 'Updateability: ' + CAST(DATABASEPROPERTYEX(@CurrentDatabaseName,'Updateability') AS nvarchar) + CHAR(13) + CHAR(10)
SET @DatabaseMessage = @DatabaseMessage + 'User access: ' + CAST(DATABASEPROPERTYEX(@CurrentDatabaseName,'UserAccess') AS nvarchar) + CHAR(13) + CHAR(10)
SET @DatabaseMessage = @DatabaseMessage + 'Is accessible: ' + CASE WHEN @CurrentIsDatabaseAccessible = 1 THEN 'Yes' ELSE 'No' END + CHAR(13) + CHAR(10)
SET @DatabaseMessage = @DatabaseMessage + 'Recovery model: ' + CAST(DATABASEPROPERTYEX(@CurrentDatabaseName,'Recovery') AS nvarchar) + CHAR(13) + CHAR(10)
IF @CurrentAvailabilityGroup IS NOT NULL SET @DatabaseMessage = @DatabaseMessage + 'Availability group: ' + @CurrentAvailabilityGroup + CHAR(13) + CHAR(10)
IF @CurrentAvailabilityGroup IS NOT NULL SET @DatabaseMessage = @DatabaseMessage + 'Availability group role: ' + @CurrentAvailabilityGroupRole + CHAR(13) + CHAR(10)
IF @CurrentAvailabilityGroup IS NOT NULL SET @DatabaseMessage = @DatabaseMessage + 'Is preferred backup replica: ' + CASE WHEN @CurrentIsPreferredBackupReplica = 1 THEN 'Yes' WHEN @CurrentIsPreferredBackupReplica = 0 THEN 'No' ELSE 'N/A' END + CHAR(13) + CHAR(10)
IF @CurrentDatabaseMirroringRole IS NOT NULL SET @DatabaseMessage = @DatabaseMessage + 'Database mirroring role: ' + @CurrentDatabaseMirroringRole + CHAR(13) + CHAR(10)
IF @CurrentLogShippingRole IS NOT NULL SET @DatabaseMessage = @DatabaseMessage + 'Log shipping role: ' + @CurrentLogShippingRole + CHAR(13) + CHAR(10)
SET @DatabaseMessage = @DatabaseMessage + 'Differential base LSN: ' + ISNULL(CAST(@CurrentDifferentialBaseLSN AS nvarchar),'N/A') + CHAR(13) + CHAR(10)
SET @DatabaseMessage = @DatabaseMessage + 'Differential base is snapshot: ' + CASE WHEN @CurrentDifferentialBaseIsSnapshot = 1 THEN 'Yes' WHEN @CurrentDifferentialBaseIsSnapshot = 0 THEN 'No' ELSE 'N/A' END + CHAR(13) + CHAR(10)
SET @DatabaseMessage = @DatabaseMessage + 'Last log backup LSN: ' + ISNULL(CAST(@CurrentLogLSN AS nvarchar),'N/A') + CHAR(13) + CHAR(10)
SET @DatabaseMessage = REPLACE(@DatabaseMessage,'%','%%') + ' '
RAISERROR(@DatabaseMessage,10,1) WITH NOWAIT
IF DATABASEPROPERTYEX(@CurrentDatabaseName,'Status') = 'ONLINE'
AND NOT (DATABASEPROPERTYEX(@CurrentDatabaseName,'UserAccess') = 'SINGLE_USER' AND @CurrentIsDatabaseAccessible = 0)
AND DATABASEPROPERTYEX(@CurrentDatabaseName,'IsInStandBy') = 0
AND NOT (@CurrentBackupType = 'LOG' AND (DATABASEPROPERTYEX(@CurrentDatabaseName,'Recovery') = 'SIMPLE' OR @CurrentLogLSN IS NULL))
AND NOT (@CurrentBackupType = 'DIFF' AND @CurrentDifferentialBaseLSN IS NULL)
AND NOT (@CurrentBackupType IN('DIFF','LOG') AND @CurrentDatabaseName = 'master')
AND NOT (@CurrentAvailabilityGroup IS NOT NULL AND @CurrentBackupType = 'FULL' AND @CopyOnly = 'N' AND (@CurrentAvailabilityGroupRole <> 'PRIMARY' OR @CurrentAvailabilityGroupRole IS NULL))
AND NOT (@CurrentAvailabilityGroup IS NOT NULL AND @CurrentBackupType = 'FULL' AND @CopyOnly = 'Y' AND (@CurrentIsPreferredBackupReplica <> 1 OR @CurrentIsPreferredBackupReplica IS NULL))
AND NOT (@CurrentAvailabilityGroup IS NOT NULL AND @CurrentBackupType = 'DIFF' AND (@CurrentAvailabilityGroupRole <> 'PRIMARY' OR @CurrentAvailabilityGroupRole IS NULL))
AND NOT (@CurrentAvailabilityGroup IS NOT NULL AND @CurrentBackupType = 'LOG' AND @CopyOnly = 'N' AND (@CurrentIsPreferredBackupReplica <> 1 OR @CurrentIsPreferredBackupReplica IS NULL))
AND NOT (@CurrentAvailabilityGroup IS NOT NULL AND @CurrentBackupType = 'LOG' AND @CopyOnly = 'Y' AND (@CurrentAvailabilityGroupRole <> 'PRIMARY' OR @CurrentAvailabilityGroupRole IS NULL))
AND NOT ((@CurrentLogShippingRole = 'PRIMARY' AND @CurrentLogShippingRole IS NOT NULL) AND @CurrentBackupType = 'LOG')
BEGIN
-- Set variables
SET @CurrentDate = GETDATE()
IF @CleanupTime IS NULL OR (@CurrentBackupType = 'LOG' AND @CurrentLatestBackup IS NULL) OR @CurrentBackupType <> @BackupType
BEGIN
SET @CurrentCleanupDate = NULL
END
ELSE
IF @CurrentBackupType = 'LOG'
BEGIN
SET @CurrentCleanupDate = (SELECT MIN([Date]) FROM(SELECT DATEADD(hh,-(@CleanupTime),@CurrentDate) AS [Date] UNION SELECT @CurrentLatestBackup AS [Date]) Dates)
END
ELSE
BEGIN
SET @CurrentCleanupDate = DATEADD(hh,-(@CleanupTime),@CurrentDate)
END
SELECT @CurrentFileExtension = CASE
WHEN @BackupSoftware IS NULL AND @CurrentBackupType = 'FULL' THEN 'bak'
WHEN @BackupSoftware IS NULL AND @CurrentBackupType = 'DIFF' THEN 'bak'
WHEN @BackupSoftware IS NULL AND @CurrentBackupType = 'LOG' THEN 'trn'
WHEN @BackupSoftware = 'LITESPEED' AND @CurrentBackupType = 'FULL' THEN 'bak'
WHEN @BackupSoftware = 'LITESPEED' AND @CurrentBackupType = 'DIFF' THEN 'bak'
WHEN @BackupSoftware = 'LITESPEED' AND @CurrentBackupType = 'LOG' THEN 'trn'
WHEN @BackupSoftware = 'SQLBACKUP' AND @CurrentBackupType = 'FULL' THEN 'sqb'
WHEN @BackupSoftware = 'SQLBACKUP' AND @CurrentBackupType = 'DIFF' THEN 'sqb'
WHEN @BackupSoftware = 'SQLBACKUP' AND @CurrentBackupType = 'LOG' THEN 'sqb'
WHEN @BackupSoftware = 'HYPERBAC' AND @CurrentBackupType = 'FULL' AND @Encrypt = 'N' THEN 'hbc'
WHEN @BackupSoftware = 'HYPERBAC' AND @CurrentBackupType = 'DIFF' AND @Encrypt = 'N' THEN 'hbc'
WHEN @BackupSoftware = 'HYPERBAC' AND @CurrentBackupType = 'LOG' AND @Encrypt = 'N' THEN 'hbc'
WHEN @BackupSoftware = 'HYPERBAC' AND @CurrentBackupType = 'FULL' AND @Encrypt = 'Y' THEN 'hbe'
WHEN @BackupSoftware = 'HYPERBAC' AND @CurrentBackupType = 'DIFF' AND @Encrypt = 'Y' THEN 'hbe'
WHEN @BackupSoftware = 'HYPERBAC' AND @CurrentBackupType = 'LOG' AND @Encrypt = 'Y' THEN 'hbe'
WHEN @BackupSoftware = 'SQLSAFE' AND @CurrentBackupType = 'FULL' THEN 'safe'
WHEN @BackupSoftware = 'SQLSAFE' AND @CurrentBackupType = 'DIFF' THEN 'safe'
WHEN @BackupSoftware = 'SQLSAFE' AND @CurrentBackupType = 'LOG' THEN 'safe'
END
INSERT INTO @CurrentDirectories (ID, DirectoryPath, CreateCompleted, CleanupCompleted)
SELECT ROW_NUMBER() OVER (ORDER BY ID), DirectoryPath + CASE WHEN RIGHT(DirectoryPath,1) = '\' THEN '' ELSE '\' END + CASE WHEN @CurrentBackupType = 'LOG' THEN '\Transaction Dumps\' + @CurrentDatabaseNameFS ELSE '' END, 0, 0
FROM @Directories
ORDER BY ID ASC
SET @CurrentFileNumber = 0
SET @CurrentMirrorFilePath = NULL
WHILE @CurrentFileNumber < @NumberOfFiles
BEGIN
SET @CurrentFileNumber = @CurrentFileNumber + 1
SELECT @CurrentDirectoryPath = DirectoryPath
FROM @CurrentDirectories
WHERE @CurrentFileNumber >= (ID - 1) * (SELECT @NumberOfFiles / COUNT(*) FROM @CurrentDirectories) + 1
AND @CurrentFileNumber <= ID * (SELECT @NumberOfFiles / COUNT(*) FROM @CurrentDirectories)
SET @CurrentFilePath = @CurrentDirectoryPath + '\' + CASE WHEN @CurrentAvailabilityGroup IS NOT NULL THEN @Cluster + '$' + @CurrentAvailabilityGroup ELSE REPLACE(CAST(SERVERPROPERTY('servername') AS nvarchar),'\','$') END + '_' + @CurrentDatabaseNameFS + '_' + REPLACE(REPLACE(REPLACE((CONVERT(nvarchar,@CurrentDate,120)),'-',''),' ','_'),':','') + CASE WHEN @NumberOfFiles > 1 AND @NumberOfFiles <= 9 THEN '_' + CAST(@CurrentFileNumber AS nvarchar) WHEN @NumberOfFiles >= 10 THEN '_' + RIGHT('0' + CAST(@CurrentFileNumber AS nvarchar),2) ELSE '' END + '_' + @CurrentDatabaseType + '_' + UPPER(@CurrentBackupType) + CASE WHEN @ReadWriteFileGroups = 'Y' THEN '_PARTIAL' ELSE '' END + CASE WHEN @CopyOnly = 'Y' THEN '_COPY_ONLY' ELSE '' END + '.' + @CurrentFileExtension
IF LEN(@CurrentFilePath) > 257
BEGIN
SET @CurrentFilePath = @CurrentDirectoryPath + '\' + CASE WHEN @CurrentAvailabilityGroup IS NOT NULL THEN @Cluster + '$' + @CurrentAvailabilityGroup ELSE REPLACE(CAST(SERVERPROPERTY('servername') AS nvarchar),'\','$') END + '_' + LEFT(@CurrentDatabaseNameFS,CASE WHEN (LEN(@CurrentDatabaseNameFS) + 257 - LEN(@CurrentFilePath) - 3) < 20 THEN 20 ELSE (LEN(@CurrentDatabaseNameFS) + 257 - LEN(@CurrentFilePath) - 3) END) + '...' + '_' + REPLACE(REPLACE(REPLACE((CONVERT(nvarchar,@CurrentDate,120)),'-',''),' ','_'),':','') + CASE WHEN @NumberOfFiles > 1 AND @NumberOfFiles <= 9 THEN '_' + CAST(@CurrentFileNumber AS nvarchar) WHEN @NumberOfFiles >= 10 THEN '_' + RIGHT('0' + CAST(@CurrentFileNumber AS nvarchar),2) ELSE '' END + '_' + @CurrentDatabaseType + '_' + UPPER(@CurrentBackupType) + CASE WHEN @ReadWriteFileGroups = 'Y' THEN '_PARTIAL' ELSE '' END + CASE WHEN @CopyOnly = 'Y' THEN '_COPY_ONLY' ELSE '' END + '.' + @CurrentFileExtension
END
IF @CurrentFileNumber = 1 AND LEN(@MirrorDirectory) > 0
BEGIN
SET @CurrentMirrorFilePath = @MirrorDirectory + CASE WHEN RIGHT(@MirrorDirectory,1) = '\' THEN '' ELSE '\' END + CASE WHEN @CurrentBackupType = 'LOG' THEN '\Transaction Dumps\' + @CurrentDatabaseNameFS ELSE '' END + '\' + CASE WHEN @CurrentAvailabilityGroup IS NOT NULL THEN @Cluster + '$' + @CurrentAvailabilityGroup ELSE REPLACE(CAST(SERVERPROPERTY('servername') AS nvarchar),'\','$') END + '_' + @CurrentDatabaseNameFS + '_' + REPLACE(REPLACE(REPLACE((CONVERT(nvarchar,@CurrentDate,120)),'-',''),' ','_'),':','') + CASE WHEN @NumberOfFiles > 1 AND @NumberOfFiles <= 9 THEN '_' + CAST(@CurrentFileNumber AS nvarchar) WHEN @NumberOfFiles >= 10 THEN '_' + RIGHT('0' + CAST(@CurrentFileNumber AS nvarchar),2) ELSE '' END + '_' + @CurrentDatabaseType + '_' + UPPER(@CurrentBackupType) + CASE WHEN @ReadWriteFileGroups = 'Y' THEN '_PARTIAL' ELSE '' END + CASE WHEN @CopyOnly = 'Y' THEN '_COPY_ONLY' ELSE '' END + '.' + @CurrentFileExtension
IF LEN(@CurrentFilePath) > 257
BEGIN
SET @CurrentMirrorFilePath = @MirrorDirectory + CASE WHEN RIGHT(@MirrorDirectory,1) = '\' THEN '' ELSE '\' END + CASE WHEN @CurrentBackupType = 'LOG' THEN '\Transaction Dumps\' + @CurrentDatabaseNameFS ELSE '' END + '\' + CASE WHEN @CurrentAvailabilityGroup IS NOT NULL THEN @Cluster + '$' + @CurrentAvailabilityGroup ELSE REPLACE(CAST(SERVERPROPERTY('servername') AS nvarchar),'\','$') END + '_' + LEFT(@CurrentDatabaseNameFS,CASE WHEN (LEN(@CurrentDatabaseNameFS) + 257 - LEN(@CurrentFilePath) - 3) < 20 THEN 20 ELSE (LEN(@CurrentDatabaseNameFS) + 257 - LEN(@CurrentFilePath) - 3) END) + '...' + '_' + REPLACE(REPLACE(REPLACE((CONVERT(nvarchar,@CurrentDate,120)),'-',''),' ','_'),':','') + CASE WHEN @NumberOfFiles > 1 AND @NumberOfFiles <= 9 THEN '_' + CAST(@CurrentFileNumber AS nvarchar) WHEN @NumberOfFiles >= 10 THEN '_' + RIGHT('0' + CAST(@CurrentFileNumber AS nvarchar),2) ELSE '' END + '_' + @CurrentDatabaseType + '_' + UPPER(@CurrentBackupType) + CASE WHEN @ReadWriteFileGroups = 'Y' THEN '_PARTIAL' ELSE '' END + CASE WHEN @CopyOnly = 'Y' THEN '_COPY_ONLY' ELSE '' END + '.' + @CurrentFileExtension
END
END
INSERT INTO @CurrentFiles (CurrentFilePath)
SELECT @CurrentFilePath
SET @CurrentDirectoryPath = NULL
SET @CurrentFilePath = NULL
END
-- Create directory
WHILE EXISTS (SELECT * FROM @CurrentDirectories WHERE CreateCompleted = 0)
BEGIN
SELECT TOP 1 @CurrentDirectoryID = ID,
@CurrentDirectoryPath = DirectoryPath
FROM @CurrentDirectories
WHERE CreateCompleted = 0
ORDER BY ID ASC
SET @CurrentCommandType01 = 'xp_create_subdir'
SET @CurrentCommand01 = 'DECLARE @ReturnCode int EXECUTE @ReturnCode = [master].dbo.xp_create_subdir N''' + REPLACE(@CurrentDirectoryPath,'''','''''') + ''' IF @ReturnCode <> 0 RAISERROR(''Error creating directory.'', 16, 1)'
EXECUTE @CurrentCommandOutput01 = [dbo].[CommandExecute] @Command = @CurrentCommand01, @CommandType = @CurrentCommandType01, @Mode = 1, @DatabaseName = @CurrentDatabaseName, @LogToTable = @LogToTable, @Execute = @Execute
SET @Error = @@ERROR
IF @Error <> 0 SET @CurrentCommandOutput01 = @Error
IF @CurrentCommandOutput01 <> 0 SET @ReturnCode = @CurrentCommandOutput01
UPDATE @CurrentDirectories
SET CreateCompleted = 1,
CreateOutput = @CurrentCommandOutput01
WHERE ID = @CurrentDirectoryID
SET @CurrentDirectoryID = NULL
SET @CurrentDirectoryPath = NULL
SET @CurrentCommand01 = NULL
SET @CurrentCommandOutput01 = NULL
SET @CurrentCommandType01 = NULL
END
-- Perform a backup
IF NOT EXISTS (SELECT * FROM @CurrentDirectories WHERE CreateOutput <> 0 OR CreateOutput IS NULL)
BEGIN
IF @BackupSoftware IS NULL
BEGIN
SELECT @CurrentCommandType02 = CASE
WHEN @CurrentBackupType IN('DIFF','FULL') THEN 'BACKUP_DATABASE'
WHEN @CurrentBackupType = 'LOG' THEN 'BACKUP_LOG'
END
SELECT @CurrentCommand02 = CASE
WHEN @CurrentBackupType IN('DIFF','FULL') THEN 'BACKUP DATABASE ' + QUOTENAME(@CurrentDatabaseName)
WHEN @CurrentBackupType = 'LOG' THEN 'BACKUP LOG ' + QUOTENAME(@CurrentDatabaseName)
END
IF @ReadWriteFileGroups = 'Y' SET @CurrentCommand02 = @CurrentCommand02 + ' READ_WRITE_FILEGROUPS'
SET @CurrentCommand02 = @CurrentCommand02 + ' TO'
SELECT @CurrentCommand02 = @CurrentCommand02 + ' DISK = N''' + REPLACE(CurrentFilePath,'''','''''') + '''' + CASE WHEN ROW_NUMBER() OVER (ORDER BY CurrentFilePath ASC) <> @NumberOfFiles THEN ',' ELSE '' END
FROM @CurrentFiles
ORDER BY CurrentFilePath ASC
SET @CurrentCommand02 = @CurrentCommand02 + ' WITH '
IF @CheckSum = 'Y' SET @CurrentCommand02 = @CurrentCommand02 + 'CHECKSUM'
IF @CheckSum = 'N' SET @CurrentCommand02 = @CurrentCommand02 + 'NO_CHECKSUM'
IF @Compress = 'Y' SET @CurrentCommand02 = @CurrentCommand02 + ', COMPRESSION'
IF @Compress = 'N' AND @Version >= 10 SET @CurrentCommand02 = @CurrentCommand02 + ', NO_COMPRESSION'
IF @CurrentBackupType = 'DIFF' SET @CurrentCommand02 = @CurrentCommand02 + ', DIFFERENTIAL'
IF @CopyOnly = 'Y' SET @CurrentCommand02 = @CurrentCommand02 + ', COPY_ONLY'
IF @BlockSize IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', BLOCKSIZE = ' + CAST(@BlockSize AS nvarchar)
IF @BufferCount IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', BUFFERCOUNT = ' + CAST(@BufferCount AS nvarchar)
IF @MaxTransferSize IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', MAXTRANSFERSIZE = ' + CAST(@MaxTransferSize AS nvarchar)
IF @Description IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', DESCRIPTION = N''' + REPLACE(@Description,'''','''''') + ''''
END
IF @BackupSoftware = 'LITESPEED'
BEGIN
SELECT @CurrentCommandType02 = CASE
WHEN @CurrentBackupType IN('DIFF','FULL') THEN 'xp_backup_database'
WHEN @CurrentBackupType = 'LOG' THEN 'xp_backup_log'
END
SELECT @CurrentCommand02 = CASE
WHEN @CurrentBackupType IN('DIFF','FULL') THEN 'DECLARE @ReturnCode int EXECUTE @ReturnCode = [master].dbo.xp_backup_database @database = N''' + REPLACE(@CurrentDatabaseName,'''','''''') + ''''
WHEN @CurrentBackupType = 'LOG' THEN 'DECLARE @ReturnCode int EXECUTE @ReturnCode = [master].dbo.xp_backup_log @database = N''' + REPLACE(@CurrentDatabaseName,'''','''''') + ''''
END
SELECT @CurrentCommand02 = @CurrentCommand02 + ', @filename = N''' + REPLACE(CurrentFilePath,'''','''''') + ''''
FROM @CurrentFiles
ORDER BY CurrentFilePath ASC
SET @CurrentCommand02 = @CurrentCommand02 + ', @with = '''
IF @CheckSum = 'Y' SET @CurrentCommand02 = @CurrentCommand02 + 'CHECKSUM'
IF @CheckSum = 'N' SET @CurrentCommand02 = @CurrentCommand02 + 'NO_CHECKSUM'
IF @CurrentBackupType = 'DIFF' SET @CurrentCommand02 = @CurrentCommand02 + ', DIFFERENTIAL'
IF @CopyOnly = 'Y' SET @CurrentCommand02 = @CurrentCommand02 + ', COPY_ONLY'
IF @BlockSize IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', BLOCKSIZE = ' + CAST(@BlockSize AS nvarchar)
SET @CurrentCommand02 = @CurrentCommand02 + ''''
IF @ReadWriteFileGroups = 'Y' SET @CurrentCommand02 = @CurrentCommand02 + ', @read_write_filegroups = 1'
IF @CompressionLevel IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', @compressionlevel = ' + CAST(@CompressionLevel AS nvarchar)
IF @BufferCount IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', @buffercount = ' + CAST(@BufferCount AS nvarchar)
IF @MaxTransferSize IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', @maxtransfersize = ' + CAST(@MaxTransferSize AS nvarchar)
IF @Threads IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', @threads = ' + CAST(@Threads AS nvarchar)
IF @Throttle IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', @throttle = ' + CAST(@Throttle AS nvarchar)
IF @Description IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', @desc = N''' + REPLACE(@Description,'''','''''') + ''''
IF @EncryptionType IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', @cryptlevel = ' + CASE
WHEN @EncryptionType = 'RC2-40' THEN '0'
WHEN @EncryptionType = 'RC2-56' THEN '1'
WHEN @EncryptionType = 'RC2-112' THEN '2'
WHEN @EncryptionType = 'RC2-128' THEN '3'
WHEN @EncryptionType = '3DES-168' THEN '4'
WHEN @EncryptionType = 'RC4-128' THEN '5'
WHEN @EncryptionType = 'AES-128' THEN '6'
WHEN @EncryptionType = 'AES-192' THEN '7'
WHEN @EncryptionType = 'AES-256' THEN '8'
END
IF @EncryptionKey IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', @encryptionkey = N''' + REPLACE(@EncryptionKey,'''','''''') + ''''
SET @CurrentCommand02 = @CurrentCommand02 + ' IF @ReturnCode <> 0 RAISERROR(''Error performing LiteSpeed backup.'', 16, 1)'
END
IF @BackupSoftware = 'SQLBACKUP'
BEGIN
SET @CurrentCommandType02 = 'sqlbackup'
SELECT @CurrentCommand02 = CASE
WHEN @CurrentBackupType IN('DIFF','FULL') THEN 'BACKUP DATABASE ' + QUOTENAME(@CurrentDatabaseName)
WHEN @CurrentBackupType = 'LOG' THEN 'BACKUP LOG ' + QUOTENAME(@CurrentDatabaseName)
END
IF @ReadWriteFileGroups = 'Y' SET @CurrentCommand02 = @CurrentCommand02 + ' READ_WRITE_FILEGROUPS'
SET @CurrentCommand02 = @CurrentCommand02 + ' TO'
SELECT @CurrentCommand02 = @CurrentCommand02 + ' DISK = N''' + REPLACE(CurrentFilePath,'''','''''') + '''' + CASE WHEN ROW_NUMBER() OVER (ORDER BY CurrentFilePath ASC) <> @NumberOfFiles THEN ',' ELSE '' END
FROM @CurrentFiles
ORDER BY CurrentFilePath ASC
SET @CurrentCommand02 = @CurrentCommand02 + ' WITH '
IF @CheckSum = 'Y' SET @CurrentCommand02 = @CurrentCommand02 + 'CHECKSUM'
IF @CheckSum = 'N' SET @CurrentCommand02 = @CurrentCommand02 + 'NO_CHECKSUM'
IF @CurrentBackupType = 'DIFF' SET @CurrentCommand02 = @CurrentCommand02 + ', DIFFERENTIAL'
IF @CopyOnly = 'Y' SET @CurrentCommand02 = @CurrentCommand02 + ', COPY_ONLY'
IF @CompressionLevel IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', COMPRESSION = ' + CAST(@CompressionLevel AS nvarchar)
IF @Threads IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', THREADCOUNT = ' + CAST(@Threads AS nvarchar)
IF @MaxTransferSize IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', MAXTRANSFERSIZE = ' + CAST(@MaxTransferSize AS nvarchar)
IF @Description IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', DESCRIPTION = N''' + REPLACE(@Description,'''','''''') + ''''
IF @EncryptionType IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', KEYSIZE = ' + CASE
WHEN @EncryptionType = 'AES-128' THEN '128'
WHEN @EncryptionType = 'AES-256' THEN '256'
END
IF @EncryptionKey IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', PASSWORD = N''' + REPLACE(@EncryptionKey,'''','''''') + ''''
SET @CurrentCommand02 = 'DECLARE @ReturnCode int EXECUTE @ReturnCode = [master].dbo.sqlbackup N''-SQL "' + REPLACE(@CurrentCommand02,'''','''''') + '"''' + ' IF @ReturnCode <> 0 RAISERROR(''Error performing SQLBackup backup.'', 16, 1)'
END
IF @BackupSoftware = 'HYPERBAC'
BEGIN
SET @CurrentCommandType02 = 'BACKUP_DATABASE'
SELECT @CurrentCommand02 = CASE
WHEN @CurrentBackupType IN('DIFF','FULL') THEN 'BACKUP DATABASE ' + QUOTENAME(@CurrentDatabaseName)
WHEN @CurrentBackupType = 'LOG' THEN 'BACKUP LOG ' + QUOTENAME(@CurrentDatabaseName)
END
IF @ReadWriteFileGroups = 'Y' SET @CurrentCommand02 = @CurrentCommand02 + ' READ_WRITE_FILEGROUPS'
SET @CurrentCommand02 = @CurrentCommand02 + ' TO'
SELECT @CurrentCommand02 = @CurrentCommand02 + ' DISK = N''' + REPLACE(CurrentFilePath,'''','''''') + '''' + CASE WHEN ROW_NUMBER() OVER (ORDER BY CurrentFilePath ASC) <> @NumberOfFiles THEN ',' ELSE '' END
FROM @CurrentFiles
ORDER BY CurrentFilePath ASC
SET @CurrentCommand02 = @CurrentCommand02 + ' WITH '
IF @CheckSum = 'Y' SET @CurrentCommand02 = @CurrentCommand02 + 'CHECKSUM'
IF @CheckSum = 'N' SET @CurrentCommand02 = @CurrentCommand02 + 'NO_CHECKSUM'
IF @CurrentBackupType = 'DIFF' SET @CurrentCommand02 = @CurrentCommand02 + ', DIFFERENTIAL'
IF @CopyOnly = 'Y' SET @CurrentCommand02 = @CurrentCommand02 + ', COPY_ONLY'
IF @BlockSize IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', BLOCKSIZE = ' + CAST(@BlockSize AS nvarchar)
IF @BufferCount IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', BUFFERCOUNT = ' + CAST(@BufferCount AS nvarchar)
IF @MaxTransferSize IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', MAXTRANSFERSIZE = ' + CAST(@MaxTransferSize AS nvarchar)
IF @Description IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', DESCRIPTION = N''' + REPLACE(@Description,'''','''''') + ''''
END
IF @BackupSoftware = 'SQLSAFE'
BEGIN
SET @CurrentCommandType02 = 'xp_ss_backup'
SET @CurrentCommand02 = 'DECLARE @ReturnCode int EXECUTE @ReturnCode = [master].dbo.xp_ss_backup @database = N''' + REPLACE(@CurrentDatabaseName,'''','''''') + ''''
SELECT @CurrentCommand02 = @CurrentCommand02 + ', ' + CASE WHEN ROW_NUMBER() OVER (ORDER BY CurrentFilePath ASC) = 1 THEN '@filename' ELSE '@backupfile' END + ' = N''' + REPLACE(CurrentFilePath,'''','''''') + ''''
FROM @CurrentFiles
ORDER BY CurrentFilePath ASC
IF @CurrentMirrorFilePath IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', @mirrorfile = N''' + @CurrentMirrorFilePath + ''''
SET @CurrentCommand02 = @CurrentCommand02 + ', @backuptype = ' + CASE WHEN @CurrentBackupType = 'FULL' THEN '''Full''' WHEN @CurrentBackupType = 'DIFF' THEN '''Differential''' WHEN @CurrentBackupType = 'LOG' THEN '''Log''' END
IF @ReadWriteFileGroups = 'Y' SET @CurrentCommand02 = @CurrentCommand02 + ', @readwritefilegroups = 1'
SET @CurrentCommand02 = @CurrentCommand02 + ', @checksum = ' + CASE WHEN @CheckSum = 'Y' THEN '1' WHEN @CheckSum = 'N' THEN '0' END
SET @CurrentCommand02 = @CurrentCommand02 + ', @copyonly = ' + CASE WHEN @CopyOnly = 'Y' THEN '1' WHEN @CopyOnly = 'N' THEN '0' END
IF @CompressionLevel IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', @compressionlevel = ' + CASE WHEN @CompressionLevel = 5 THEN N'ispeed' WHEN @CompressionLevel = 6 THEN N'isize' ELSE CAST(@CompressionLevel AS nvarchar) END
IF @RetryWrites IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', @retrywrites = N''' + @RetryWrites + ''''
IF @Threads IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', @threads = ' + CAST(@Threads AS nvarchar)
IF @Description IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', @desc = N''' + REPLACE(@Description,'''','''''') + ''''
IF @EncryptionType IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', @encryptiontype = N''' + CASE
WHEN @EncryptionType = 'AES-128' THEN 'AES128'
WHEN @EncryptionType = 'AES-256' THEN 'AES256'
END + ''''
IF @EncryptionKey IS NOT NULL SET @CurrentCommand02 = @CurrentCommand02 + ', @encryptedbackuppassword = N''' + REPLACE(@EncryptionKey,'''','''''') + ''''
SET @CurrentCommand02 = @CurrentCommand02 + ' IF @ReturnCode <> 0 RAISERROR(''Error performing SQLsafe backup.'', 16, 1)'
END
EXECUTE @CurrentCommandOutput02 = [dbo].[CommandExecute] @Command = @CurrentCommand02, @CommandType = @CurrentCommandType02, @Mode = 1, @DatabaseName = @CurrentDatabaseName, @LogToTable = @LogToTable, @Execute = @Execute
SET @Error = @@ERROR
IF @Error <> 0 SET @CurrentCommandOutput02 = @Error
IF @CurrentCommandOutput02 <> 0 SET @ReturnCode = @CurrentCommandOutput02
END
-- Verify the backup
IF @CurrentCommandOutput02 = 0 AND @Verify = 'Y'
BEGIN
IF @BackupSoftware IS NULL
BEGIN
SET @CurrentCommandType03 = 'RESTORE_VERIFYONLY'
SET @CurrentCommand03 = 'RESTORE VERIFYONLY FROM'
SELECT @CurrentCommand03 = @CurrentCommand03 + ' DISK = N''' + REPLACE(CurrentFilePath,'''','''''') + '''' + CASE WHEN ROW_NUMBER() OVER (ORDER BY CurrentFilePath ASC) <> @NumberOfFiles THEN ',' ELSE '' END
FROM @CurrentFiles
ORDER BY CurrentFilePath ASC
SET @CurrentCommand03 = @CurrentCommand03 + ' WITH '
IF @CheckSum = 'Y' SET @CurrentCommand03 = @CurrentCommand03 + 'CHECKSUM'
IF @CheckSum = 'N' SET @CurrentCommand03 = @CurrentCommand03 + 'NO_CHECKSUM'
END
IF @BackupSoftware = 'LITESPEED'
BEGIN
SET @CurrentCommandType03 = 'xp_restore_verifyonly'
SET @CurrentCommand03 = 'DECLARE @ReturnCode int EXECUTE @ReturnCode = [master].dbo.xp_restore_verifyonly'
SELECT @CurrentCommand03 = @CurrentCommand03 + ' @filename = N''' + REPLACE(CurrentFilePath,'''','''''') + '''' + CASE WHEN ROW_NUMBER() OVER (ORDER BY CurrentFilePath ASC) <> @NumberOfFiles THEN ',' ELSE '' END
FROM @CurrentFiles
ORDER BY CurrentFilePath ASC
SET @CurrentCommand03 = @CurrentCommand03 + ', @with = '''
IF @CheckSum = 'Y' SET @CurrentCommand03 = @CurrentCommand03 + 'CHECKSUM'
IF @CheckSum = 'N' SET @CurrentCommand03 = @CurrentCommand03 + 'NO_CHECKSUM'
SET @CurrentCommand03 = @CurrentCommand03 + ''''
IF @EncryptionKey IS NOT NULL SET @CurrentCommand03 = @CurrentCommand03 + ', @encryptionkey = N''' + REPLACE(@EncryptionKey,'''','''''') + ''''
SET @CurrentCommand03 = @CurrentCommand03 + ' IF @ReturnCode <> 0 RAISERROR(''Error verifying LiteSpeed backup.'', 16, 1)'
END
IF @BackupSoftware = 'SQLBACKUP'
BEGIN
SET @CurrentCommandType03 = 'sqlbackup'
SET @CurrentCommand03 = 'RESTORE VERIFYONLY FROM'
SELECT @CurrentCommand03 = @CurrentCommand03 + ' DISK = N''' + REPLACE(CurrentFilePath,'''','''''') + '''' + CASE WHEN ROW_NUMBER() OVER (ORDER BY CurrentFilePath ASC) <> @NumberOfFiles THEN ',' ELSE '' END
FROM @CurrentFiles
ORDER BY CurrentFilePath ASC
SET @CurrentCommand03 = @CurrentCommand03 + ' WITH '
IF @CheckSum = 'Y' SET @CurrentCommand03 = @CurrentCommand03 + 'CHECKSUM'
IF @CheckSum = 'N' SET @CurrentCommand03 = @CurrentCommand03 + 'NO_CHECKSUM'
IF @EncryptionKey IS NOT NULL SET @CurrentCommand03 = @CurrentCommand03 + ', PASSWORD = N''' + REPLACE(@EncryptionKey,'''','''''') + ''''
SET @CurrentCommand03 = 'DECLARE @ReturnCode int EXECUTE @ReturnCode = [master].dbo.sqlbackup N''-SQL "' + REPLACE(@CurrentCommand03,'''','''''') + '"''' + ' IF @ReturnCode <> 0 RAISERROR(''Error verifying SQLBackup backup.'', 16, 1)'
END
IF @BackupSoftware = 'HYPERBAC'
BEGIN
SET @CurrentCommandType03 = 'RESTORE_VERIFYONLY'
SET @CurrentCommand03 = 'RESTORE VERIFYONLY FROM'
SELECT @CurrentCommand03 = @CurrentCommand03 + ' DISK = N''' + REPLACE(CurrentFilePath,'''','''''') + '''' + CASE WHEN ROW_NUMBER() OVER (ORDER BY CurrentFilePath ASC) <> @NumberOfFiles THEN ',' ELSE '' END
FROM @CurrentFiles
ORDER BY CurrentFilePath ASC
SET @CurrentCommand03 = @CurrentCommand03 + ' WITH '
IF @CheckSum = 'Y' SET @CurrentCommand03 = @CurrentCommand03 + 'CHECKSUM'
IF @CheckSum = 'N' SET @CurrentCommand03 = @CurrentCommand03 + 'NO_CHECKSUM'
END
IF @BackupSoftware = 'SQLSAFE'
BEGIN
SET @CurrentCommandType03 = 'xp_ss_verify'
SET @CurrentCommand03 = 'DECLARE @ReturnCode int EXECUTE @ReturnCode = [master].dbo.xp_ss_verify @database = N''' + REPLACE(@CurrentDatabaseName,'''','''''') + ''''
SELECT @CurrentCommand03 = @CurrentCommand03 + ', ' + CASE WHEN ROW_NUMBER() OVER (ORDER BY CurrentFilePath ASC) = 1 THEN '@filename' ELSE '@backupfile' END + ' = N''' + REPLACE(CurrentFilePath,'''','''''') + ''''
FROM @CurrentFiles
ORDER BY CurrentFilePath ASC
SET @CurrentCommand03 = @CurrentCommand03 + ' IF @ReturnCode <> 0 RAISERROR(''Error verifying SQLsafe backup.'', 16, 1)'
END
EXECUTE @CurrentCommandOutput03 = [dbo].[CommandExecute] @Command = @CurrentCommand03, @CommandType = @CurrentCommandType03, @Mode = 1, @DatabaseName = @CurrentDatabaseName, @LogToTable = @LogToTable, @Execute = @Execute
SET @Error = @@ERROR
IF @Error <> 0 SET @CurrentCommandOutput03 = @Error
IF @CurrentCommandOutput03 <> 0 SET @ReturnCode = @CurrentCommandOutput03
END
-- Delete old backup files
IF (@CurrentCommandOutput02 = 0 AND @Verify = 'N' AND @CurrentCleanupDate IS NOT NULL)
OR (@CurrentCommandOutput02 = 0 AND @Verify = 'Y' AND @CurrentCommandOutput03 = 0 AND @CurrentCleanupDate IS NOT NULL)
BEGIN
WHILE EXISTS (SELECT * FROM @CurrentDirectories WHERE CleanupCompleted = 0)
BEGIN
SELECT TOP 1 @CurrentDirectoryID = ID,
@CurrentDirectoryPath = DirectoryPath
FROM @CurrentDirectories
WHERE CleanupCompleted = 0
ORDER BY ID ASC
IF @BackupSoftware IS NULL
BEGIN
SET @CurrentCommandType04 = 'xp_delete_file'
SET @CurrentCommand04 = 'DECLARE @ReturnCode int EXECUTE @ReturnCode = [master].dbo.xp_delete_file 0, N''' + REPLACE(@CurrentDirectoryPath,'''','''''') + ''', ''' + @CurrentFileExtension + ''', ''' + CONVERT(nvarchar(19),@CurrentCleanupDate,126) + ''' IF @ReturnCode <> 0 RAISERROR(''Error deleting files.'', 16, 1)'
END
IF @BackupSoftware = 'LITESPEED'
BEGIN
SET @CurrentCommandType04 = 'xp_slssqlmaint'
SET @CurrentCommand04 = 'DECLARE @ReturnCode int EXECUTE @ReturnCode = [master].dbo.xp_slssqlmaint N''-MAINTDEL -DELFOLDER "' + REPLACE(@CurrentDirectoryPath,'''','''''') + '" -DELEXTENSION "' + @CurrentFileExtension + '" -DELUNIT "' + CAST(DATEDIFF(mi,@CurrentCleanupDate,GETDATE()) + 1 AS nvarchar) + '" -DELUNITTYPE "minutes" -DELUSEAGE'' IF @ReturnCode <> 0 RAISERROR(''Error deleting LiteSpeed backup files.'', 16, 1)'
END
IF @BackupSoftware = 'SQLBACKUP'
BEGIN
SET @CurrentCommandType04 = 'sqbutility'
SET @CurrentCommand04 = 'DECLARE @ReturnCode int EXECUTE @ReturnCode = [master].dbo.sqbutility 1032, N''' + REPLACE(@CurrentDatabaseName,'''','''''') + ''', N''' + REPLACE(@CurrentDirectoryPath,'''','''''') + ''', ''' + CASE WHEN @CurrentBackupType = 'FULL' THEN 'D' WHEN @CurrentBackupType = 'DIFF' THEN 'I' WHEN @CurrentBackupType = 'LOG' THEN 'L' END + ''', ''' + CAST(DATEDIFF(hh,@CurrentCleanupDate,GETDATE()) + 1 AS nvarchar) + 'h'', ' + ISNULL('''' + REPLACE(@EncryptionKey,'''','''''') + '''','NULL') + ' IF @ReturnCode <> 0 RAISERROR(''Error deleting SQLBackup backup files.'', 16, 1)'
END
IF @BackupSoftware = 'HYPERBAC'
BEGIN
SET @CurrentCommandType04 = 'xp_delete_file'
SET @CurrentCommand04 = 'DECLARE @ReturnCode int EXECUTE @ReturnCode = [master].dbo.xp_delete_file 0, N''' + REPLACE(@CurrentDirectoryPath,'''','''''') + ''', ''' + @CurrentFileExtension + ''', ''' + CONVERT(nvarchar(19),@CurrentCleanupDate,126) + ''' IF @ReturnCode <> 0 RAISERROR(''Error deleting files.'', 16, 1)'
END
IF @BackupSoftware = 'SQLSAFE'
BEGIN
SET @CurrentCommandType04 = 'xp_ss_delete'
SET @CurrentCommand04 = 'DECLARE @ReturnCode int EXECUTE @ReturnCode = [master].dbo.xp_ss_delete @filename = N''' + REPLACE(@CurrentDirectoryPath,'''','''''') + '\*.' + @CurrentFileExtension + ''', @age = ''' + CAST(DATEDIFF(mi,@CurrentCleanupDate,GETDATE()) + 1 AS nvarchar) + 'Minutes'' IF @ReturnCode <> 0 RAISERROR(''Error deleting SQLsafe backup files.'', 16, 1)'
END
EXECUTE @CurrentCommandOutput04 = [dbo].[CommandExecute] @Command = @CurrentCommand04, @CommandType = @CurrentCommandType04, @Mode = 1, @DatabaseName = @CurrentDatabaseName, @LogToTable = @LogToTable, @Execute = @Execute
SET @Error = @@ERROR
IF @Error <> 0 SET @CurrentCommandOutput04 = @Error
IF @CurrentCommandOutput04 <> 0 SET @ReturnCode = @CurrentCommandOutput04
UPDATE @CurrentDirectories
SET CleanupCompleted = 1,
CleanupOutput = @CurrentCommandOutput04
WHERE ID = @CurrentDirectoryID
SET @CurrentDirectoryID = NULL
SET @CurrentDirectoryPath = NULL
SET @CurrentCommand04 = NULL
SET @CurrentCommandOutput04 = NULL
SET @CurrentCommandType04 = NULL
END
END
END
-- Update that the database is completed
UPDATE @tmpDatabases
SET Completed = 1
WHERE Selected = 1
AND Completed = 0
AND ID = @CurrentDBID
-- Clear variables
SET @CurrentDBID = NULL
SET @CurrentDatabaseID = NULL
SET @CurrentDatabaseName = NULL
SET @CurrentBackupType = NULL
SET @CurrentFileExtension = NULL
SET @CurrentFileNumber = NULL
SET @CurrentDifferentialBaseLSN = NULL
SET @CurrentDifferentialBaseIsSnapshot = NULL
SET @CurrentLogLSN = NULL
SET @CurrentLatestBackup = NULL
SET @CurrentDatabaseNameFS = NULL
SET @CurrentDatabaseType = NULL
SET @CurrentDate = NULL
SET @CurrentCleanupDate = NULL
SET @CurrentIsDatabaseAccessible = NULL
SET @CurrentAvailabilityGroup = NULL
SET @CurrentAvailabilityGroupRole = NULL
SET @CurrentIsPreferredBackupReplica = NULL
SET @CurrentDatabaseMirroringRole = NULL
SET @CurrentLogShippingRole = NULL
SET @CurrentCommand02 = NULL
SET @CurrentCommand03 = NULL
SET @CurrentCommandOutput02 = NULL
SET @CurrentCommandOutput03 = NULL
SET @CurrentCommandType02 = NULL
SET @CurrentCommandType03 = NULL
DELETE FROM @CurrentDirectories
DELETE FROM @CurrentFiles
END
--// Log completing information //--
Logging:
SET @EndMessage = 'Date and time: ' + CONVERT(nvarchar,GETDATE(),120)
SET @EndMessage = REPLACE(@EndMessage,'%','%%')
RAISERROR(@EndMessage,10,1) WITH NOWAIT
IF @ReturnCode <> 0
BEGIN
RETURN @ReturnCode
END
END
GO
ALTER AUTHORIZATION ON [dbo].[DatabaseBackup] TO SCHEMA OWNER
GO
Diane
Maybe you are looking for
-
Hi friends, I make one header alv ok I want and take one variable count in my program so I want to display its value in ALV HEADER Total Target Qty: Total EMP. Efficiency Total Machine Effi. I take may header like this and pass thre text here.ok No
-
How to diagnose flickering exported JS animations from Flash CC?
Quick stats on my system: Macbook Pro Retina 2012 running OSX 10.9.3 Flash CC 13.1.0.226 I'm not experiencing an error so much as a lack of understanding about how to diagnose Flash CC JS export issues. Here's the backstory: In 2012, my company start
-
Statefull bean Reference in a JSP
Weblogic Server 4.5.1 I have got the reference to a statefull session bean in a JSP, how can i use the same reference of session bean in another JSP file. How is this achieved. Here is an example of the problem
-
Where did the orginalsprache go?
I can't find movies in original language anymore after updating to iOS 5 in it's new interface. Here in Germany it's called "orginalsprache". Anyone else having the same problem?
-
Please forgive me If the issue I have raised is one that has been discussed at length previously. I am new to all things Apple and new to discussion forums. I am now the owner of an Apple TV. I intend to use it with my Panasonic HD ready plasma. Howe