项目作者: sabbiryan

项目描述 :
Production server maintenance necessary tools like SQL Express database schedule backup, Database backup file upload to azure storage etc.
高级语言: PowerShell
项目地址: git://github.com/sabbiryan/server-maintenance.git
创建时间: 2017-02-05T09:02:02Z
项目社区:https://github.com/sabbiryan/server-maintenance

开源协议:

下载


Features

  1. Automatic DB Backup Job
  2. Automatically create a zip copy of backup file
  3. Automatically push the zip backup file to Azure Storage
  4. Automatically push the zip backup file to AWS S3 Bucket
  5. Automatic Index Maintenance
  6. Shrik database to 10% and rebuild index after shrink

How to user it

  • Register as windows task scheduler

Getting Start

  • Clone this repository
  • Open the solution in Visual Studio (2019 recommended).
  • Open DatabaseJobs.Client/App.config file.
  • Check the following appSettings key value and change as your need
    1. <add key="ServerName" value=".\SQLEXPRESS" ></add> <!--database server name-->
    2. <add key="EnableShrink" value="true" ></add> <!--enable index reorganize before taking backup, rebild index after shrink-->
    3. <add key="EnableIndexMaintenance" value="true"></add> <!--enable index reorganize before taking backup, rebild index after shrink-->
    4. <add key="BackupAllDatabases" value="true" ></add> <!--backup all database of the provided server except system databases-->
    5. <add key="BackupDatabases" value="AuditorDb,UrlShortenDb" ></add> <!--existing database names of the provided server-->
    6. <add key="UseRootBackupDirectory" value="false" ></add> <!--backup will be stored on the application hosted base directory-->
    7. <add key="BackupDirectoryPath" value="C:\temp\backups\" ></add> <!--define a specific backup location. it will activate when UseRootBackupDirectory is false-->
    8. <add key="RemoveBackupAfterXDays" value="5" ></add> <!--remove older backup after n days, empty for disable this rule-->
    9. <add key="RemoveBakFileAfterZip" value="true" ></add> <!--remove .bak file after zip completion-->
    10. <add key="PushToAzureStorage" value="true" ></add> <!--true for push the backup zip file to your azure storage blob-->
    11. <!--aws s3 bucket config-->
    12. <add key="PushToAwsS3Bucket" value="false"></add>
    13. <add key="AwsAccessKey" value="*your aws access key*"></add>
    14. <add key="AwsSecretKey" value="*your aws secret key*"></add>
    15. <add key="S3BucketName" value="*your bucket name*"></add>
    16. <add key="S3BucketRegion" value="ap-southeast-1"></add>
  • Configur your azure storage connection string (only if you make PushToAzureStorage is true) <add name="AzureStroage" connectionString="DefaultEndpointsProtocol=https;AccountName=yourAzureStorageAccountName;AccountKey=yourAzureStroageAccountKey;EndpointSuffix=core.windows.net" ></add>
  • All are set now. Build and run the program.
  • Publish the client project and up it on your virtual machine and register as a windows task scheduler

Rebuild Index

Rebuild all index of a database in SQL Server

Command: Exec sp_msforeachtable 'SET QUOTED_IDENTIFIER ON; ALTER INDEX ALL ON ? REBUILD'

Reorganize Index

Reorganize all index of a database in SQL Server

Command: Exec sp_msforeachtable 'SET QUOTED_IDENTIFIER ON; ALTER INDEX ALL ON ? REBUILD'

Delete Old IIS Logs by Script

  1. sLogFolder = "c:\inetpub\logs\LogFiles"
  2. iMaxAge = 30 'in days
  3. Set objFSO = CreateObject("Scripting.FileSystemObject")
  4. set colFolder = objFSO.GetFolder(sLogFolder)
  5. For Each colSubfolder in colFolder.SubFolders
  6. Set objFolder = objFSO.GetFolder(colSubfolder.Path)
  7. Set colFiles = objFolder.Files
  8. For Each objFile in colFiles
  9. iFileAge = now-objFile.DateCreated
  10. if iFileAge > (iMaxAge+1) then
  11. objFSO.deletefile objFile, True
  12. end if
  13. Next
  14. Next