vanamp's avatar

Run a sql server backup

I have a simple app that deletes a bunch of data based on a date selection. I would like to add the ability to run a backup before deleting any data. I have tried a number of things with no luck.

I am using IIS 7 and SQL server 2008 R2

I am currently trying this but have tried many other ways:

 DB::unprepared(DB::raw("BACKUP DATABASE MyDB TO DISK = 'D:\backup.bak'"));

If I run this via MS SQL server management studio it works great. It fails when I try to run it from my laravel app.

The SQL error logs tell me to look at my apps log form more information. I also see a schannel error that seems to be associated with ssl certificate but I am unsure if this is related as I am using http:

I am getting NULL back from sqlsrv_erros() but am new to laravel and am unsure if this works as I expect it to.

Any help is appreciated.

0 likes
2 replies
vanamp's avatar

That is the blog post that got me started. I am not following it 100% as I do not want to set my recovery mode to Full, but I do not think that would prevent me from making a backup. My app fails with no errors after about 90 seconds. The same query in MSSQL management studio creates a backup as expected.

The backup takes a few minutes is there anything special I need to do for a query that takes this long? I tried adjusting every timeout setting I could find related to IIS. I am currently experimenting with write permissions to make sure that is not causing the problems.

Please or to participate in this conversation.