Solved

database backup in CF

Posted on 2006-11-07
6
373 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 7

Accepted Solution

by:
bwasyliuk earned 500 total points
ID: 17890870
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
ID: 17891222
thanks Ben, will look at this in the morining
0
 
LVL 12

Author Comment

by:pigmentarts
ID: 17896525
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
Flexible connectivity for any environment

The KE6900 series can extend and deploy computers with high definition displays across multiple stations in a variety of applications that suit any environment. Expand computer use to stations across multiple rooms with dynamic access.

 
LVL 7

Expert Comment

by:bwasyliuk
ID: 17898991
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
ID: 17899024
thanks for your help! :)
0
 
LVL 6

Expert Comment

by:lightspeedvt
ID: 21363085
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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

688 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