Пример #1
0
        private void FrmMain_Load(object sender, EventArgs e)
        {
            if (backupSetting == null)
            {
                if (File.Exists(Program.ConfigFile))
                {
                    backupSetting = JsonHelp.FromJson <BackupSetting>(File.ReadAllText(Program.ConfigFile));
                }
                else
                {
                    BackupSetting defaultSetting = new BackupSetting();
                    defaultSetting.SvnAdminCmd    = new FileInfo(@"C:\Program Files\TortoiseSVN\bin\svnadmin.exe");
                    defaultSetting.BackupHome     = new DirectoryInfo(@"D:\backup\svn");
                    defaultSetting.RepositoryHome = new DirectoryInfo(@"D:\repositories");
                    defaultSetting.BackupTime     = "01:00";
                    defaultSetting.BackupRetain   = 7;
                    backupSetting = defaultSetting;
                    // 保存配置文件
                    File.WriteAllText(Program.ConfigFile, JsonHelp.ToJson(backupSetting));
                }
            }

            int index = backupSetting.BackupTime.IndexOf(":");

            settingHour   = Convert.ToInt32(backupSetting.BackupTime.Substring(0, index));
            settingMinute = Convert.ToInt32(backupSetting.BackupTime.Substring(index + 1));

            // Hook up the Elapsed event for the timer.
            timer1.Elapsed  += OnTimedEvent;
            timer1.AutoReset = true;

            taskIsRuning = true;
            SetButtonEnabled();
        }
Пример #2
0
        private string ExeBackup(BackupSetting setting, bool isTask)
        {
            StringBuilder output = new StringBuilder();

            var p = new Process();

            p.StartInfo.FileName        = setting.SvnAdminCmd.FullName;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.CreateNoWindow  = true;
            //
            string backupPath;

            if (isTask)
            {
                backupPath = Path.Combine(setting.BackupHome.FullName, DateTime.Now.ToString("yyyyMMdd"));
            }
            else
            {
                backupPath = Path.Combine(setting.BackupHome.FullName, DateTime.Now.ToString("yyyyMMddHHmmss"));
            }

            var backupDir = new DirectoryInfo(backupPath);

            if (!backupDir.Exists)
            {
                backupDir.Create();
            }

            //
            foreach (var item in setting.RepositoryHome.GetDirectories())
            {
                if (item.GetFiles("format") != null && item.GetFiles("README.txt") != null)
                {
                    var repoFolder       = item;
                    var repoBackupFolder = new DirectoryInfo(Path.Combine(backupDir.FullName, item.Name));
                    repoBackupFolder.Create();

                    p.StartInfo.Arguments = " hotcopy " + repoFolder.FullName + " " + repoBackupFolder.FullName;
                    try
                    {
                        p.Start();
                        p.WaitForExit();
                        p.Close();
                        output.AppendFormat("backup repository {0} to {1}", repoFolder.FullName, repoBackupFolder.FullName);
                    }
                    catch (Exception e)
                    {
                        output.Append(e.Message);
                    }
                }
                output.AppendLine("");
            }

            DeleteExpiredDir(setting);

            return(output.ToString());
        }
Пример #3
0
        private void DeleteExpiredDir(BackupSetting setting)
        {
            var folders = setting.BackupHome.GetDirectories();

            if (folders.Length > setting.BackupRetain)
            {
                SortAsFolderCreationTime(ref folders);
                for (int i = setting.BackupRetain, c = folders.Length; i < c; i++)
                {
                    DeleteDirectory(folders[i].FullName);
                }
            }
        }
Пример #4
0
        private void btnSetting_Click(object sender, EventArgs e)
        {
            var frmSetting = new FrmSetting();

            frmSetting.Setting = backupSetting;
            frmSetting.ShowDialog(this);
            this.backupSetting = frmSetting.Setting;

            // 修改计划任务的时间
            int index = backupSetting.BackupTime.IndexOf(":");

            settingHour   = Convert.ToInt32(backupSetting.BackupTime.Substring(0, index));
            settingMinute = Convert.ToInt32(backupSetting.BackupTime.Substring(index + 1));

            // 保存配置文件
            File.WriteAllText(Program.ConfigFile, JsonHelp.ToJson(backupSetting));
        }
