ASP.Net Backup and Restore Database Tool

Script version:2
Language:ASP.Net
Rating:
6.4 (11 votes cast)
Category:No Category
Description:This script is a slight extension to Sheo Narayan's excellent <b>Backup and Restore Database in ASP.Net</b>(http://www.dotnetfunda.com/articles/article489-backup-and-restore-database-in-aspnet-.aspx) code. In the code below, I've added some tweaks to the xml file to include the database schema, and also an xml file download and upload facility so you can save your backups and store them somewhere else, and then you can upload any previously downloaded backup in case the most recent backup set has corrupted or missing data.

This code is written in c# and targets SQL server, but in theory it should work fine when targeting mySQL or any other database type (I haven't tested it with other database types though)


Instructions:

Create two files, one called dbbackup.aspx and dbbackup.aspx.cs. Copy the code from the script above into each of the files.

Make sure you enter your connection string in the top of the .cs file (replace the bit in the code which says [ENTER YOUR CONNECTION STRING HERE]. You can also change the backupfolder to target another folder. Your backup folder must exist within your web directory so that you can download the files once you have created them (and you must make sure that the server has read/write permission in this folder).
For extra security, you can create a secret folder to store them in, or change the filenames according to a secret key if desired.

Many thanks go to Sheo Narayan, without whom this code would never have been written.

Probably.
Code:




Comments



YAMA
31 July 2011 17:38:12
Sir I'm a new user for MSSQL database, so i did a backup of my database folder AAA.bak, what i would like to do is have an aspx page code contain sample code for restoring the .bak folder to .mdf & .ldf folders, after searching, i found below sample code for restoring but i don't know how to put it in aspx page USE master GO -- First determine the number and names of the files in the backup. -- MyNwind_2 is the name of the backup device. RESTORE FILELISTONLY FROM MyNwind_2 -- Restore the files for MyNwind2_Test. RESTORE DATABASE MyNwind2_Test FROM MyNwind_2 WITH RECOVERY, MOVE 'MyNwind2_data' TO 'C:\MyData\MyNwind2_Test_data.mdf', MOVE 'MyNwind2_log' TO 'C:\MyData\MyNwind2_Test_log.ldf' GO regards yama




Myke Black
www.mykeblack.com
20 October 2011 11:48:34
The best option there is to create a stored procedure then call that from you .aspx file. This page will give you a few pointers: http://forums.asp.net/t/1576299.aspx/1


Name: *
Email: (not shown on website)
Website:
Rate this script:
1 2 3 4 5 6 7 8 9 10
worse better
Comment: *
CAPTCHA Image
Change Image
Write the characters in the image above


* = required field

Related Scripts:

Pass null parameter in to parameterized query

Tags

[ backup ] [ restore ] [ database ] [ c# ] [ asp.net ] [View tag cloud]

Back to main scripts page








Tag Cloud    Submit a script


Latest Scripts Added

jQuery image swap on mouseover (jQuery)
04 January 2012
This simple bit of code allows you to quickly create image rollovers. The code was modified from a version by Sam Colletts on http://webdevel.blogspot.com/2008/04/rollover-images-with-jquery.html ...

replace XML characters in a string using ASP.Net (ASP.Net)
12 December 2011
Sometimes you need to insert a string into an xml document. Before doing this, you need to ensure that your string does not contain any special xml characters. It is possible to use a CDATA section ...

How to remove title tag in ASP.Net (ASP.Net)
14 October 2011
This is not really a script, but a little trick that you can use to remove the title tag in ASP.net. In ASP.net, when the head tag is rendered, the title tag is automatically added. One of the real ...

ASP sort numerical array (ASP)
12 September 2011
This code is similar to the sort array script which sorts an array alphabetical, however it also sorts arrays based on numberical ordering, for example: dim numbers(4) numbers(0) = ...

Force file download in ASP.Net / c# (ASP.Net)
02 September 2011
this script allows you to force browsers to display a file save dialogue for any file type. It contains a string of allowed file types so users cannot change the querystring to downoad your ...