This commit is contained in:
Michael 2017-03-25 19:57:06 -04:00
parent bdfa66ec39
commit 416b924175

View file

@ -110,7 +110,7 @@ public ActionResult CreateUser(CreateUserModel model)
return RedirectToAction("Users"); return RedirectToAction("Users");
} }
public ActionResult BackupDatabase() public ActionResult BackupAssets()
{ {
var db = new ApplicationDbContext(); var db = new ApplicationDbContext();
string backupDir = "~/Backups/Database"; string backupDir = "~/Backups/Database";
@ -123,17 +123,17 @@ public ActionResult BackupDatabase()
System.IO.Compression.ZipFile.CreateFromDirectory(Server.MapPath("~/Uploads"), backupname); System.IO.Compression.ZipFile.CreateFromDirectory(Server.MapPath("~/Uploads"), backupname);
var backupData = new DatabaseBackup(); var backupData = new AssetBackup();
backupData.Id = Guid.NewGuid().ToString(); backupData.Id = Guid.NewGuid().ToString();
backupData.UserId = User.Identity.GetUserId(); backupData.UserId = User.Identity.GetUserId();
backupData.DownloadUrl = backupUrl; backupData.DownloadUrl = backupUrl;
backupData.Timestamp = DateTime.Now; backupData.Timestamp = DateTime.Now;
db.Backups.Add(backupData); db.AssetBackups.Add(backupData);
db.SaveChanges(); db.SaveChanges();
return RedirectToAction("Backups"); return RedirectToAction("Backups");
} }
public ActionResult BackupAssets() public ActionResult BackupDatabase()
{ {
var db = new ApplicationDbContext(); var db = new ApplicationDbContext();
string backupDir = "~/Backups/Assets"; string backupDir = "~/Backups/Assets";
@ -145,12 +145,12 @@ public ActionResult BackupAssets()
string backupname = backupServerDir + "\\ShiftOS-" + DateTime.Now.ToString() + ".sql"; string backupname = backupServerDir + "\\ShiftOS-" + DateTime.Now.ToString() + ".sql";
const string sqlCommand = @"BACKUP DATABASE [{0}] TO DISK = N'{1}' WITH NOFORMAT, NOINIT, NAME = N'ShiftOS Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10"; const string sqlCommand = @"BACKUP DATABASE [{0}] TO DISK = N'{1}' WITH NOFORMAT, NOINIT, NAME = N'ShiftOS Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10";
int path = db.Database.ExecuteSqlCommand(System.Data.Entity.TransactionalBehavior.DoNotEnsureTransaction, string.Format(sqlCommand, db.Database.Connection.Database, backupname)); int path = db.Database.ExecuteSqlCommand(System.Data.Entity.TransactionalBehavior.DoNotEnsureTransaction, string.Format(sqlCommand, db.Database.Connection.Database, backupname));
var backupData = new AssetBackup(); var backupData = new DatabaseBackup();
backupData.Id = Guid.NewGuid().ToString(); backupData.Id = Guid.NewGuid().ToString();
backupData.UserId = User.Identity.GetUserId(); backupData.UserId = User.Identity.GetUserId();
backupData.DownloadUrl = backupUrl; backupData.DownloadUrl = backupUrl;
backupData.Timestamp = DateTime.Now; backupData.Timestamp = DateTime.Now;
db.AssetBackups.Add(backupData); db.Backups.Add(backupData);
db.SaveChanges(); db.SaveChanges();
return RedirectToAction("Backups"); return RedirectToAction("Backups");
} }