GetTimestamp() public static method

public static GetTimestamp ( ) : string
return string
示例#1
0
        private void RenameLiveDatabase(
            IDbExecutor masterDbExecutor)
        {
            var timestamp  = Util.GetTimestamp();
            var liveDbName = "Live_" + timestamp;

            Log.Info("Renaming NuGetGallery to {0}.", liveDbName);
            var sql = $"ALTER DATABASE NuGetGallery MODIFY Name = {liveDbName}";

            masterDbExecutor.Execute(sql);
            Log.Info("Renamed NuGetGallery to {0}.", liveDbName);
        }
示例#2
0
        public override void ExecuteCommand()
        {
            Log.Trace("Connecting to server '{0}' to back up database '{1}'.", ConnectionString.InitialCatalog, Util.GetDatabaseServerName(ConnectionString));

            _startedBackup = false;

            var cstr = Util.GetMasterConnectionString(ConnectionString.ConnectionString);

            using (var connection = new SqlConnection(cstr))
                using (var db = new SqlExecutor(connection))
                {
                    connection.Open();

                    if (!Force)
                    {
                        Log.Trace("Checking for a backup in progress.");
                        if (Util.BackupIsInProgress(db, BackupNamePrefix))
                        {
                            Log.Trace("Found a backup in progress; exiting.");
                            return;
                        }

                        Log.Trace("Found no backup in progress.");

                        Log.Trace("Getting last backup time.");
                        var lastBackupTime = Util.GetLastBackupTime(db, BackupNamePrefix);
                        if (lastBackupTime >= DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(IfOlderThan)))
                        {
                            Log.Info("Skipping Backup. Last Backup was less than {0} minutes ago", IfOlderThan);
                            return;
                        }
                        Log.Trace("Last backup time is more than {0} minutes ago. Starting new backup.", IfOlderThan);
                    }
                    else
                    {
                        Log.Trace("Forcing new backup");
                    }

                    // Generate a backup name
                    var timestamp = Util.GetTimestamp();

                    _backupName = BackupNamePrefix + timestamp;

                    if (!WhatIf)
                    {
                        db.Execute(string.Format("CREATE DATABASE {0} AS COPY OF {1}", _backupName, ConnectionString.InitialCatalog));
                        _startedBackup = true;
                    }

                    Log.Info("Started Copy of '{0}' to '{1}'", ConnectionString.InitialCatalog, _backupName);
                }
        }
示例#3
0
        private string CopyDatabaseForRestore(
            SqlExecutor masterDbExecutor)
        {
            var restoreDbName = $"Restore_{Util.GetTimestamp()}";

            Log.Info("Copying {0} to {1}.", BackupName, restoreDbName);
            masterDbExecutor.Execute($"CREATE DATABASE {restoreDbName} AS COPY OF {BackupName}");
            Log.Info("Waiting for copy to complete.");
            WaitForBackupCopy(
                masterDbExecutor,
                restoreDbName);
            return(restoreDbName);
        }