Skip to content

Commit 65755e8

Browse files
author
Ajay Dwivedi
committed
Updated powershell codes
Updated powershell codes
1 parent b6b9607 commit 65755e8

File tree

8 files changed

+137
-11
lines changed

8 files changed

+137
-11
lines changed
0 Bytes
Binary file not shown.

Baselining/Baselining.ssmssqlproj

+6
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@
241241
<AssociatedConnUserName />
242242
<FullPath>sp_Blitz Views Extra.sql</FullPath>
243243
</FileNode>
244+
<FileNode Name="SQLQuery1.sql">
245+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:LOCALHOST:True</AssociatedConnectionMoniker>
246+
<AssociatedConnSrvName>LOCALHOST</AssociatedConnSrvName>
247+
<AssociatedConnUserName />
248+
<FullPath>SQLQuery1.sql</FullPath>
249+
</FileNode>
244250
<FileNode Name="StackOverflow-TopQueries.sql">
245251
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:TUL1DBAPMTDB1\SQL2017:True</AssociatedConnectionMoniker>
246252
<AssociatedConnSrvName>TUL1DBAPMTDB1\SQL2017</AssociatedConnSrvName>

Baselining/SQLQuery1.sql

Whitespace-only changes.

BlitzQueries/BlitzQueries.ssmssqlproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@
206206
<FullPath>Detect n Reduce High VLFs.sql</FullPath>
207207
</FileNode>
208208
<FileNode Name="Other queries.sql">
209-
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:tul1cipxdb14:True</AssociatedConnectionMoniker>
210-
<AssociatedConnSrvName>tul1cipxdb14</AssociatedConnSrvName>
209+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:(local):True</AssociatedConnectionMoniker>
210+
<AssociatedConnSrvName>(local)</AssociatedConnSrvName>
211211
<AssociatedConnUserName />
212212
<FullPath>Other queries.sql</FullPath>
213213
</FileNode>

Misscellaneous Queries/RoboCopy.sql

+10-7
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@
33
-- https://stackoverflow.com/a/40750265
44

55
-- Copy single file named 'ACTIONSHEET_DATA_20180321.csq' from source folder to destination folder
6-
robocopy \\TUL1CIPEDB2\I$\Backup \\tul1dbapfs2\f$\TUL1CIPEDB2\Full_Backups COSMO_DATA_20180815.csq
7-
robocopy \\tul1cipedb2\I$\pssdiag_Output_June06_Ajay "E:\Cosmo Issue\Replication_PSSDiag_Output" CosmoServer__0125AM_to_0205AM_CST.zip
6+
robocopy \\SRCServer\I$\Backup \\DestinationServer\f$\Somefolder\Full_Backups COSMO_DATA_20180815.csq
7+
robocopy \\SRCServer\I$\pssdiag_Output_June06_Ajay "E:\Cosmo Issue\Replication_PSSDiag_Output" CosmoServer__0125AM_to_0205AM_CST.zip
88

9-
robocopy \\TUL1CIPEDB2\C$\DBA\SQLTrace E:\PerformanceAnalysis\Cosmo_Publisher_Baseline\SQLTrace TUL1CIPEDB2_25Jun2018_1030PM.zip
10-
robocopy \\TUL1CIPEDB2\C$\DBA\SQLTrace \\TUL1CIPCNPDB1\G$\DBA\SQLTrace TUL1CIPEDB2_25Jun2018_1030PM.trc
11-
robocopy \\TUL1CIPCNPDB1\G$\DBA\SQLTrace E:\PerformanceAnalysis\Cosmo_Publisher_Baseline\SQLTrace TUL1CIPCNPDB1_26Jun2018_0153AM.zip
9+
robocopy \\SRCServer\C$\DBA\SQLTrace E:\PerformanceAnalysis\Cosmo_Publisher_Baseline\SQLTrace SomeFile.zip
10+
robocopy \\SRCServer\C$\DBA\SQLTrace \\DestinationServer\G$\DBA\SQLTrace SomeFile.trc
11+
robocopy \\SRCServer\G$\DBA\SQLTrace E:\PerformanceAnalysis\Cosmo_Publisher_Baseline\SQLTrace SomeFile.zip
1212

1313
robocopy src dst sample.txt /is # copy if attributes are equal
1414
robocopy src dst sample.txt /it # copy if attributes differ
1515
robocopy src dst sample.txt /is /it # copy irrespective of attributes
1616

1717

1818
Step 01 - Copy Dbs Required by Job [Restore AMGMusicProdcopy DB from production]
19-
robocopy \\Ann1vesPDb02\F$\dump\db01\ v:\dump\DB02_dump\ "AMGMusicAuthority-data.DMP" "AMGMusicMore-data.DMP" "AMGMusic-data.DMP" "EntryAggregation-data.DMP" "VestaMusicProcessing-data.DMP"
19+
robocopy \\SRCServer\F$\dump\db01\ v:\dump\DB02_dump\ "AMGMusicAuthority-data.DMP" "AMGMusicMore-data.DMP" "AMGMusic-data.DMP" "EntryAggregation-data.DMP" "VestaMusicProcessing-data.DMP"
2020

2121
Step 02 - Copy All Dbs Except Step 01
22-
robocopy \\Ann1vesPDb02\F$\dump\db01\ v:\dump\DB02_dump\ *-data.DMP /XF "AMGMusicAuthority-data.DMP" "AMGMusicMore-data.DMP" "AMGMusic-data.DMP" "EntryAggregation-data.DMP" "VestaMusicProcessing-data.DMP"
22+
robocopy \\SRCServer\F$\dump\db01\ v:\dump\DB02_dump\ *-data.DMP /XF "AMGMusicAuthority-data.DMP" "AMGMusicMore-data.DMP" "AMGMusic-data.DMP" "EntryAggregation-data.DMP" "VestaMusicProcessing-data.DMP"
23+
24+
-- Copy all files of extension *.csql from source folder to destination
25+
robocopy \\SourceServer\F$\dump\ I:\Backups\CW\Logs\ *.csq /is
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Delete files older than 48 hours
2+
$CleanUpTimeHours = 48
3+
$CleanUpTimeMinutes = 5
4+
$a = Get-ChildItem I:\Backups\CW | Where-Object {$_.Name -like '*BKS*'}
5+
$filesRemoved = @();
6+
7+
try {
8+
if($a.Count -gt 0)
9+
{
10+
foreach($x in $a)
11+
{
12+
$y = ((Get-Date) - $x.CreationTime);
13+
$y_Hours = ($y.Days * 24) + ($y.Hours);
14+
$y_Minutes = ($y.Days * 24) + ($y.Hours) + ($y.Minutes);
15+
16+
#Folder
17+
if ($y_Hours -gt $CleanUpTimeHours -and $x.PsISContainer)
18+
{
19+
Write-Output "Removing folder '$($x.Name)' with its content";
20+
$files = Get-ChildItem $x.Fullname -Recurse | Where-Object {$_.PsISContainer -ne $True};
21+
$subFolders = Get-ChildItem $x.Fullname -Recurse | Where-Object {$_.PsISContainer};
22+
23+
# If files are found, then delete them
24+
if($files) {
25+
$filesNames = $files | Select-Object -ExpandProperty Name;
26+
$files | Remove-Item;
27+
}
28+
# If sub-folders are found, then delete them
29+
if($subFolders) {
30+
$subFolders | Remove-Item;
31+
}
32+
33+
$filesRemoved += $filesNames;
34+
$x.Delete();
35+
}
36+
}
37+
}
38+
if($filesRemoved.Count -eq 0) {
39+
Write-Output "No files to remove";
40+
}
41+
else {
42+
Write-Output "`r`nBelow files were removed successfully:- ";
43+
Write-Output $filesRemoved;
44+
}
45+
return 0; #success
46+
}
47+
catch {
48+
$formatstring = "{0} : {1}`n{2}`n" +
49+
" + CategoryInfo : {3}`n" +
50+
" + FullyQualifiedErrorId : {4}`n"
51+
$fields = $_.InvocationInfo.MyCommand.Name,
52+
$_.ErrorDetails.Message,
53+
$_.InvocationInfo.PositionMessage,
54+
$_.CategoryInfo.ToString(),
55+
$_.FullyQualifiedErrorId
56+
57+
$formatstring -f $fields
58+
Write-Output ($_.Exception.Message);
59+
return 1; #failure
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Delete files older than 48 hours
2+
$CleanUpTimeHours = 48
3+
$CleanUpTimeMinutes = 5
4+
$a = Get-ChildItem I:\Backups\CW\Logs
5+
$filesRemoved = @();
6+
7+
$filesRemoved = $a | Where-Object {$_.CreationTime -lt (Get-Date).AddHours(-$CleanUpTimeHours) }
8+
9+
try {
10+
if($filesRemoved.Count -gt 0)
11+
{
12+
Write-Output "`r`nRemoving $($filesRemoved.Count) number of files. ";
13+
$filesRemoved | Remove-Item;
14+
}
15+
else {
16+
Write-Output "No files to remove";
17+
}
18+
return 0; #success
19+
}
20+
catch {
21+
$formatstring = "{0} : {1}`n{2}`n" +
22+
" + CategoryInfo : {3}`n" +
23+
" + FullyQualifiedErrorId : {4}`n"
24+
$fields = $_.InvocationInfo.MyCommand.Name,
25+
$_.ErrorDetails.Message,
26+
$_.InvocationInfo.PositionMessage,
27+
$_.CategoryInfo.ToString(),
28+
$_.FullyQualifiedErrorId
29+
30+
$formatstring -f $fields
31+
Write-Output ($_.Exception.Message);
32+
return 1; #failure
33+
}

PowerShell Commands/PowerShell Commands.ssmssqlproj

+26-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@
3939
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
4040
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
4141
</ConnectionNode>
42+
<ConnectionNode Name="localhost:CORPORATE\adwivedi">
43+
<Created>2019-08-08T14:29:26.9893474+05:30</Created>
44+
<Type>SQL</Type>
45+
<Server>localhost</Server>
46+
<UserName />
47+
<Authentication>Windows Authentication</Authentication>
48+
<InitialDB>master</InitialDB>
49+
<LoginTimeout>30</LoginTimeout>
50+
<ExecutionTimeout>0</ExecutionTimeout>
51+
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
52+
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
53+
</ConnectionNode>
4254
</Items>
4355
</LogicalFolder>
4456
<LogicalFolder Name="Queries" Type="0" Sorted="true">
@@ -49,9 +61,21 @@
4961
<AssociatedConnUserName />
5062
<FullPath>All Query Against Servers.sql</FullPath>
5163
</FileNode>
64+
<FileNode Name="Cleanup_All_Files_in_All_SubFolders.sql">
65+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:localhost:True</AssociatedConnectionMoniker>
66+
<AssociatedConnSrvName>localhost</AssociatedConnSrvName>
67+
<AssociatedConnUserName />
68+
<FullPath>Cleanup_All_Files_in_All_SubFolders.sql</FullPath>
69+
</FileNode>
70+
<FileNode Name="Cleanup_All_Files_in_Single_Folder.sql">
71+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:localhost:True</AssociatedConnectionMoniker>
72+
<AssociatedConnSrvName>localhost</AssociatedConnSrvName>
73+
<AssociatedConnUserName />
74+
<FullPath>Cleanup_All_Files_in_Single_Folder.sql</FullPath>
75+
</FileNode>
5276
<FileNode Name="Common-Commands.sql">
53-
<AssociatedConnectionMoniker />
54-
<AssociatedConnSrvName />
77+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:localhost:True</AssociatedConnectionMoniker>
78+
<AssociatedConnSrvName>localhost</AssociatedConnSrvName>
5579
<AssociatedConnUserName />
5680
<FullPath>Common-Commands.sql</FullPath>
5781
</FileNode>

0 commit comments

Comments
 (0)