Solved

database backup in CF

Posted on 2006-11-07
6
358 Views
Last Modified: 2013-12-24
Hi,

i have a MS SQL database with all my products in, i wanted to know if it was possible in coldfusion to create a system where i could click a button and download a a sql file of the database as a backup to my desktop?

this sql file has to be one which could be used to restore my database if needed.


thanks
0
Comment
Question by:pigmentarts
  • 3
  • 2
6 Comments
 
LVL 7

Accepted Solution

by:
bwasyliuk earned 500 total points
Comment Utility
The backup process (when done through Enterprise Manager as an example) is just a set of SQL commands run against the database.  I used SQL Profiler to "watch" what enterprise manager is doing when you run a backup - and you could easily do the same.

It appears as though something like the following will create the backup file:

<cfquery name="back_it_up" datasource="#session.mydsn#">
  BACKUP DATABASE [your_DB_name_here] TO  DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\whateveryouwantyourfiletobe.bak' WITH  INIT ,  NOUNLOAD ,  NAME = N'My backup',  NOSKIP ,  STATS = 10,  NOFORMAT
</cfquery>

Assuming you can then do some CFFile actions on the file that is created above (file permissions etc) - then you should be able to write the script to download it.

Let me know if you want me to expand on this...

Ben
www.scheduleforce.net
0
 
LVL 12

Author Comment

by:pigmentarts
Comment Utility
thanks Ben, will look at this in the morining
0
 
LVL 12

Author Comment

by:pigmentarts
Comment Utility
i get this error....

 Error Executing Database Query.
[Macromedia][SQLServer JDBC Driver][SQLServer]BACKUP DATABASE permission denied in database 'testdatabase'.

but i do use the password like so...


<cfquery datasource="#dbSource#" username="#dbUsername#" password="#dbPassword#" name="backup">
  BACKUP DATABASE #dbSource# TO  DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\whateveryouwantyourfiletobe.bak' WITH  INIT ,  NOUNLOAD ,  NAME = N'My backup',  NOSKIP ,  STATS = 10,  NOFORMAT
</cfquery>      

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 7

Expert Comment

by:bwasyliuk
Comment Utility
This is a permissions issue with the username you are using to connect.  Nothing wrong with the code as such - so I would go into the security are of enterprise manager and take a look at what the user is setup as.

There are a number of flags that can be set for the users access/privilages to the db, from memory I cant remember the exact name, but there is one that does say "backup" something in it.

Try turning that on for the user you are working with, and see what happens.
0
 
LVL 12

Author Comment

by:pigmentarts
Comment Utility
thanks for your help! :)
0
 
LVL 6

Expert Comment

by:lightspeedvt
Comment Utility
Hello, i have the same question. But in my case the SQL server is not the same machine the CF running. It is remote. I'm trying this

<cfquery name="back_it_up" datasource="#request.datasource#">
BACKUP DATABASE bgtaweb6 TO DISK = '\\10.2.9.89\dbbackup\bgtaweb6.bak' WITH  INIT ,  NOUNLOAD ,  NAME = 'bgtaweb6',  NOSKIP ,  STATS = 10,  NOFORMAT
</cfquery>

But get this error
[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Cannot open backup device '\\10.2.9.89\dbbackup\bgtaweb6.bak'. Device error or device off-line. See the SQL Server error log for more details.

Could u pls help?
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Firewall Speed Issue 6 60
Internal DNS Zone Issue 13 51
Apache SSL and mod_rewrite not working 8 103
listing all functions in JavaScript 19 96
A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now