Esempio n. 1
0
        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.");
            }
        }
Esempio n. 2
0
        public void CreateHead(
            [Description("The path of the backup directory")]
            [Required]
            string backupPath,
            [Description("The name of the head")]
            [Required]
            string name,
            [Description("The identifier the head should point to (can be a backup id or a head name)")]
            [Required]
            string identifier)
        {
            var backupRepo = new ZipBackupRepository(backupPath);

            if (backupRepo.HeadExists(name))
                throw new InvalidOperationException("The head already exists");

            backupRepo.AddHead(name, backupRepo.ResolveIdentifier(identifier));
        }
Esempio n. 3
0
        public void RenameHead(
            [Description("The path of the backup directory")]
            [Required]
            string backupPath,
            [Description("The name of the head")]
            [Required]
            string name,
            [Description("The new name of the head")]
            [Required]
            string newName)
        {
            var backupRepo = new ZipBackupRepository(backupPath);

            if (!backupRepo.HeadExists(name))
                throw new InvalidOperationException("The head does not exist");

            var value = backupRepo.ResolveIdentifier(name);
            backupRepo.AddHead(newName, value);
            backupRepo.RemoveHead(name);
        }