public void Create( [Description("The root of the directory which should be saved")] [Required] string workingDirectory, [Description("The path of the backup directory")] [Required] string resultPath, [DefaultValue(null)] [Description("Defines the issuer of this backup")] string issuer, [DefaultValue("HEAD")] [Description("Defines the branch of this backup")] string branch, [DefaultValue(null)] [Description("Defines the comment of this backup")] string comment, [DefaultValue(false)] [Description("If this is set to true the backup itself is standalone")] bool fullBackup) { var backupRepo = new ZipBackupRepository(resultPath); if(!Directory.Exists(workingDirectory)) throw new DirectoryNotFoundException("Working directory could not be found"); var backup = backupRepo.GetBackup(branch); if (backup == null) throw new BackupNotFoundException("Could not find any backup that fits to the given branch."); using (backup) using (var prototype = backupRepo.CreateBackup ()) { Trace.WriteLine(fullBackup ? "Creating full backup" : "Creating backup", "File Tool"); prototype.SetCreationDate(DateTime.Now); prototype.SetCreator(issuer); prototype.SetDescription(comment); prototype.SetParentBackup(backup); var source = new DirectoryBackupSource(workingDirectory); var patch = fullBackup ? Patch.CreateFromSource(source) : Patch.Compare(source, backup.GetChain()); patch.ApplyPatch(prototype); if(fullBackup) prototype.SetFullBackup(true); prototype.Save (); if (backupRepo.HeadExists(branch)) backupRepo.UpdateHead(branch, prototype.Name); else Trace.WriteLine("Backup created without having a branch pointing at it."); } }
public static void Init(string path) { Directory.CreateDirectory(SysIO.Path.Combine(path, "temp")); Directory.CreateDirectory(SysIO.Path.Combine(path, "data")); Directory.CreateDirectory(SysIO.Path.Combine(path, "heads")); var rep = new ZipBackupRepository(path); using (var proto = rep.CreateBackup ()) { proto.SetDescription("Init"); proto.Save (); rep.AddHead("HEAD", proto.Name); } }