Exemple #1
0
        public void DoWork(object data)
        {
            try
            {
                BuckupOptions options = data as BuckupOptions;
                lock (rar)
                {
                    while (!rar.HasExited)
                    {
                        try
                        {
                            Thread.Sleep(options.StepDuration);
                            foreach (ProcessThread thread in rar.Threads)
                            {
                                Thread_Suspend(Thread_GetHandle(thread.Id));
                            }

                            Thread.Sleep(options.Sleep);
                            foreach (ProcessThread thread in rar.Threads)
                            {
                                Thread_Resume(Thread_GetHandle(thread.Id));
                            }
                        }
                        catch { }
                    }
                }
            }
            catch { }
        }
Exemple #2
0
        private void DoRAR(BuckupOptions options)
        {
            rar.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            rar.StartInfo.FileName    = string.Format("{0}bin\\rar.exe", options.BuckupFolder);

            rar.StartInfo.Arguments = options.GetCommandLine();

            if (!string.IsNullOrEmpty(rar.StartInfo.Arguments))
            {
                rar.Start();
                if (options.StepDuration > 0 || options.Sleep > 0)
                {
                    ThreadPool.QueueUserWorkItem(new WaitCallback(DoWork), options);
                }

                Thread.Sleep(500);
                rar.WaitForExit();

                if (options.IncludeDatabase)
                {
                    File.Delete(options.DBBakFile);
                }
            }
            else
            {
                return;
            }
        }
    private DataTable GetFiles()
    {
        BuckupOptions option = new BuckupOptions
        {
            BuckupFolder = HttpContext.Current.Request.PhysicalApplicationPath + "backup\\",
            DestinationFolder = HttpContext.Current.Request.PhysicalApplicationPath,
            ConnectionString = WebConfigurationManager.ConnectionStrings["BXConnectionString"].ConnectionString
        };
        chbIncludeDataBase.Text = string.Format("({0})", BuckupMeneger.GetDBSize(option));

        DataTable result = new DataTable();

        result.Columns.Add("Name", typeof(string));
        result.Columns.Add("FullName", typeof(string));
        result.Columns.Add("Size", typeof(int));
        result.Columns.Add("Created", typeof(DateTime));
        result.Columns.Add("ID", typeof(int));
        int i = 0;
        foreach (var file in BuckupMeneger.GetFiles(option))
        {
            DataRow dr = result.NewRow();
            dr["Name"] = file.Name;
            dr["FullName"] = string.Format("{0}", file.FullName);
            dr["Size"] = file.Length / 1024 / 1024;
            dr["Created"] = file.CreationTime;
            dr["ID"] = i;
            i++;
            result.Rows.Add(dr);
        }

        return result;
    }
Exemple #4
0
 public static FileInfo[] GetFiles(BuckupOptions options)
 {
     DirectoryInfo dir = new DirectoryInfo(options.BuckupFolder);
     //if (dir.Parent != null)
     //    dir = dir.Parent;
     return dir.GetFiles("*.rar", SearchOption.TopDirectoryOnly);
 }
Exemple #5
0
        public static FileInfo[] GetFiles(BuckupOptions options)
        {
            DirectoryInfo dir = new DirectoryInfo(options.BuckupFolder);

            //if (dir.Parent != null)
            //    dir = dir.Parent;
            return(dir.GetFiles("*.rar", SearchOption.TopDirectoryOnly));
        }
Exemple #6
0
        public bool Execute(BXSchedulerAgent agent, DataTypes.BXParamsBag <object> parameters)
        {
            BuckupOptions option = FromBase64(parameters["BackupOptions"].ToString());

            BuckupMeneger meneger = new BuckupMeneger();

            meneger.Buckup(option);

            return(true);
        }
Exemple #7
0
        public static object GetDBSize(BuckupOptions options)
        {
            SqlCommand cmd = new SqlCommand(options.GetDBSizeSQLCommand(), new SqlConnection(options.ConnectionString));

            cmd.Connection.Open();
            object size = cmd.ExecuteScalar();

            cmd.Connection.Close();
            return(size);
        }
