Solved

database backup in CF

Posted on 2006-11-07
6
366 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

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…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

777 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