{"id":15002854,"url":"https://github.com/brokenthorn/mssql-database-backup-service","last_synced_at":"2025-10-30T09:31:07.607Z","repository":{"id":181612176,"uuid":"299705268","full_name":"brokenthorn/mssql-database-backup-service","owner":"brokenthorn","description":"A quick and dirty Windows Service for running SQL commands regularly, mainly to maintain regular database backups","archived":false,"fork":false,"pushed_at":"2020-10-07T21:01:02.000Z","size":30,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-02T07:41:24.631Z","etag":null,"topics":["csharp","dotnet-core","dotnetcore","mssql","mssql-backup","mssql-server","mssqlserver","quartz-scheduler","scheduling-backups","sql-agent","sql-server","topshelf","windows-services"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brokenthorn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-09-29T18:32:14.000Z","updated_at":"2024-05-02T11:59:18.000Z","dependencies_parsed_at":"2023-07-16T14:03:45.637Z","dependency_job_id":null,"html_url":"https://github.com/brokenthorn/mssql-database-backup-service","commit_stats":null,"previous_names":["brokenthorn/mssql-database-backup-service"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brokenthorn%2Fmssql-database-backup-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brokenthorn%2Fmssql-database-backup-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brokenthorn%2Fmssql-database-backup-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brokenthorn%2Fmssql-database-backup-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brokenthorn","download_url":"https://codeload.github.com/brokenthorn/mssql-database-backup-service/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238950485,"owners_count":19557533,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnet-core","dotnetcore","mssql","mssql-backup","mssql-server","mssqlserver","quartz-scheduler","scheduling-backups","sql-agent","sql-server","topshelf","windows-services"],"created_at":"2024-09-24T18:53:14.165Z","updated_at":"2025-10-30T09:31:04.941Z","avatar_url":"https://github.com/brokenthorn.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bt_sql_backup_service\n\nA quick and dirty Windows Service replacement for [SQL Server\nAgent](https://en.wikipedia.org/wiki/SQL_Server_Agent).\n\nI built this to monitor and automate database backups to local disk and cloud\nstorage for on-premise servers running SQL Server Express edition, which doesn't\nhave SQL Server Agent.\n\nThere are\n[other](https://www.mssqltips.com/sqlservertip/5830/how-to-schedule-sql-scripts-on-sql-server-express-edition/)\nsolutions out there but they seem very\n[limited](https://stackoverflow.com/questions/7201061/how-to-create-jobs-in-sql-server-express-edition)\n(no reporting, no notification, no auditing, no integration and not to mention,\nvery hard to maintain).\n\nI plan to gradually add new functionality to this service over time. Check the\nTODO list below for more info.\n\n## How to Build, Install and Use\n\n1. Clone this repository using Git or download a zipped version from GitHub.\n1. Install the [.Net Core 3.1\n   SDK](https://dotnet.microsoft.com/download/dotnet-core/3.1) if you don't have\n   it already.\n1. Open a command line and navigate to the folder where the source code is and\n   run:\n\n   ```sh\n   $dotnet publish -r win-x64 -c Release\n   ```\n\n   If you don't like publishing the app with so many DLLs and other files in the\n   same folder, you can try publishing as a single file, which will zip all the\n   dependencies together in the EXE and unzip it to a temp folder at runtime\n   (initial startup time will be slower):\n\n   ```sh\n   $dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true\n   ```\n\n1. Move the generated EXE (and optional dependencies) to your folder of\n   preference. There is no installer yet.\n1. Make sure you also create a `sql_commands.json` file in\n   the same folder as the service EXE.\n1. Set up SQL command jobs by editing `sql_commands.json`. There is an example\n   file provided in this repository.\n1. Customize the `SmtpClientSettings` section of the config in the `appsettings.json` file.\n   `AdminEmail` is the email address to which to send notifications of errors and other\n   information that occurs outside of jobs (like when the service is started or stopped).\n1. Install and start the service by running\n\n   ```sh\n   $bt_sql_backup_service.exe install\n   $bt_sql_backup_service.exe start\n   ```\n\n1. Check Windows Event Viewer for log messages from the service and any errors.\n   You can also run the service executable from the command line and see log\n   messages outputted directly to the console by just calling the executable\n   with no arguments.\n\nMore command line arguments are available. Read the\n[Topshelf](http://topshelf-project.com/) project documentation for more info.\nFor example, you can install multiple instances of this service by passing\ncertain command line arguments when installing the service. Make sure you\ninstall the service from different folder if you do this, so they don't all load\nthe same settings and jobs.\n\n## The `sql_commands.json` file\n\nThis file contains a list of `SqlCommandEntity`. The service will read\nthis file on startup and load any commands defined there as jobs to schedule and\nexecute.\n\nAn example file is provided which should be self-explanatory:\n\n```json\n[\n  {\n    \"name\": \"Full backup of user databases\",\n    \"description\": \"Performs full backups to local disk, at 3:00 AM, for all user databases, using Ola Hallengren's DatabaseBackup procedure. After it's finished, it deletes backups older than 24h.\",\n    \"connectionString\": \"Server=127.0.0.1,1443;Connection Timeout=10;Database=master;User Id=USERNAME;Password=PASSWORD\",\n    \"sqlCommand\": \"EXECUTE [master].[dbo].[DatabaseBackup] @Databases = 'USER_DATABASES', @Directory = N'D:\\\\sqlbackups', @BackupType = 'FULL', @CleanupTime = 24, @CopyOnly = 'N', @MaxTransferSize = 4194304, @BufferCount = 25, @Compress = 'N', @CheckSum = 'Y', @Verify = 'N', @LogToTable = 'Y';\",\n    \"commandTimeout\": 10800,\n    \"cron\": \"0 0 3 ? * * *\"\n  },\n  {\n    \"name\": \"Diff backup of user databases\",\n    \"description\": \"Performs diff backups to local disk, every 2 hours from 10 AM to 10 PM, for all user databases, using Ola Hallengren's DatabaseBackup procedure. After it's finished, it deletes backups older than 24h.\",\n    \"connectionString\": \"Server=127.0.0.1,1443;Connection Timeout=10;Database=master;User Id=USERNAME;Password=PASSWORD\",\n    \"sqlCommand\": \"EXECUTE [master].[dbo].[DatabaseBackup] @Databases = 'USER_DATABASES', @Directory = N'D:\\\\sqlbackups', @BackupType = 'DIFF', @CleanupTime = 24, @CopyOnly = 'N', @MaxTransferSize = 4194304, @BufferCount = 25, @Compress = 'N', @CheckSum = 'Y', @Verify = 'N', @LogToTable = 'Y';\",\n    \"commandTimeout\": 10800,\n    \"cron\": \"0 0 10,12,14,16,18,20 ? * * *\"\n  }\n]\n```\n\nIn case you yet understand what this file does: this assumes you have [Ola's\n`DatabaseBackup`](https://ola.hallengren.com/sql-server-backup.html) script\ninstalled on the `master` database and a SQL Server instance installed and\nrunning on the same machine as the service.\n\nWhat this configuration essentially does is schedule a job for a full backup of\nall user databases everyday at 3 AM and a job for differential backups of all\nuser databases every 2 hours starting from 10 AM up until 8 PM including\n(assuming those are working hours, when the database gets new data added).\n\n## TODO\n\n- [x] Run SQL scripts on a CRON schedule.\n- [x] Email notifications.\n- [ ] Option to backup to Azure Blob Storage directly (as opposed to SQL Server\n      doing that).\n- [ ] Option to sync local backups to Azure Blob Storage or Azure File Shares in\n      order to preserve backup LSN chain and not have to run the same backup\n      twice.\n\n## Contributing\n\nPull requests are welcome. For major changes, please open an issue first to\ndiscuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrokenthorn%2Fmssql-database-backup-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrokenthorn%2Fmssql-database-backup-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrokenthorn%2Fmssql-database-backup-service/lists"}