Exemple #8
0
 private void DoDBBuckup(BuckupOptions options)
 {
     if (options.IncludeDatabase)
     {
         SqlCommand cmd = new SqlCommand(options.GetBackupSQLCommand(), new SqlConnection(options.ConnectionString));
         cmd.Connection.Open();
         cmd.ExecuteNonQuery();
         cmd.Connection.Close();
     }
     return;
 }
Exemple #9
0
        private void DoRAR(BuckupOptions options)
        {

            rar.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            rar.StartInfo.FileName = string.Format("{0}bin\\rar.exe", options.BuckupFolder);

            rar.StartInfo.Arguments = options.GetCommandLine();

            if (!string.IsNullOrEmpty(rar.StartInfo.Arguments))
            {
                rar.Start();
                if (options.StepDuration > 0 || options.Sleep > 0)
                    ThreadPool.QueueUserWorkItem(new WaitCallback(DoWork), options);

                Thread.Sleep(500);
                rar.WaitForExit();

                if (options.IncludeDatabase)
                    File.Delete(options.DBBakFile);
            }
            else
                return;
        }
Exemple #10
0
        public void Buckup(BuckupOptions options)
        {
            DoDBBuckup(options);

            DoRAR(options);
        }
    protected void btnArchive_Click(object sender, EventArgs e)
    {
        long excludeFileSize = 0;
        long.TryParse(txbExcludeFileSize.Text, out excludeFileSize);

        DirectoryInfo dir = new DirectoryInfo(HttpContext.Current.Request.PhysicalApplicationPath + "backup\\");
        if (!dir.Exists)
            dir.Create();

        int stepDuration = 0;
        int.TryParse(txbStepDuration.Text, out stepDuration);

        int sleep = 0;
        int.TryParse(txbSleep.Text, out sleep);


        BuckupOptions option = new BuckupOptions
        {
            BuckupFolder = HttpContext.Current.Request.PhysicalApplicationPath,
            DestinationFolder = dir.FullName,
            ExcludeFiles = (@"*\bitrix\cache;*\backup;" + (!chbArchivePublicPart.Checked? @"*\bitrix;":string.Empty) + txbExcludeFiles.Text).Split(new char[] {';'}, StringSplitOptions.RemoveEmptyEntries),
            IncludeCorePart = chbArchiveCore.Checked,
            ExcludeFileSize = excludeFileSize*1024,
            ExcludeStandardTypesCompressing = chbExcludeStandardTypesCompressing.Checked,
            DisableCompresing = chbDisableCompressing.Checked,
            CheckPackage = chbCheckPackage.Checked,
            IncludeDatabase = chbIncludeDataBase.Checked,
            StepDuration = stepDuration * 1000,
            Sleep = sleep * 1000,
            ConnectionString = WebConfigurationManager.ConnectionStrings["BXConnectionString"].ConnectionString
        };

        BuckupMeneger.Buckup(option);
        dataSource = GetFiles();
        BackupsGridView.MarkAsChanged();
        //FileListDataBind();
    }
Exemple #12
0
 private void DoDBBuckup(BuckupOptions options)
 {
     if (options.IncludeDatabase)
     {
         SqlCommand cmd = new SqlCommand(options.GetBackupSQLCommand(), new SqlConnection(options.ConnectionString));
         cmd.Connection.Open();
         cmd.ExecuteNonQuery();
         cmd.Connection.Close();
     }
     return;
 }
Exemple #13
0
        public void Buckup(BuckupOptions options)
        {
            DoDBBuckup(options);

            DoRAR(options);
        }
Exemple #14
0
 public static object GetDBSize(BuckupOptions options)
 {
     SqlCommand cmd = new SqlCommand(options.GetDBSizeSQLCommand(), new SqlConnection(options.ConnectionString));
     cmd.Connection.Open();
     object size = cmd.ExecuteScalar();
     cmd.Connection.Close();
     return size;
 }