Production server maintenance necessary tools like SQL Express database schedule backup, Database backup file upload to azure storage etc.
DatabaseJobs.Client/App.config
file.
<add key="ServerName" value=".\SQLEXPRESS" ></add> <!--database server name-->
<add key="EnableShrink" value="true" ></add> <!--enable index reorganize before taking backup, rebild index after shrink-->
<add key="EnableIndexMaintenance" value="true"></add> <!--enable index reorganize before taking backup, rebild index after shrink-->
<add key="BackupAllDatabases" value="true" ></add> <!--backup all database of the provided server except system databases-->
<add key="BackupDatabases" value="AuditorDb,UrlShortenDb" ></add> <!--existing database names of the provided server-->
<add key="UseRootBackupDirectory" value="false" ></add> <!--backup will be stored on the application hosted base directory-->
<add key="BackupDirectoryPath" value="C:\temp\backups\" ></add> <!--define a specific backup location. it will activate when UseRootBackupDirectory is false-->
<add key="RemoveBackupAfterXDays" value="5" ></add> <!--remove older backup after n days, empty for disable this rule-->
<add key="RemoveBakFileAfterZip" value="true" ></add> <!--remove .bak file after zip completion-->
<add key="PushToAzureStorage" value="true" ></add> <!--true for push the backup zip file to your azure storage blob-->
<!--aws s3 bucket config-->
<add key="PushToAwsS3Bucket" value="false"></add>
<add key="AwsAccessKey" value="*your aws access key*"></add>
<add key="AwsSecretKey" value="*your aws secret key*"></add>
<add key="S3BucketName" value="*your bucket name*"></add>
<add key="S3BucketRegion" value="ap-southeast-1"></add>
only if you make PushToAzureStorage is true
) <add name="AzureStroage" connectionString="DefaultEndpointsProtocol=https;AccountName=yourAzureStorageAccountName;AccountKey=yourAzureStroageAccountKey;EndpointSuffix=core.windows.net" ></add>
Rebuild all index of a database in SQL Server
Command: Exec sp_msforeachtable 'SET QUOTED_IDENTIFIER ON; ALTER INDEX ALL ON ? REBUILD'
Reorganize all index of a database in SQL Server
Command: Exec sp_msforeachtable 'SET QUOTED_IDENTIFIER ON; ALTER INDEX ALL ON ? REBUILD'
sLogFolder = "c:\inetpub\logs\LogFiles"
iMaxAge = 30 'in days
Set objFSO = CreateObject("Scripting.FileSystemObject")
set colFolder = objFSO.GetFolder(sLogFolder)
For Each colSubfolder in colFolder.SubFolders
Set objFolder = objFSO.GetFolder(colSubfolder.Path)
Set colFiles = objFolder.Files
For Each objFile in colFiles
iFileAge = now-objFile.DateCreated
if iFileAge > (iMaxAge+1) then
objFSO.deletefile objFile, True
end if
Next
Next