Ejemplo n.º 1
0
        public static int ListChanges(List <string> args, Dictionary <string, string> options, Library.Utility.IFilter filter)
        {
            if (args.Count < 1)
            {
                return(PrintWrongNumberOfArguments(args, 1));
            }

            // Support for not adding the --auth-username if possible
            string dbpath;

            options.TryGetValue("dbpath", out dbpath);
            if (string.IsNullOrEmpty(dbpath))
            {
                dbpath = Library.Main.DatabaseLocator.GetDatabasePath(args[0], new Duplicati.Library.Main.Options(options), false, true);
                if (dbpath != null)
                {
                    options["dbpath"] = dbpath;
                }
            }

            // Don't ask for passphrase if we have a local db
            if (!string.IsNullOrEmpty(dbpath) && System.IO.File.Exists(dbpath) && !options.ContainsKey("no-encryption") && !Duplicati.Library.Utility.Utility.ParseBoolOption(options, "no-local-db"))
            {
                string passphrase;
                options.TryGetValue("passphrase", out passphrase);
                if (string.IsNullOrEmpty(passphrase))
                {
                    options["no-encryption"] = "true";
                }
            }

            Library.Interface.IListChangesResults result;
            using (var i = new Library.Main.Controller(args[0], options, new ConsoleOutput(options)))
                if (args.Count == 2)
                {
                    result = i.ListChanges(null, args[1], null, filter);
                }
                else
                {
                    result = i.ListChanges(args.Count > 1 ? args[1] : null, args.Count > 2 ? args[2] : null, null, filter);
                }

            Console.WriteLine("Listing changes");
            Console.WriteLine("  {0}: {1}", result.BaseVersionIndex, result.BaseVersionTimestamp);
            Console.WriteLine("  {0}: {1}", result.CompareVersionIndex, result.CompareVersionTimestamp);
            Console.WriteLine();

            Console.WriteLine("Size of backup {0}: {1}", result.BaseVersionIndex, Library.Utility.Utility.FormatSizeString(result.PreviousSize));

            if (result.ChangeDetails != null)
            {
                Console.WriteLine();

                var added    = result.ChangeDetails.Where(x => x.Item1 == Library.Interface.ListChangesChangeType.Added);
                var deleted  = result.ChangeDetails.Where(x => x.Item1 == Library.Interface.ListChangesChangeType.Deleted);
                var modified = result.ChangeDetails.Where(x => x.Item1 == Library.Interface.ListChangesChangeType.Modified);

                var count = added.Count();
                if (count > 0)
                {
                    Console.WriteLine("  {0} added entries:", count);
                    foreach (var n in added)
                    {
                        Console.WriteLine("  + {0}", n.Item3);
                    }
                    Console.WriteLine();
                }
                count = modified.Count();
                if (count > 0)
                {
                    Console.WriteLine("  {0} modified entries:", count);
                    foreach (var n in modified)
                    {
                        Console.WriteLine("  ~ {0}", n.Item3);
                    }
                    Console.WriteLine();
                }
                count = deleted.Count();
                if (count > 0)
                {
                    Console.WriteLine("{0} deleted entries:", count);
                    foreach (var n in deleted)
                    {
                        Console.WriteLine("  - {0}", n.Item3);
                    }
                    Console.WriteLine();
                }

                Console.WriteLine();
            }
            else
            {
                if (result.AddedFolders > 0)
                {
                    Console.WriteLine("  Added folders:     {0}", result.AddedFolders);
                }
                if (result.AddedSymlinks > 0)
                {
                    Console.WriteLine("  Added symlinks:    {0}", result.AddedSymlinks);
                }
                if (result.AddedFiles > 0)
                {
                    Console.WriteLine("  Added files:       {0}", result.AddedFiles);
                }
                if (result.DeletedFolders > 0)
                {
                    Console.WriteLine("  Deleted folders:   {0}", result.DeletedFolders);
                }
                if (result.DeletedSymlinks > 0)
                {
                    Console.WriteLine("  Deleted symlinks:  {0}", result.DeletedSymlinks);
                }
                if (result.DeletedFiles > 0)
                {
                    Console.WriteLine("  Deleted files:     {0}", result.DeletedFiles);
                }
                if (result.ModifiedFolders > 0)
                {
                    Console.WriteLine("  Modified folders:  {0}", result.ModifiedFolders);
                }
                if (result.ModifiedSymlinks > 0)
                {
                    Console.WriteLine("  Modified symlinka: {0}", result.ModifiedSymlinks);
                }
                if (result.ModifiedFiles > 0)
                {
                    Console.WriteLine("  Modified files:    {0}", result.ModifiedFiles);
                }

                if (result.AddedFolders + result.AddedSymlinks + result.AddedFolders +
                    result.ModifiedFolders + result.ModifiedSymlinks + result.ModifiedFiles +
                    result.DeletedFolders + result.DeletedSymlinks + result.DeletedFiles == 0)
                {
                    Console.WriteLine("  No changes found");
                }
            }

            Console.WriteLine("Size of backup {0}: {1}", result.CompareVersionIndex, Library.Utility.Utility.FormatSizeString(result.CurrentSize));

            return(0);
        }
