using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using System.Configuration;
using System.Data;
using System.Web.UI.HtmlControls;
using System.Web.Services;
using System.Text.RegularExpressions;

using System.Net;
using System.Collections;
using System.IO;
using System.Diagnostics;
using System.Collections.Generic;
using System.Web.Script.Services;
using Newtonsoft.Json;
public partial class module_masterjqury : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    [WebMethod]
    public static string backup()
    {
        string data = "";
        var d = DateTime.UtcNow.ToString("dd-MM-yyyy");
        var dirFullPath = HttpContext.Current.Server.MapPath("~/Backup/");
        string[] files;
        int numfiles;
        files = System.IO.Directory.GetFiles(dirFullPath);
        numfiles = files.Length;
        numfiles = numfiles + 1;
        string fileName1 = "Backup" + d + ".sql";
        string fileName = HttpContext.Current.Server.MapPath("~/Backup/") + fileName1;
        if (File.Exists(fileName))
        {
            File.Delete(fileName);
        }

        // Create a new file     
        using (FileStream fs = new FileStream(fileName, FileMode.Create))
        {
            fs.Close();



            using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString))
            {
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    using (MySqlBackup mb = new MySqlBackup(cmd))
                    {

                        cmd.Connection = con;
                        con.Open();
                        mb.ExportToFile(fileName);
                        con.Close();

                    }

                }
            }

        }
        return data;
    }
}