Skip to content

Incremental Backup of Database

Kasthu Guna

Asked Jan 6, 2016, 11:30 PM EST3 answers
Share
LinkedInX
Hay!
 
I need to write a C# based Incremental backup application. From that application only modified database files should be backup from our Database (SQL server Database ) .
 
Please any one suggest a way to do this. And it is good , if you suggest any tools also.
 
Thankyou 

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Use the Below code in .Net in Windows Apps. Create a exe file.
     
    and use in Windows Task Sheduler to execute that exe file. 
     
     
    PowerShell
    using Microsoft.VisualBasic;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Diagnostics;
    using System.Data.SqlClient;
    
    public class Form1
    {
    	SqlConnection con;
    	SqlConnection con1;
    	SqlCommand cmd;
    	SqlDataReader dread;
    	private void Form1_Load(object sender, System.EventArgs e)
    	{
    		connection();
    		blank("backup");
    	}
    	public void blank(string str)
    	{
    		string Lsm_Date = null;
    		Lsm_Date = Convert.ToDateTime(Today).ToString("dd-MMM-yyyy");
    		if (str == "backup") {
    			Timer1.Enabled = true;
    			ProgressBar1.Visible = true;
    			string s = null;
    			s = "D:\DataBackup\" + Lsm_Date + ".bak";
    			query("backup database <DatabaseName> to disk='" + s + "'");
    		}
    	}
    	private void Timer1_Tick(System.Object sender, System.EventArgs e)
    	{
    		if (ProgressBar1.Value == 100) {
    			Timer1.Enabled = false;
    			ProgressBar1.Visible = false;
    			System.Environment.Exit(0);
    		} else {
    			ProgressBar1.Value = ProgressBar1.Value + 5;
    		}
    	}
    	public void query(string que)
    	{
    		 // ERROR: Not supported in C#: OnErrorStatement
    
    		cmd = new SqlCommand(que, con);
    		cmd.ExecuteNonQuery();
    	}
    	public void connection()
    	{
    		con = new SqlConnection("Data Source=.;Database=Master;integrated security=SSPI;");
    		con.Open();
    		cmd = new SqlCommand("select * from sysdatabases", con);
    		dread = cmd.ExecuteReader;
    		while (dread.Read) {
    		}
    		dread.Close();
    	}
    	public Form1()
    	{
    		Load += Form1_Load;
    	}
    }
     
    0
  • 0
    Thank you so much ! Is any possibilities to use any existing API s to backup DB files. (Alpha VSS).
    And some articles says , we can't make an incremental backup from SQL Server Db..Can you give me a clarification :) 
    0
  • 0
    Dear,
     
    Below is another code to take backup. Just Try this.
     
     
    VB.NET
    Dim sqlConnectionString As String = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DBNAME ;Data Source=.\SQLEXPRESS"
        Dim conn As New SqlConnection(sqlConnectionString)
        conn.Open()
    
        Dim cmd As New SqlCommand
        cmd.CommandType = CommandType.Text
        cmd.CommandText = "BACKUP DATABASE DBNAME TO DISK='C:\location.BAK'"
        cmd.Connection = conn
        cmd.ExecuteNonQuery()
    0