Ejemplo n.º 2
0
        public static int ListChanges(List<string> args, Dictionary<string, string> options, Library.Utility.IFilter filter)
        {
            if (args.Count < 1)
                return PrintWrongNumberOfArguments(args, 1);
            
            // Support for not adding the --auth-username if possible
            string dbpath;
            options.TryGetValue("dbpath", out dbpath);
            if (string.IsNullOrEmpty(dbpath))
            {
                dbpath = Library.Main.DatabaseLocator.GetDatabasePath(args[0], new Duplicati.Library.Main.Options(options), false, true);
                if (dbpath != null)
                    options["dbpath"] = dbpath;
            }
            
            // Don't ask for passphrase if we have a local db
            if (!string.IsNullOrEmpty(dbpath) && System.IO.File.Exists(dbpath) && !options.ContainsKey("no-encryption") && !Duplicati.Library.Utility.Utility.ParseBoolOption(options, "no-local-db"))
            {
                string passphrase;
                options.TryGetValue("passphrase", out passphrase);
                if (string.IsNullOrEmpty(passphrase))
                    options["no-encryption"] = "true";
            }
                            
            Library.Interface.IListChangesResults result;
            using(var i = new Library.Main.Controller(args[0], options, new ConsoleOutput(options)))
                if (args.Count == 2)
                    result = i.ListChanges(null, args[1], null, filter);
                else            
                    result = i.ListChanges(args.Count > 1 ? args[1] : null, args.Count > 2 ? args[2] : null, null, filter);
            
            Console.WriteLine("Listing changes");
            Console.WriteLine("  {0}: {1}", result.BaseVersionIndex, result.BaseVersionTimestamp);
            Console.WriteLine("  {0}: {1}", result.CompareVersionIndex, result.CompareVersionTimestamp);
            Console.WriteLine();
            
            Console.WriteLine("Size of backup {0}: {1}", result.BaseVersionIndex, Library.Utility.Utility.FormatSizeString(result.PreviousSize));
            
            if (result.ChangeDetails != null)
            {
                Console.WriteLine();
                
                var added = result.ChangeDetails.Where(x => x.Item1 == Library.Interface.ListChangesChangeType.Added);
                var deleted = result.ChangeDetails.Where(x => x.Item1 == Library.Interface.ListChangesChangeType.Deleted);
                var modified = result.ChangeDetails.Where(x => x.Item1 == Library.Interface.ListChangesChangeType.Modified);
            
                var count = added.Count();
                if (count > 0)
                {
                    Console.WriteLine("  {0} added entries:", count);
                    foreach(var n in added)
                        Console.WriteLine("  + {0}", n.Item3);
                    Console.WriteLine();
                }
                count = modified.Count();
                if (count > 0)
                {
                    Console.WriteLine("  {0} modified entries:", count);
                    foreach(var n in modified)
                        Console.WriteLine("  ~ {0}", n.Item3);
                    Console.WriteLine();
                }
                count = deleted.Count();
                if (count > 0)
                {
                    Console.WriteLine("{0} deleted entries:", count);
                    foreach(var n in deleted)
                        Console.WriteLine("  - {0}", n.Item3);
                    Console.WriteLine();
                }
                
                Console.WriteLine();
            }
            else
            {
                if (result.AddedFolders > 0)
                    Console.WriteLine("  Added folders:     {0}", result.AddedFolders);
                if (result.AddedSymlinks > 0)
                    Console.WriteLine("  Added symlinks:    {0}", result.AddedSymlinks);
                if (result.AddedFiles > 0)
                    Console.WriteLine("  Added files:       {0}", result.AddedFiles);
                if (result.DeletedFolders > 0)
                    Console.WriteLine("  Deleted folders:   {0}", result.DeletedFolders);
                if (result.DeletedSymlinks > 0)
                    Console.WriteLine("  Deleted symlinks:  {0}", result.DeletedSymlinks);
                if (result.DeletedFiles > 0)
                    Console.WriteLine("  Deleted files:     {0}", result.DeletedFiles);
                if (result.ModifiedFolders > 0)
                    Console.WriteLine("  Modified folders:  {0}", result.ModifiedFolders);
                if (result.ModifiedSymlinks > 0)
                    Console.WriteLine("  Modified symlinka: {0}", result.ModifiedSymlinks);
                if (result.ModifiedFiles > 0)
                    Console.WriteLine("  Modified files:    {0}", result.ModifiedFiles);

                if (result.AddedFolders + result.AddedSymlinks + result.AddedFolders +
                    result.ModifiedFolders + result.ModifiedSymlinks + result.ModifiedFiles +
                    result.DeletedFolders + result.DeletedSymlinks + result.DeletedFiles == 0)
                        Console.WriteLine("  No changes found");
            }
            
            Console.WriteLine("Size of backup {0}: {1}", result.CompareVersionIndex, Library.Utility.Utility.FormatSizeString(result.CurrentSize));
            
            return 0;
        }