Exemplo n.º 1
0
        private static (int index, BackupFileType fileType) GetBackupType(ReadOnlySpan <char> name)
        {
            BackupFileType fileType = BackupFileType.None;
            int            index    = name.LastIndexOf("_LOG_", StringComparison.Ordinal);

            if (index != -1)
            {
                fileType = BackupFileType.LOG;
                index   += 5;
            }
            else
            {
                index = name.LastIndexOf("_DIFF_", StringComparison.Ordinal);
                if (index != -1)
                {
                    fileType = BackupFileType.DIFF;
                    index   += 6;
                }
                else
                {
                    index = name.LastIndexOf("_FULL_", StringComparison.Ordinal);
                    if (index != -1)
                    {
                        fileType = BackupFileType.FULL;
                        index   += 6;
                    }
                }
            }

            return(index, fileType);
        }
Exemplo n.º 2
0
        internal void Backup(string BackupFolderPath, BackupFileType bkFileType, string backupServer, string BackupServerPost, string backupServerID, string backupServerPassword)
        {
            try
            {
                //백업 경로 생성
                string DBName     = NpgConn.Database;
                string BackupPath = string.Format
                                    (
                    "{0}\\{1}_{2}{3}{4}{5}{6}.bk",
                    BackupFolderPath,
                    DBName,
                    DateTime.Now.Year.ToString().Substring(2, 2),
                    DateTime.Now.Month.ToString().PadLeft(2, '0'),
                    DateTime.Now.Day.ToString().PadLeft(2, '0'),
                    DateTime.Now.Hour.ToString().PadLeft(2, '0'),
                    DateTime.Now.Minute.ToString().PadLeft(2, '0')
                                    );


                //옵션 args작성
                StringBuilder sbArgs = new StringBuilder();
                //백업파일 형식
                switch (bkFileType)
                {
                case BackupFileType.PlainText: { sbArgs.Append(" -F p "); }
                break;

                case BackupFileType.Binary: { sbArgs.Append(" -F c "); }
                break;

                case BackupFileType.tar: { sbArgs.Append(" -F t "); }
                break;

                default:
                    break;
                }
                //출력 파일명
                sbArgs.Append(" -f ");
                sbArgs.Append(BackupPath);
                //데이터베이스 생성구문까지 백업
                sbArgs.Append(" -C ");
                //복구할 데이터베이스
                sbArgs.Append(" -d ");
                sbArgs.Append(NpgConn.Database);
                sbArgs.Append(" -U  ");
                sbArgs.Append(backupServerID);
                sbArgs.Append(" -W ");
                sbArgs.Append(backupServerPassword);
                sbArgs.Append(" -h ");
                sbArgs.Append(backupServer);
                sbArgs.Append(" -p ");
                sbArgs.Append(BackupServerPost);
                new FileExecuter().Exec("pg_dump.exe", sbArgs.ToString());
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 3
0
        public override void OnRestoreFile(ParcelFileDescriptor data, long size, File destination, BackupFileType type, long mode, long mtime)
        {
            System.Diagnostics.Debug.WriteLine("OnRestore initiated", "BackUp");

            base.OnRestoreFile(data, size, destination, type, mode, mtime);
        }
Exemplo n.º 4
0
        internal static void Restore(string DBFilePath, string DBName, string BackupFilePath, BackupFileType bkFileType, string DbID, string DbPassword)
        {
            //db커낵션 확인후 커넥션 끊고 기존db파일 이름 바꿈
            try
            {
                //원본 DB파일 이름 변경(원본파일 유지 해야 되니까)
                if (File.Exists(DBFilePath))
                {
                    string dbFolder  = DBFilePath.Substring(DBFilePath.LastIndexOf("\\") - 1);
                    string oldDbPath = string.Format
                                       (
                        "{0}\\{1}_{2}{3}{4}{5}{6}.OldDB",
                        dbFolder,
                        DBName,
                        DateTime.Now.Year.ToString().Substring(2, 2),
                        DateTime.Now.Month.ToString().PadLeft(2, '0'),
                        DateTime.Now.Day.ToString().PadLeft(2, '0'),
                        DateTime.Now.Hour.ToString().PadLeft(2, '0'),
                        DateTime.Now.Minute.ToString().PadLeft(2, '0')
                                       );
                    File.Move(DBFilePath, oldDbPath);
                }


                if (bkFileType == BackupFileType.PlainText)
                {
                    new FileExecuter().Exec("psql.exe", string.Format("{0} < {1}", DBName, BackupFilePath));
                }
                else
                {
                    new FileExecuter().Exec("psql.exe", string.Format("{0} < {1}", DBName, BackupFilePath));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 5
0
        internal void Backup(string BackupFolderPath,BackupFileType bkFileType,string backupServer,string BackupServerPost,string backupServerID,string backupServerPassword)
        {
            try
            {
                //백업 경로 생성
                string DBName = NpgConn.Database;
                string BackupPath = string.Format
                (
                "{0}\\{1}_{2}{3}{4}{5}{6}.bk",
                BackupFolderPath,
                DBName,
                DateTime.Now.Year.ToString().Substring(2,2),
                DateTime.Now.Month.ToString().PadLeft(2, '0'),
                DateTime.Now.Day.ToString().PadLeft(2, '0'),
                DateTime.Now.Hour.ToString().PadLeft(2, '0'),
                DateTime.Now.Minute.ToString().PadLeft(2, '0')
                );

                //옵션 args작성
                StringBuilder sbArgs = new StringBuilder();
                //백업파일 형식
                switch (bkFileType)
                {
                    case BackupFileType.PlainText: { sbArgs.Append(" -F p "); }
                        break;
                    case BackupFileType.Binary: { sbArgs.Append(" -F c "); }
                        break;
                    case BackupFileType.tar: { sbArgs.Append(" -F t "); }
                        break;
                    default:
                        break;
                }
                //출력 파일명
                sbArgs.Append(" -f ");
                sbArgs.Append(BackupPath);
                //데이터베이스 생성구문까지 백업
                sbArgs.Append(" -C ");
                //복구할 데이터베이스
                sbArgs.Append(" -d ");
                sbArgs.Append(NpgConn.Database);
                sbArgs.Append(" -U  ");
                sbArgs.Append(backupServerID);
                sbArgs.Append(" -W ");
                sbArgs.Append(backupServerPassword);
                sbArgs.Append(" -h ");
                sbArgs.Append(backupServer);
                sbArgs.Append(" -p ");
                sbArgs.Append(BackupServerPost);
                new FileExecuter().Exec("pg_dump.exe", sbArgs.ToString());
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 6
0
        internal static void Restore(string DBFilePath, string DBName,string BackupFilePath, BackupFileType bkFileType, string DbID, string DbPassword)
        {
            //db커낵션 확인후 커넥션 끊고 기존db파일 이름 바꿈
            try
            {
                //원본 DB파일 이름 변경(원본파일 유지 해야 되니까)
                if (File.Exists(DBFilePath))
                {
                    string dbFolder = DBFilePath.Substring(DBFilePath.LastIndexOf("\\") - 1);
                    string oldDbPath = string.Format
                    (
                    "{0}\\{1}_{2}{3}{4}{5}{6}.OldDB",
                    dbFolder,
                    DBName,
                    DateTime.Now.Year.ToString().Substring(2, 2),
                    DateTime.Now.Month.ToString().PadLeft(2, '0'),
                    DateTime.Now.Day.ToString().PadLeft(2, '0'),
                    DateTime.Now.Hour.ToString().PadLeft(2, '0'),
                    DateTime.Now.Minute.ToString().PadLeft(2, '0')
                    );
                    File.Move(DBFilePath, oldDbPath);
                }

                if (bkFileType==BackupFileType.PlainText)
                {
                    new FileExecuter().Exec("psql.exe", string.Format("{0} < {1}", DBName, BackupFilePath));
                }
                else
                {
                    new FileExecuter().Exec("psql.exe", string.Format("{0} < {1}", DBName, BackupFilePath));
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        private void RefreshFromDB()
        {
            txtPath.Text = currentFolder;
            List <BackupBrowserGridItem> gridItems = new List <BackupBrowserGridItem>();

            currentBackupFileType = BackupFileType.Unknown;
            if (string.IsNullOrWhiteSpace(currentFolder))
            {
                gridItems.Add(new BackupBrowserGridItem()
                {
                    Name = "Files", LastModified = "", Size = "", Versions = "", BackupFile = null
                });
                gridItems.Add(new BackupBrowserGridItem()
                {
                    Name = "MSSQL", LastModified = "", Size = "", Versions = "", BackupFile = null
                });
            }
            else
            {
                string pathFileType;
                string pathRest;
                if (!currentFolder.Contains("\\"))
                {
                    pathFileType = currentFolder;
                    pathRest     = string.Empty;
                }
                else
                {
                    pathFileType = currentFolder.Substring(0, currentFolder.IndexOf("\\"));
                    pathRest     = currentFolder.Substring(currentFolder.IndexOf("\\") + 1);
                }
                if (pathFileType == "Files")
                {
                    currentBackupFileType = BackupFileType.File;
                }
                else if (pathFileType == "MSSQL")
                {
                    currentBackupFileType = BackupFileType.MSSQL;
                }

                if (currentBackupFileType != BackupFileType.Unknown)
                {
                    List <string> includedPaths = new List <string>();
                    BackupFile[]  files         = string.IsNullOrWhiteSpace(pathRest)
                        ? BackupDbContext.DB.BackupFiles.ToArray()
                        : BackupDbContext.DB.BackupFiles.Where(f => f.Path.StartsWith(pathRest)).ToArray();
                    foreach (BackupFile file in files.OrderBy(f => f.Path))
                    {
                        if (pathRest.Length > file.Path.Length)
                        {
                            continue;
                        }
                        string thisPath = file.Path.Substring(pathRest.Length).TrimStart(new [] { '\\' });
                        if (thisPath.Contains("\\"))
                        {
                            thisPath = thisPath.Substring(0, thisPath.IndexOf("\\"));
                        }
                        if (includedPaths.FirstOrDefault(p => p == thisPath) != null)
                        {
                            continue;
                        }
                        includedPaths.Add(thisPath);

                        string thisFilePath = LongFile.Combine(currentFolder, thisPath);

                        gridItems.Add(new BackupBrowserGridItem()
                        {
                            Name         = thisPath,
                            LastModified = file.LastModified.ToShortDateString() + " " + file.LastModified.ToShortTimeString(),
                            Size         = file.Size.ToString("#,####,####,###0"),
                            Versions     = "",
                            BackupFile   = null,
                        });
                    }
                }
            }

            Grid.Rows.Clear();
            if (gridItems.Count > 0)
            {
                foreach (BackupBrowserGridItem item in gridItems)
                {
                    DataGridViewRow row = new DataGridViewRow();
                    row.Tag = item.BackupFile;

                    DataGridViewTextBoxCell cell1 = new DataGridViewTextBoxCell();
                    cell1.Value = item.Name;
                    row.Cells.Add(cell1);

                    DataGridViewTextBoxCell cell2 = new DataGridViewTextBoxCell();
                    cell2.Value = item.LastModified;
                    row.Cells.Add(cell2);

                    DataGridViewTextBoxCell cell3 = new DataGridViewTextBoxCell();
                    cell3.Value = item.Size;
                    row.Cells.Add(cell3);

                    DataGridViewTextBoxCell cell4 = new DataGridViewTextBoxCell();
                    cell4.Value = item.Versions;
                    row.Cells.Add(cell4);

                    Grid.Rows.Add(row);
                }
            }
        }