Exemplo n.º 1
0
 /// <summary>
 /// Update History
 /// </summary>
 public void UpdateHistory(string aHistory)
 {
     using (XervBackup.Scheduler.Data.HistoryDataSet hds = new XervBackup.Scheduler.Data.HistoryDataSet())
     {
         hds.Load();
         History(System.IO.File.GetLastWriteTime(aHistory), hds.History);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Convert internal options to XervBackup options
 /// </summary>
 /// <param name="aOptions"></param>
 /// <returns></returns>
 private Dictionary<string, string> FixOptions(Dictionary<string, string> aOptions)
 {
     Dictionary<string, string> Result = new Dictionary<string, string>(aOptions);
     // Try to find history entry
     if (aOptions.ContainsKey("restore-time"))
     {
         using (XervBackup.Scheduler.Data.HistoryDataSet hds = new XervBackup.Scheduler.Data.HistoryDataSet())
         {
             hds.Load();
             XervBackup.Scheduler.Data.HistoryDataSet.HistoryRow hRow = hds.History.FindByNameActionDate(
                 this.toolStripLabel1.Text, DateTime.Parse(aOptions["restore-time"]));
             if (hRow != null)
             {
                 Result["Checksum"] = System.Convert.ToBase64String( hRow.Checksum );
                 Result["encryption-module"] = hRow.CheckMod;
             }
         }
     }
     // XervBackup should use SecureString
     if (Result.ContainsKey("Checksum"))
     {
         // Unprotect will only work if process is the same user as it was protected, which this one should be.
         Result["passphrase"] = System.Text.ASCIIEncoding.ASCII.GetString(Utility.Tools.Unprotect(System.Convert.FromBase64String(Result["Checksum"])));
         Result.Remove("Checksum");
     }
     return Result;
 }
Exemplo n.º 3
0
        /// <summary>
        /// This is basically a very small XervBackup command line that only supports backup.
        /// This is a console app; but compiled with 'forms' to get rid of the dreaded console window in xp.
        /// </summary>
        /// <param name="aArgs">Arguments are job name and XML file name</param>
        static void Main(string[] aArgs)
        {
            // Args as a handy list
            List<string> ArgList = new List<string>(aArgs);
            #if DEBUGUSER
            if (!Environment.UserInteractive)
                System.Threading.Thread.Sleep(20000); // Give time to attach debugger
            if (!Environment.UserName.EndsWith("\\User"))
            {
                // TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST
                Utility.Su.Impersonate("User", Environment.UserDomainName, "asd");  // TEST
                Environment.SetEnvironmentVariable("TMP", "C:\\temp"); // TEST
            }
            #endif
            if (ArgList.Count == 0)
            {
                System.Windows.Forms.MessageBox.Show("This program must be executed with a job name and should not be executed manually");
                return;
            }

            itsDryRun = ArgList.Contains("DryRun"); // Good for debugging
            if(itsDryRun) ArgList.Remove("DryRun");
            // The job name
            Job = ArgList[0];

            // Be nice
            System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.BelowNormal;
            // Get a log file
            string LogFile = XervBackup.Scheduler.Utility.Tools.LogFileName(Package);
            using (new Notifier())  // Attempt to put that little thingy in the tray
            // Create the log
            using (XervBackup.Library.Logging.AppendLog Log = new XervBackup.Library.Logging.AppendLog(LogFile, Job))
            {
                XervBackup.Library.Logging.Log.CurrentLog = Log;
                // Hard code level to info, deal with filters in the forms level
                XervBackup.Library.Logging.Log.LogLevel = XervBackup.Library.Logging.LogMessageType.Information;
            #if !DEBUG
                try
            #endif
                {
                    // Load the history XML dataset
                    using (XervBackup.Scheduler.Data.HistoryDataSet hds = new XervBackup.Scheduler.Data.HistoryDataSet())
                    {
                        hds.Load();
                        // Create a new history record for this run
                        XervBackup.Scheduler.Data.HistoryDataSet.HistoryRow HistoryRow = hds.History.AddHistoryRow(Job, DateTime.Now, "Backup", true, false, LogFile, new byte[0], string.Empty);
                        // Actually run the job
                        RunBackup(ArgList.ToArray(), HistoryRow);
                        // Just clean out history
                        foreach (XervBackup.Scheduler.Data.HistoryDataSet.HistoryRow Row in
                            from XervBackup.Scheduler.Data.HistoryDataSet.HistoryRow qR in hds.History
                            where !System.IO.File.Exists(qR.LogFileName) select qR)
                                Row.Delete();
                        hds.Save();     // Save the XML (later: make so the whole db need not be loaded (XMLReader)
                    }
                }
            #if !DEBUG
                catch (Exception Ex)        // Log error
                {
                    Library.Logging.Log.WriteMessage(Ex.Message, XervBackup.Library.Logging.LogMessageType.Error);
                }
            #endif
                UpdateMonitors(LogFile);
                // All done, set the log file (filewathers are looking for AttributeChange)
                System.IO.File.SetAttributes(LogFile, System.IO.FileAttributes.ReadOnly);
            }
        }