Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL Server BACKUP and RESTORE statements broken #1711

Closed
andrey-poltavskiy opened this issue Jul 16, 2017 · 5 comments
Closed

SQL Server BACKUP and RESTORE statements broken #1711

andrey-poltavskiy opened this issue Jul 16, 2017 · 5 comments

Comments

@andrey-poltavskiy
Copy link

What version of Flyway are you using?

Flyway 4.2.0 by Boxfuse

Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin, SBT plugin, ANT tasks)

Command-line

What database are you using (type & version)?

Microsoft SQL Server 2014 - 12.0.2269.0 (X64)
Jun 10 2015 03:35:45
Copyright (c) Microsoft Corporation
Express Edition (64-bit) on Windows NT 6.3 (Build 9600: ) (Hypervisor)

What operating system are you using?

Microsoft Windows [Version 10.0.10586]

What did you do?

In sql file:
BACKUP DATABASE [POS_TEST] TO DISK = N'e:\Shared\Backup\OLCHA$SQLEXPRESS\POS_TEST\FULL\OLCHA$SQLEXPRESS_POS_TEST_FULL_20170716_212844.bak' WITH CHECKSUM, NO_COMPRESSION

After execute in Flyway:
Database: jdbc:jtds:sqlserver://192.168.20.22/POS_TEST;instance=SQLEXPRESS (Microsoft SQL Server 12.0)
Successfully validated 2 migrations (execution time 00:00.096s)
SQLServer does not support setting the schema for the current session. Default schema NOT changed to dbo
Current version of schema [dbo]: 1
Migrating schema [dbo] with repeatable migration 1600 ANGUS
ERROR: Migration of schema [dbo] with repeatable migration 1600 ANGUS failed! Changes successfully rolled back.
ERROR:
Migration R__1600_ANGUS.sql failed

SQL State : S1000
Error Code : 3013
Message : BACKUP DATABASE is terminating abnormally.
Location : C:/Flyway/POS/sql/R__1600_ANGUS.sql (C:\Flyway\POS\sql\R__1600_ANGUS.sql)
Line : 5
Statement : BACKUP DATABASE [POS_TEST] TO DISK = N'e:\Shared\Backup\OLCHA$SQLEXPRESS\POS_TEST\FULL\OLCHA$SQLEXPRESS_POS_TEST_FULL_20170716_212844.bak' WITH CHECKSUM, NO_COMPRESSION

No problem if exeute in Management Studio

What did you expect to see?
What did you see instead?
@axelfontaine
Copy link
Contributor

Can this statement be executed within a transaction? Could this be the issue?

@axelfontaine
Copy link
Contributor

I investigated and BACKUP and RESTORE are indeed not able to run inside a transaction. Solving this would probably require a good answer to https://stackoverflow.com/questions/47497351/sql-server-how-to-lock-and-unlock-a-table-exclusively-outside-of-a-transaction

@axelfontaine axelfontaine changed the title Backup SQL Server BACKUP and RESTORE statements should be run outside a transaction Nov 26, 2017
@axelfontaine axelfontaine changed the title SQL Server BACKUP and RESTORE statements should be run outside a transaction SQL Server BACKUP and RESTORE statements broken Nov 26, 2017
@axelfontaine axelfontaine modified the milestones: Someday-Maybe, Flyway 5.0.0 Nov 26, 2017
@axelfontaine
Copy link
Contributor

OK, I did find a way to make this work after all. Fixed.

axelfontaine pushed a commit to flyway/flywaydb.org that referenced this issue Nov 26, 2017
@jbryu
Copy link

jbryu commented Jan 25, 2018

axelfontaine, How did you fix the issue? I tried to run the following command, but I couldn't execute it inside a transaction.

USE [TARGET_DB];
GO
BACKUP DATABASE [TARGET_DB]
TO DISK = 'D:\Backups[TARGET_DB].bak'
WITH FORMAT,
MEDIANAME = '[TARGET_DB]_Backup',
NAME = 'Full Backup of [TARGET_DB]';
GO

@axelfontaine
Copy link
Contributor

axelfontaine commented Jan 25, 2018

@jbryu Are you having trouble running that statement with Flyway? If so, please open a new issue with all necessary details to reproduce.

dohrayme pushed a commit to dohrayme/flyway that referenced this issue Feb 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants