v0.0.8.9.3.4-beta
"db-vcs-ci" is a tool that automatically backups your database along your code, and inserts the backups to your commits, so you could source-control the backups of your database.
The default sql commands that come with "db-vcs-ci" extract / import a MSSQL database that uses SQL Server Management Studio (SSMS) and is run on Windows Server 2012 R2, but you can edit the sql commands to be any commands, for any database.
Merge this repository to a new folder called db-vcs-ci-client
at the root folder of your project:
git subtree add -P db-vcs-ci-client https://github.com/taljacob2/db-vcs-ci-client master --squash
Open powershell.exe and run:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass; db-vcs-ci-client/setup-for-windows.ps1
Open terminal and run:
./db-vcs-ci-client/setup-for-linux.sh
"db-vcs-ci" would backup your database automatically, when you make the git commit
command, and will insert the .bak
file to your commit.
Right after you commit your files via
git commit
"db-vcs-ci" executes a sql command on the server which the database is located on, that:
- Exports a backup
.bak
file of the database. - Downloads it from the server to your actual working-directory.
- And finally adds it to your commit.
So the database you are working on will be automatically backed-up to your source-code.
The default settings set the .bak
file to be placed at db-vcs-ci-client/db-vcs-ci/db.bak.
You can change the settings here.
The backup runs as a "pre-commit" hook.
Means, after you run git commit
, but before the actual commit process.
In case you don't want to backup the database in your commit, then you can skip the backuping process with:
git commit --no-verify
If you want to update the backup of the database on a new commit, and not include changes from source-code, you can call the backup process with an empty commit, like so:
git commit --allow-empty
Also, "db-vcs-ci" is able to use a backup .bak
file you already own, to import it staight into the server's database.
This can be done by running:
git import-db
You can change the settings of "db-vcs-ci" in the db-vcs-ci-settings.sh
file.
In case you already have an existing version of "db-vcs-ci-client" and you want to update to the newest version available,
you can merge the newest version of this repository to your existing db-vcs-ci-client
folder:
git subtree pull -P db-vcs-ci-client https://github.com/taljacob2/db-vcs-ci-client master --squash
AFter exporting, I am receiving the following output:
Msg 916, Level 14, State 1, Server WBX-VPS-P42\SQLEXPRESS, Line 1
The server principal "IIS APPPOOL\dbvcsci.example.com" is not able to access the database "KlilDBCore" under the current security context.
Msg 3013, Level 16, State 1, Server WBX-VPS-P42\SQLEXPRESS, Line 1
BACKUP DATABASE is terminating abnormally.
The IIS app that runs the "sqlcmd" command doesn't have credentials for managing the database. You should create a new "SQL Server Authentication" user in your SSMS, so your IIS app could use it to export the database through "sqlcmd".
- Follow this video for doing so.
- Navigate to
db-vcs-ci/export-db/cmd-command-for-windows-server.bat
and add the credentials you have made to the "sqlcmd" command, like the following template:For example:-U USERNAME -P PASSWORD
del /f %3\%4 >nul 2>&1 sqlcmd -S %1 -U db-vcs-ci -P pass123456 -Q "BACKUP DATABASE [%2] TO DISK = '%3\%4'"