public override void Init(IDictionary <string, string> jobArgsDictionary) { var retrievedMaxManifestSize = JobConfigurationManager.TryGetIntArgument(jobArgsDictionary, JobArgumentNames.MaxManifestSize); MaxManifestSize = retrievedMaxManifestSize == null ? DefaultMaxAllowedManifestBytes : Convert.ToInt64(retrievedMaxManifestSize); PackageDatabase = new SqlConnectionStringBuilder( JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.PackageDatabase)); Source = CloudStorageAccount.Parse( JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.SourceStorage)); Backups = CloudStorageAccount.Parse( JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.BackupStorage)); SourceContainerName = JobConfigurationManager.TryGetArgument(jobArgsDictionary, JobArgumentNames.SourceContainerName) ?? DefaultSourceContainerName; BackupsContainerName = JobConfigurationManager.TryGetArgument(jobArgsDictionary, JobArgumentNames.BackupContainerName) ?? DefaultBackupContainerName; ReadMeContainerName = JobConfigurationManager.TryGetArgument(jobArgsDictionary, JobArgumentNames.ReadMeContainerName) ?? DefaultReadMeContainerName; SourceContainer = Source.CreateCloudBlobClient().GetContainerReference(SourceContainerName); BackupsContainer = Backups.CreateCloudBlobClient().GetContainerReference(BackupsContainerName); ReadMeContainer = Source.CreateCloudBlobClient().GetContainerReference(ReadMeContainerName); MaxTryCount = DefaultMaxRetryCount; }
private void IdentifyBackups() { Backups.Clear(); Backups.AddRange( Snapshots.Select(b => b.Metadata["Name"]) .Distinct()); }
public void BackupPath() { string baseDir = @"c:\my\fancy\folder"; Backups bf = new Backups(baseDir + @"\test.xlsx", ".backup"); Assert.AreEqual(baseDir + @"\.backup", bf.BackupPath); }
public void BackupDir() { string dir = ".backup"; Backups bf = new Backups(@"c:\test.xlsx", dir); Assert.AreEqual(dir, bf.BackupDir); }
private void Execute(string routinesFile) { DimConsole.WriteIntro("Executing the current routines script."); if (File.Exists(routinesFile)) { DimConsole.WriteLine("Backing up existing database first."); Backups.SaveFile(base.DryRun, completedCallback : delegate(string filePath) { DimConsole.WriteLine("Backup complete:", filePath); }); if (!base.DryRun) { // using(var db = new DatabaseCommander()) // { DatabaseProvider.Manager.Execute(File.ReadAllText(routinesFile)); // } } DimConsole.WriteLine("Routines script executed!"); } else { DimConsole.WriteLine("routines.sql file does not exist."); } }
public static void Main(string[] args) { if (args.Length != 3) { throw new ArgumentException($"Incorrect number of input arguments. {ConfigurationImporter.usageString}"); } string configurationFile = args[0]; Dictionary <string, string> importOptions = Duplicati.Library.Utility.CommandLineParser.ExtractOptions(args.Skip(1).ToList()); if (!importOptions.TryGetValue("import-metadata", out string importMetadataString)) { throw new ArgumentException($"Invalid import-metadata argument. {ConfigurationImporter.usageString}"); } bool importMetadata = Duplicati.Library.Utility.Utility.ParseBool(importMetadataString, false); if (!importOptions.TryGetValue("server-datafolder", out string serverDatafolder)) { throw new ArgumentException($"Invalid server-datafolder argument. {ConfigurationImporter.usageString}"); } Dictionary <string, string> advancedOptions = new Dictionary <string, string> { { "server-datafolder", serverDatafolder } }; ImportExportStructure importedStructure = Backups.ImportBackup(configurationFile, importMetadata, () => ConfigurationImporter.ReadPassword($"Password for {configurationFile}: "), advancedOptions); Console.WriteLine($"Imported \"{importedStructure.Backup.Name}\" with ID {importedStructure.Backup.ID} and local database at {importedStructure.Backup.DBPath}."); }
/// <summary> /// /// </summary> /// <param name="files"></param> /// <param name="token"></param> protected void BackupInternal(IEnumerable <String> files, CancellationToken?token = null) { TotalSteps = files.Count(); CurrentStep = 0; foreach (var fileFullPath in files) { if (!Backups.ContainsKey(fileFullPath)) { var backupDirPath = TryGetBackupDirForFile(fileFullPath); if (backupDirPath == null) { backupDirPath = CreateBackupDirForFile(fileFullPath); BackupDirectories.Add(backupDirPath); } var fileBackupPath = Path.Combine(backupDirPath, Path.GetRandomFileName()); if (token.HasValue) { FileUtilities.CopyFileEx(fileFullPath, fileBackupPath, token.Value); } else { FileUtilities.CopyFileEx(fileFullPath, fileBackupPath); } // Zastnowić się nad tym czy kolejność danych w słowniku jest dobra (w sensie klucz\wartość) Backups.Add(fileFullPath, fileBackupPath); } CurrentStep++; } CurrentStep = TotalSteps; }
public void DeleteBackup(BackupDefenition bs) { if (bs == null) { return; } try { if (Backups.ContainsKey(bs.Name)) { Backups.Remove(bs.Name); } foreach (XmlElement xmlElement in _backupXml.ChildNodes) { if (xmlElement.GetAttribute("name").Equals(bs.Name)) { _backupXml.RemoveChild(xmlElement); } } _backupXml.Save(_backupXmlPath); } catch (Exception ex) { Logger.Log(LogLevel.Severe, "Backupmanager", "Severe error in deleteBackup(bs)!", ex.Message); } if (BackupsLoaded != null) { BackupsLoaded(); } }
private bool _disposedValue; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!_disposedValue) { if (disposing) { Files.Dispose(); BackupModifiedFilenames.Dispose(); Documents.Dispose(); Folders.Dispose(); Parametrized.Dispose(); ListingFilesTest.Dispose(); ListingFilesFound.Dispose(); Backups.Dispose(); OpenFoldersFound.Dispose(); InsecureMethodFoldersFound.Dispose(); } Files = null; BackupModifiedFilenames = null; Documents = null; Folders = null; Parametrized = null; ListingFilesTest = null; ListingFilesFound = null; Backups = null; OpenFoldersFound = null; InsecureMethodFoldersFound = null; _disposedValue = true; } }
/// <summary> /// Add a backup file if it doesn't exist /// </summary> /// <param name="backupFile"></param> public void AddBackUp(BackUpFile backupFile) { if (!ExistBackUp(backupFile)) { Backups.Add(backupFile); } }
/// <summary> /// Method that will generage and save the configuration file for all the backups /// </summary> /// <param name="filename">File name of the backup</param> private void SerializeCollection(string filename) { _logger.Info("Save backup in the configuration file : " + filename); // Create the collection of backups Backups backups = new Backups(); // Name te collection backups.CollectionName = "Backups"; // Add the value to the collection from the existing backup list foreach (var backup in _mainProcess.backupList) { backups.Add(backup); } // Initiate a Serializer XmlSerializer x = new XmlSerializer(typeof(Backups)); // Initiate a stream writer TextWriter writer = new StreamWriter(filename); // Serialise the collection and print it into the file x.Serialize(writer, backups); // Close the file writer.Close(); }
private void Execute() { DimConsole.WriteIntro("Executing the current baseline script."); if (File.Exists(this.BaselineFilePath)) { DimConsole.WriteLine("Backing up existing database first."); Backups.SaveFile(base.DryRun, completedCallback : delegate(string filePath) { DimConsole.WriteLine("Backup completed:", filePath); }); if (!base.DryRun) { DatabaseProvider.Manager.CreateSchema(); DatabaseProvider.Manager.Execute(File.ReadAllText(this.BaselineFilePath)); } DimConsole.WriteLine("Baseline script executed!"); } else { DimConsole.WriteLine("The baseline file does not exist."); } }
internal async Task <string> Clone(SnapSession session) { try { PrimaryBackup b = new PrimaryBackup(); b.BackupName = session.BackupName; CloneBody body = new CloneBody(); CloneConfigurationApplication cloneConfApp = new CloneConfigurationApplication(); cloneConfApp.type = "SMCoreContracts.SmSCCloneConfiguration, SMCoreContracts"; cloneConfApp.MountCmd = new System.Collections.Generic.List <string>(); cloneConfApp.MountCmd.Add($"mount {session.LeafIP}:%mysql_vol_Clone {session.MountPath}"); cloneConfApp.PostCloneCreateCmd = new System.Collections.Generic.List <string>(); cloneConfApp.PostCloneCreateCmd.Add($"{session.MountScript}"); cloneConfApp.Host = session.CloneHostName; CloneConfiguration conf = new CloneConfiguration(); conf.type = "SMCoreContracts.SmCloneConfiguration, SMCoreContracts"; conf.Suffix = string.Empty; // string.Format("_{0}", session.AppName); //set app alias to distiguish clones conf.CloneConfigurationApplication = cloneConfApp; body.CloneConfiguration = conf; body.Backups = new System.Collections.Generic.List <Backups>(); Backups back = new Backups(); back.PrimaryBackup = b; body.Backups.Add(back); var response = await this.SendRequestAsync <dynamic>(Method.POST, $"api/3.0/plugins/{session.Plugin}/resources/{session.DbKey}/clone", body, false); return(response.Response.StatusCode.ToString()); } catch (Exception ex) { this.log.Error($"Error while cloning {session.DbKey}: {ex}"); throw; } }
/// <summary> /// /// </summary> /// <param name="files"></param> /// <param name="token"></param> protected void RestoreInternal(IEnumerable <String> files, CancellationToken?token = null) { TotalSteps = files.Count(); CurrentStep = 0; foreach (var fileFullPath in files) { if (Backups.ContainsKey(fileFullPath)) { var fileBackupPath = Backups[fileFullPath]; if (token.HasValue) { FileUtilities.CopyFileEx(fileBackupPath, fileFullPath, token.Value); } else { FileUtilities.CopyFileEx(fileBackupPath, fileFullPath); } CurrentStep++; } } CurrentStep = TotalSteps; }
public override bool Init(IDictionary <string, string> jobArgsDictionary) { string maxManifestSizeString = JobConfigurationManager.TryGetArgument(jobArgsDictionary, JobArgumentNames.MaxManifestSize); if (string.IsNullOrEmpty(maxManifestSizeString)) { MaxManifestSize = DefaultMaxAllowedManifestBytes; } else { MaxManifestSize = Convert.ToInt64(maxManifestSizeString); } PackageDatabase = new SqlConnectionStringBuilder( JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.PackageDatabase, EnvironmentVariableKeys.SqlGallery)); Source = CloudStorageAccount.Parse( JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.SourceStorage, EnvironmentVariableKeys.StorageGallery)); Backups = CloudStorageAccount.Parse( JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.BackupStorage, EnvironmentVariableKeys.StorageGallery)); SourceContainerName = JobConfigurationManager.TryGetArgument(jobArgsDictionary, JobArgumentNames.SourceContainerName) ?? DefaultSourceContainerName; BackupsContainerName = JobConfigurationManager.TryGetArgument(jobArgsDictionary, JobArgumentNames.BackupContainerName) ?? DefaultBackupContainerName; SourceContainer = Source.CreateCloudBlobClient().GetContainerReference(SourceContainerName); BackupsContainer = Backups.CreateCloudBlobClient().GetContainerReference(BackupsContainerName); return(true); }
/// <summary> /// 更新一条数据 /// </summary> public virtual void Update(Backups model) { using (var session = sessionFactory.OpenSession()) { session.SaveOrUpdate(model); session.Flush(); } }
public void InvalidBackupPath() { string baseDir = @"c:\my\fancy\folder"; Assert.Throws <ArgumentException>(() => { Backups bf = new Backups(baseDir + @"\test.xlsx", @"c:\.backup"); }); }
public override int Run(string[] remainingArguments) { if (!Program.IsCorrectlySetup()) { return(0); } DimConsole.WriteIntro("Run updates on the database"); base.CheckRecordsTableExists(); var runFiles = DimFileProcessor.GetRunFiles(); if (runFiles.Count > 0) { // Display count of files found. DimConsole.WriteLine(string.Format("{0} script(s) found to be run.", runFiles.Count)); // Display names of files found. for (int i = 0, l = runFiles.Count; i < l; i++) { int count = i + 1; var fileName = Path.GetFileName(runFiles[i].FileName); DimConsole.WriteLine(string.Format("{0}. \"{1}\"", count, fileName)); } // Backup before running anything (use for rollback) DimConsole.WriteLine("Backing up database (local backup)"); Backups.SaveFile(base.DryRun, completedCallback : delegate(string fileName) { DimConsole.WriteLine("Completed backup:", fileName); }); // Execute all new patches foreach (var file in runFiles) { DimConsole.WriteLine("Executing: \"" + Path.GetFileName(file.FileName) + "\""); DimFileProcessor.ExecuteFile(file, base.DryRun, successCallback : delegate() { DimConsole.WriteLine("Executed successfully!"); }, failureCallback : delegate(string message) { DimConsole.WriteLine("Execution failed:", message); }); } DimConsole.WriteLine("Update completed."); } else { DimConsole.WriteLine("No scripts found to be run."); } return(0); }
/// <summary> /// 增加一条数据 /// </summary> public virtual object Save(Backups model) { using (ISession session = sessionFactory.OpenSession()) { var id = session.Save(model); session.Flush(); return(id); } }
/// <summary> /// 删除数据 /// </summary> public virtual void Delete(Backups model) { using (var session = sessionFactory.OpenSession()) { session.Delete(model); session.Flush(); } }
public AzureStorage(IDictionary <string, string> jobArgsDictionary) { Source = CloudStorageAccount.Parse(JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.SourceStorage)); SourceContainerName = JobConfigurationManager.TryGetArgument(jobArgsDictionary, JobArgumentNames.SourceContainerName) ?? DefaultSourceContainerName; SourceContainer = Source.CreateCloudBlobClient().GetContainerReference(SourceContainerName); Backups = CloudStorageAccount.Parse(JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.BackupStorage)); BackupsContainerName = JobConfigurationManager.TryGetArgument(jobArgsDictionary, JobArgumentNames.BackupContainerName) ?? DefaultBackupContainerName; BackupsContainer = Backups.CreateCloudBlobClient().GetContainerReference(BackupsContainerName); SnapshotService = new AzureSnapshotService(); }
public void AddBackup(string filePath, string backupPath, StorageType storageType) { if (!File.Exists(filePath)) { BackupLogger.GetInstance().Error($"Cannot add backup for the file {filePath}." + $" File {filePath} does not exist."); return; } Backups.Add(new Backup(filePath, backupPath, storageType)); BackupLogger.GetInstance().Info($"Backup for the file {filePath} was added to the current backup system."); }
public BackupDefenition GetBackupByName(string name) { if (string.IsNullOrEmpty(name)) { return(null); } if (!Backups.ContainsKey(name)) { return(null); } return(Backups[name]); }
/// <summary> /// 删除数据 /// </summary> public override void Delete(Backups model) { string key = "Backups:" + model.id; if (rh.Exist(key) > 0) //存在 { rh.Remove(key); //检查是否存在关联 rh.DelJoin("Backups"); } base.Delete(model); }
/// <summary> /// 更新一条数据 /// </summary> public override void Update(Backups model) { string key = "Backups:" + model.id; if (rh.Exist(key) > 0) //存在 { //修改当前集合 rh.Set <Backups>(key, model); //检查是否存在关联 rh.DelJoin("Backups"); } base.Update(model); }
public void RemoveBackup(string filePath) { var backup = Backups.FirstOrDefault(b => b.OriginalFilePath == filePath); if (backup is null) { BackupLogger.GetInstance().Error( $"Backup for the file {filePath} does not exist in the current backup system."); return; } Backups.Remove(backup); BackupLogger.GetInstance().Info($"Backup for the file {filePath} was removed from the current backup system."); }
private async Task GetFiles() { var folder = await StorageFolder.GetFolderFromPathAsync(UserDataPaths.GetDefault().Music); StorageFolder assets = await folder.GetFolderAsync("Backups"); Backups.Clear(); var files = await assets.GetFilesAsync(); foreach (var fileToAdd in files) { Backups.Add(fileToAdd); } }
public override int Run(string[] remainingArguments) { if (!Program.IsCorrectlySetup()) { return(0); } DimConsole.WriteIntro("Running a complete backup"); //CreateBackup(base.DryRun, this.FilePath); Backups.SaveFile(base.DryRun, this.FilePath, delegate(string filePath) { DimConsole.WriteLine("Backup completed:", filePath); }); return(0); }
public IEnumerable <string> getAllBackUps() { string destdir = @"C:\backupdb"; string[] files = Directory.GetFiles(destdir); Backups backups = new Backups(); foreach (string file in files) { var arr = file.Split(@"\"); string name = arr[arr.Length - 1]; backups.List.Add(name); } return(backups.List); }
public void Purge() { string tmpPath = Path.GetTempPath(); string backupDir = Path.GetRandomFileName(); string basename = "myfile"; string file = basename + ".xlsx"; string backupsStub = Path.Combine(tmpPath, backupDir, basename); DateTime dt = DateTime.Today; string today = dt.ToString("yyyyMMdd"); string yesterday = dt.AddDays(-1).ToString("yyyyMMdd"); Directory.CreateDirectory(Path.Combine(tmpPath, backupDir)); List <string> expected = new List <string>(); TouchFile(String.Format("{0}_{1}_090000.xlsx", backupsStub, yesterday)); TouchFile(String.Format("{0}_{1}_100000.xlsx", backupsStub, yesterday), expected); TouchFile(String.Format("{0}_{1}_080000.xlsx", backupsStub, today), expected); TouchFile(String.Format("{0}_{1}_090000.xlsx", backupsStub, today), expected); TouchFile(String.Format("{0}_{1}_100000.xlsx", backupsStub, today), expected); TouchFile(String.Format("{0}_{1}_110000.xlsx", backupsStub, today), expected); TouchFile(String.Format("{0}_{1}_120000.xlsx", backupsStub, today), expected); TouchFile(String.Format("{0}_{1}_100000.xlsx", backupsStub, dt.AddDays(-2).ToString("yyyyMMdd")), expected); TouchFile(String.Format("{0}_{1}_100000.xlsx", backupsStub, dt.AddDays(-4).ToString("yyyyMMdd")), expected); TouchFile(String.Format("{0}_{1}_090000.xlsx", backupsStub, dt.AddDays(-4).ToString("yyyyMMdd"))); TouchFile(String.Format("{0}_{1}_100000.xlsx", backupsStub, dt.AddDays(-5).ToString("yyyyMMdd")), expected); TouchFile(String.Format("{0}_{1}_100000.xlsx", backupsStub, dt.AddDays(-6).ToString("yyyyMMdd")), expected); TouchFile(String.Format("{0}_{1}_100000.xlsx", backupsStub, dt.AddDays(-7).ToString("yyyyMMdd")), expected); TouchFile(String.Format("{0}_{1}_100000.xlsx", backupsStub, dt.AddDays(-8).ToString("yyyyMMdd")), expected); TouchFile(backupsStub + "_20151008_133212.xlsx", expected); TouchFile(backupsStub + "_20151007_120000.xlsx"); TouchFile(backupsStub + "_20141008_133212.xlsx", expected); TouchFile(backupsStub + "_20140515_120000.xlsx", expected); TouchFile(backupsStub + "_20140102_073212.xlsx", expected); TouchFile(backupsStub + "_20151123_160000.xlsx", expected); Backups b = new Backups(Path.Combine(tmpPath, basename) + ".xlsx", backupDir); b.Purge(); List <string> actual = b.Files.Select(f => f.Path).ToList(); expected.Sort(); actual.Sort(); Assert.AreEqual(expected, actual); Directory.Delete(Path.Combine(tmpPath, backupDir), true); }