Пример #1
0
        /// <summary>
        ///     Performs a global backup action, copying all files in the SavesDirectory to the BackupDirectory.
        /// </summary>
        public static void Backup()
        {
            if (Busy)
            {
                ToConsole("Could not perform backup action, the service is busy.");
                return;
            }

            Busy = true;

            var now = DateTime.UtcNow;

            try
            {
                ToConsole(String.Empty);
                ToConsole("Backup action started...");

                if (BackupExpireAge > TimeSpan.Zero)
                {
                    ToConsole("Backup Expire Age: {0}", BackupExpireAge);

                    lock (IOLock)
                    {
                        BackupDirectory.EmptyDirectory(BackupExpireAge);
                    }
                }

                lock (IOLock)
                {
                    SavesDirectory.CopyDirectory(
                        IOUtility.EnsureDirectory(BackupDirectory + "/" + DateTime.Now.ToSimpleString("D d M y"), true));
                }

                InvokeByPriority(OnBackup);
            }
            finally
            {
                Busy = false;
            }

            var time = (DateTime.UtcNow - now).TotalSeconds;

            ToConsole("Backup action completed in {0:F2} second{1}", time, (time != 1) ? "s" : String.Empty);
        }
Пример #2
0
 private static void FlushExpired()
 {
     BackupDirectory.EmptyDirectory(TimeSpan.FromDays(3.0));
 }