Solved

database backup in CF

Posted on 2006-11-07
6
372 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
Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 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