Пример #5
0
        private void btnSetting_Click(object sender, EventArgs e)
        {
            var frmSetting = new FrmSetting();
            frmSetting.Setting = backupSetting;
            frmSetting.ShowDialog(this);
            this.backupSetting = frmSetting.Setting;

            // 修改计划任务的时间
            int index = backupSetting.BackupTime.IndexOf(":");
            settingHour = Convert.ToInt32(backupSetting.BackupTime.Substring(0, index));
            settingMinute = Convert.ToInt32(backupSetting.BackupTime.Substring(index + 1));

            // 保存配置文件
            File.WriteAllText(Program.ConfigFile, JsonHelp.ToJson(backupSetting));
        }
Пример #6
0
        private void FrmMain_Load(object sender, EventArgs e)
        {
            if (backupSetting == null)
            {
                if (File.Exists(Program.ConfigFile))
                {
                    backupSetting = JsonHelp.FromJson<BackupSetting>(File.ReadAllText(Program.ConfigFile));
                }
                else
                {
                    BackupSetting defaultSetting = new BackupSetting();
                    defaultSetting.SvnAdminCmd = new FileInfo(@"C:\Program Files\TortoiseSVN\bin\svnadmin.exe");
                    defaultSetting.BackupHome = new DirectoryInfo(@"D:\backup\svn");
                    defaultSetting.RepositoryHome = new DirectoryInfo(@"D:\repositories");
                    defaultSetting.BackupTime = "01:00";
                    defaultSetting.BackupRetain = 7;
                    backupSetting = defaultSetting;
                    // 保存配置文件
                    File.WriteAllText(Program.ConfigFile, JsonHelp.ToJson(backupSetting));
                }
            }

            int index = backupSetting.BackupTime.IndexOf(":");
            settingHour = Convert.ToInt32(backupSetting.BackupTime.Substring(0, index));
            settingMinute = Convert.ToInt32(backupSetting.BackupTime.Substring(index + 1));

            // Hook up the Elapsed event for the timer.
            timer1.Elapsed += OnTimedEvent;
            timer1.AutoReset = true;

            taskIsRuning = true;
            SetButtonEnabled();
        }
Пример #7
0
        private string ExeBackup(BackupSetting setting, bool isTask)
        {
            StringBuilder output = new StringBuilder();

            var p = new Process();
            p.StartInfo.FileName = setting.SvnAdminCmd.FullName;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.CreateNoWindow = true;
            //
            string backupPath;
            if (isTask)
            {
                backupPath = Path.Combine(setting.BackupHome.FullName, DateTime.Now.ToString("yyyyMMdd"));
            }
            else
            {
                backupPath = Path.Combine(setting.BackupHome.FullName, DateTime.Now.ToString("yyyyMMddHHmmss"));
            }

            var backupDir = new DirectoryInfo(backupPath);
            if (!backupDir.Exists)
            {
                backupDir.Create();
            }

            //
            foreach (var item in setting.RepositoryHome.GetDirectories())
            {
                if (item.GetFiles("format") != null && item.GetFiles("README.txt") != null)
                {
                    var repoFolder = item;
                    var repoBackupFolder = new DirectoryInfo(Path.Combine(backupDir.FullName, item.Name));
                    repoBackupFolder.Create();

                    p.StartInfo.Arguments = " hotcopy " + repoFolder.FullName + " " + repoBackupFolder.FullName;
                    try
                    {
                        p.Start();
                        p.WaitForExit();
                        p.Close();
                        output.AppendFormat("backup repository {0} to {1}", repoFolder.FullName, repoBackupFolder.FullName);
                    }
                    catch (Exception e)
                    {
                        output.Append(e.Message);
                    }
                }
                output.AppendLine("");
            }

            DeleteExpiredDir(setting);

            return output.ToString();
        }
Пример #8
0
 private void DeleteExpiredDir(BackupSetting setting)
 {
     var folders = setting.BackupHome.GetDirectories();
     if (folders.Length > setting.BackupRetain)
     {
         SortAsFolderCreationTime(ref folders);
         for (int i = setting.BackupRetain, c = folders.Length; i < c; i++)
         {
             DeleteDirectory(folders[i].FullName);
         }
     }
 }