public void Backup(BackupParameters parameters) { var server = new Server(parameters.Server); try { server.ConnectionContext.LoginSecure = true; server.ConnectionContext.Connect(); var backup = new Backup { Action = BackupActionType.Database, Database = parameters.DatabaseName }; var backupPath = GenerateBackupPath(parameters); Logger.WriteLine("Backing up to {0}", backupPath); backup.Devices.AddDevice(backupPath, DeviceType.File); backup.BackupSetName = string.Format("{0} backup", parameters.DatabaseName); backup.PercentComplete += HandlePercentComplete; backup.Complete += HandleComplete; Logger.WriteLine("Running backup..."); backup.SqlBackup(server); } finally { if (server.ConnectionContext.IsOpen) { Logger.Write("Closing connection..."); server.ConnectionContext.Disconnect(); Logger.WriteLine("OK"); } } }
private string GenerateBackupPath(BackupParameters parameters) { if (parameters.FilePath.IsNotNullOrEmpty()) { return(Path.IsPathRooted(parameters.FilePath) ? parameters.FilePath : Path.Combine(Settings.BackupDirectory, parameters.FilePath)); } var filename = string.Format("{0}_{1}.bak", parameters.DatabaseName, DateTime.Now.ToString("yyyyMMdd_hhmmss")); return(Path.Combine(Settings.BackupDirectory, filename)); }
static void Main(string[] args) { System.Console.WriteLine(System.Environment.CommandLine); BackupParameters param = ProcessCommandLine(args); Backup b = new Backup(); b.BackupErrorMessage += new Backup.BackupErrorMessageDelegate(BackupErrorMessageHandler); b.BackupUpdate += new Backup.BackupUpdateDelegate(BackupUpdateHandler); FileList files = b.GetFiles(selectionList, filter, param); System.Console.WriteLine($"Backing Up {files.Count:n0} files {files.totalBytes:n0} bytes"); b.DoBackup(files, param); }
public void Restore(BackupParameters parameters) { var databaseName = parameters.DatabaseName; var filePath = GetFullPathFrom(parameters.FilePath); Logger.WriteLine("Restoring {0} from file {1}", databaseName, filePath); var server = new Server(parameters.Server); try { server.ConnectionContext.LoginSecure = true; server.ConnectionContext.Connect(); var restore = new Restore { Database = databaseName, Action = RestoreActionType.Database }; restore.Devices.AddDevice(filePath, DeviceType.File); restore.ReplaceDatabase = true; var database = server.Databases[databaseName]; if (database == null) { Logger.WriteLine("Database {0} does not exist", databaseName); return; } var users = server.GetLoginUsers(database); Logger.WriteLine("User mappings to restore: {0}", string.Join(",", users)); RelocateFiles(database, restore); server.RenewConnection(); restore.PercentComplete += HandlePercentComplete; restore.Complete += HandleComplete; restore.SqlRestore(server); RestoreUserMappings(server, users, databaseName); } finally { if (server.ConnectionContext.IsOpen) { Logger.Write("Closing connection..."); server.ConnectionContext.Disconnect(); Logger.WriteLine("OK"); } } }
public override void DoExecute(CommandArgs args) { var connectionData = Settings.GetConnection(args.Arguments[0]); var parameters = new BackupParameters { DatabaseName = connectionData.Name, FilePath = args.Arguments[1], Server = connectionData.Host }; var restoreTask = TaskFactory.CreateRestoreTask(connectionData); restoreTask.PercentComplete += PrintPercentage; restoreTask.Complete += TaskComplete; restoreTask.Restore(parameters); }
public AdbViewModel() { ThreeTextCommandParameters = new ThreeTextCommandParameters(); FiveTextCommandParameters = new FiveTextCommandParameters(); InstallTwoCommandParameters = new TwoCommandParameters(); UninstallTwoCommandParameters = new TwoCommandParameters(); UiParameters = new UIParameters(); ExecuteSingleCommandParameters = new TwoCommandParameters(); CopyCommandParameters = new ThreeTextCommandParameters(); MoveCommandParameters = new ThreeTextCommandParameters(); DeleteCommandParameters = new TwoCommandParameters(); SideloadParameters = new TwoCommandParameters(); ExecuteCommandsParameters = new ExecuteCommandParameters(); BackupParameters = new BackupParameters(); RestoreParameters = new TwoCommandParameters(); RemoteConnectParameters = new ThreeTextCommandParameters(); RemoteDisconnectParameters = new SingleCommandParameters(); RemoteSaveParameters = new ThreeTextCommandParameters(); _remoteInfoRepository = ((ViewModelLocator)Application.Current.Resources["Locator"]).RemoteInfoRepository; }
public static void ExecuteBackup(object parameter) { BackupParameters parameters = parameter as BackupParameters; if (parameters != null) { Context = parameters.Context; BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += async(sender, args) => { await Context.Dispatcher.InvokeAsync(async() => { _adb = new AdbTools(Context); if (parameters.Context2.SelectedIndex == 0) { await _adb.Backup(parameters.Text, parameters.Text2, AdbBackupMode.All, parameters.Bool, parameters.Target); } if (parameters.Context2.SelectedIndex == 1) { await _adb.Backup(parameters.Text, parameters.Text2, AdbBackupMode.Apps, parameters.Bool, parameters.Target); } if (parameters.Context2.SelectedIndex == 2) { await _adb.Backup(parameters.Text, parameters.Text2, AdbBackupMode.SystemApps, parameters.Bool, parameters.Target); } if (parameters.Context2.SelectedIndex == 3) { await _adb.Backup(parameters.Text, parameters.Text2, AdbBackupMode.AppsWithoutSystemApps, parameters.Bool, parameters.Target); } if (parameters.Context2.SelectedIndex == 4) { await _adb.Backup(parameters.Text, parameters.Text2, AdbBackupMode.SDCard, parameters.Bool, parameters.Target); } }); }; worker.RunWorkerCompleted += (sender, args) => worker.Dispose(); worker.RunWorkerAsync(); } }
static BackupParameters ProcessCommandLine(string[] args) { BackupParameters param = new BackupParameters(); int index = 0; while (index < args.Length) { string arg = args[index]; string nextArg = index + 1 < args.Length ? args[index + 1] : ""; switch (arg) { case "--type": if (nextArg == "Full") { param.type = EBackupType.Full; } else if (nextArg == "Incremental") { param.type = EBackupType.Incremental; } else { throw new ApplicationException($"Unknown backup type '{nextArg}'"); } index++; break; case "--fileList": if (!File.Exists(nextArg)) { throw new ApplicationException($"Can't find include file '{nextArg}'"); } else { string[] files = File.ReadAllLines(nextArg); foreach (var f in files) { selectionList.Add(f); } } index++; break; case "--excludeList": if (!File.Exists(nextArg)) { throw new ApplicationException($"Can't find exclusion file '{nextArg}'"); } else { string[] files = File.ReadAllLines(nextArg); foreach (var f in files) { filter.Add(f); } } index++; break; case "--lastBackup": { DateTime dt; if (DateTime.TryParse(nextArg, out dt)) { param.lastBackup = dt; } else { throw new ApplicationException($"Can't understand --lastBackup datetime '{nextArg}'"); } } index++; break; case "--outputPath": param.outputDirectory = nextArg; index++; break; case "--backupName": param.backupName = nextArg; index++; break; case "--help": System.Console.WriteLine(helpText); System.Environment.Exit(0); break; } index++; } System.Console.WriteLine("Backup Starting..."); System.Console.WriteLine($"Backup Name {param.backupName}"); System.Console.WriteLine($"Backup Time {param.backupTime}"); System.Console.WriteLine($"Last Backup Time {param.lastBackup}"); System.Console.WriteLine($"Output Directory {param.outputDirectory}"); System.Console.WriteLine($"Backup Type {param.type}"); return(param); }