示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="config"></param>
        /// <param name="jobID"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        public string Execute(string config, int jobID, IBackupTarget target)
        {
            MSSQLDatabaseBackupConfig conf      = MSSQLDatabaseBackupConfig.Load(config);
            List <string>             databases = conf.Databases;

            if (databases == null || databases.Count == 0)
            {
                databases = new List <string>();
                List <string> tmp = MSSQLDatabaseBackupConfigGUI.GetDatabases(conf.Server, conf.Username, conf.Password);
                foreach (string s in tmp)
                {
                    if (!s.EqualsAny(StringComparison.OrdinalIgnoreCase, "master", "model", "msdb", "tempdb"))
                    {
                        databases.Add(s);
                    }
                }
            }
            bool   remoteCleanupOK = true;
            string outputDir       = conf.LocalTempDirectory;
            string remoteDir       = conf.RemoteTempDir;

            if (conf.IsLocalServer)
            {
                remoteDir = outputDir;
                outputDir = null;
            }
            foreach (string db in databases)
            {
                BackupResult res;
                using (SQLLocalBackup lb = new SQLLocalBackup(conf.Server, conf.Username, conf.Password, db)) {
                    res = lb.DoLocalBackup(remoteDir, outputDir, conf.AddDateToFilename);
                    if (!res.CleanupOK)
                    {
                        remoteCleanupOK = false;
                    }
                }
                if (conf.CompressFiles)
                {
                    res.OutputFilename = ZipFile(res.OutputFilename);
                }
                target.Store(new FileInfo(res.OutputFilename), "");
                //if( conf.SaveAs == SaveAsTypes.FTP ) {
                //    FTPFile( res.OutputFilename, conf );
                //    try {
                //        File.Delete( res.OutputFilename );
                //    } catch {
                //    }
                //}
            }
            if (!remoteCleanupOK)
            {
                return(@"{0} was backed up.
Temporary files on the remote server was not deleted.
Enable procedure xp_cmdshell to perform this".FillBlanks(databases.ToString(", ")));
            }
            return("{0} was backuped.".FillBlanks(databases.ToString(", ")));
        }
示例#2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="fi"></param>
 /// <param name="path"></param>
 private void Add(FileInfo fi, string path)
 {
     if (config.CompressFiles)
     {
         Zip.AddFile(fi.FullName, path);
     }
     else
     {
         target.Store(fi, path);
         //if( config.SaveAs == SaveAsTypes.Directory ) {
         //    DirectoryInfo td = new DirectoryInfo( config.SaveToDir );
         //    if( !string.IsNullOrEmpty( path ) ) {
         //        td = new DirectoryInfo( "{0}\\{1}".FillBlanks( td.FullName, path ) );
         //    }
         //    if( !Directory.Exists( td.FullName ) ) {
         //        Directory.CreateDirectory( td.FullName );
         //    }
         //    string tn = "{0}\\{1}".FillBlanks( td.FullName, fi.Name );
         //    if( File.Exists( tn ) ) {
         //        FileInfo tf = new FileInfo( tn );
         //        if( tf.LastWriteTime == fi.LastWriteTime && tf.Length == fi.Length ) {
         //            // file already exist, is not modified, and is as large as the file being backup, so we consider it already copied
         //            return;
         //        }
         //        File.SetAttributes( tn, FileAttributes.Normal );
         //    }
         //    File.Copy( fi.FullName, tn, true );
         //} else {
         //    string rd = config.FTPRemoteDirectory;
         //    if( !rd.EndsWith( "/" ) ) {
         //        rd += "/";
         //    }
         //    rd += path.Replace( "\\", "/" );
         //    rd = rd.Replace( "//", "/" );
         //    FTPTarget.UploadFile( fi.FullName, rd );
         //}
     }
 }