server icon indicating copy to clipboard operation
server copied to clipboard

[PM-3240] Shrink the database transaction logs after backup

Open zadjadr opened this issue 2 years ago • 5 comments
trafficstars

Type of change

- [X] Bug fix
- [ ] New feature development
- [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other

Objective

Without shrinking the transaction logs, mssql will keep them indefinitely. This would generate a huge log file after some time. In my case this is 27GB

Code changes

Most important change is adding

  • backup-db.sh: DBCC SHRINKFILE ('$(DATABASE_NAME)_log', EMPTYFILE);

According to https://learn.microsoft.com/de-de/sql/t-sql/database-console-commands/dbcc-shrinkfile-transact-sql?view=sql-server-ver16

  • file.ext: Description of what was changed and why

Before you submit

  • Please check for formatting errors (dotnet format --verify-no-changes) (required)
  • If making database changes - make sure you also update Entity Framework queries and/or migrations
  • Please add unit tests where it makes sense to do so (encouraged but not required)
  • If this change requires a documentation update - notify the documentation team
  • If this change has particular deployment requirements - notify the DevOps team

zadjadr avatar Jul 28 '23 11:07 zadjadr

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jul 28 '23 11:07 CLAassistant

Thank you for your contribution! We've added this to our internal Community PR board for review. ID: PM-3240

bitwarden-bot avatar Jul 28 '23 11:07 bitwarden-bot

Logo Checkmarx One – Scan Summary & Details0da55a2a-e37e-423c-8fc8-6d9d177fb10f

No New Or Fixed Issues Found

bitwarden-bot avatar Jul 28 '23 11:07 bitwarden-bot

Fixes https://github.com/bitwarden/server/issues/648

zadjadr avatar Aug 21 '23 08:08 zadjadr

surprised this hasn't been fixed yet, my vault_log.ldf file is 2.3GB which sure doesn't seem like a lot in this day and age but it is running on a low end VPS with limited storage so in the end I have to regularly delete backup files to not run out of space

pocoloko avatar Jun 19 '24 08:06 pocoloko