internal async Task <string> Clone(SnapSession session) { try { PrimaryBackup b = new PrimaryBackup(); b.BackupName = session.BackupName; CloneBody body = new CloneBody(); CloneConfigurationApplication cloneConfApp = new CloneConfigurationApplication(); cloneConfApp.type = "SMCoreContracts.SmSCCloneConfiguration, SMCoreContracts"; cloneConfApp.MountCmd = new System.Collections.Generic.List <string>(); cloneConfApp.MountCmd.Add($"mount {session.LeafIP}:%mysql_vol_Clone {session.MountPath}"); cloneConfApp.PostCloneCreateCmd = new System.Collections.Generic.List <string>(); cloneConfApp.PostCloneCreateCmd.Add($"{session.MountScript}"); cloneConfApp.Host = session.CloneHostName; CloneConfiguration conf = new CloneConfiguration(); conf.type = "SMCoreContracts.SmCloneConfiguration, SMCoreContracts"; conf.Suffix = string.Empty; // string.Format("_{0}", session.AppName); //set app alias to distiguish clones conf.CloneConfigurationApplication = cloneConfApp; body.CloneConfiguration = conf; body.Backups = new System.Collections.Generic.List <Backups>(); Backups back = new Backups(); back.PrimaryBackup = b; body.Backups.Add(back); var response = await this.SendRequestAsync <dynamic>(Method.POST, $"api/3.0/plugins/{session.Plugin}/resources/{session.DbKey}/clone", body, false); return(response.Response.StatusCode.ToString()); } catch (Exception ex) { this.log.Error($"Error while cloning {session.DbKey}: {ex}"); throw; } }
internal async Task <string> RestoreClone(SnapSession session) { try { session.HostName = session.CloneHostName; log.Info($"restoring clone with session: {session.toString()}"); session.DbKey = await this.GetDbKey(session, false); log.Info($"DB Key of the clone received: {session.DbKey}"); // Got Junction Path : This parameter is needed for Restore API Call session.JunctionPath = await this.GetJunctionPath(session, false); log.Info($"JunctionPath of the clone received: {session.JunctionPath}"); PrimaryBackup b = new PrimaryBackup(); b.BackupName = session.BackupName; RestoreBody body = new RestoreBody(); RestoreConfiguration cloneConfApp = new RestoreConfiguration(); cloneConfApp.type = "SMCoreContracts.SmSCRestoreConfiguration, SMCoreContracts"; //Extra Parameters needed in Restore Body:- cloneConfApp.MountCommands = new System.Collections.Generic.List <string>(); cloneConfApp.MountCommands.Add($"mount {session.LeafIP}:{session.JunctionPath} {session.MountPath} ; sleep 3; /var/lib/start-mysql.sh"); cloneConfApp.UnMountCommands = new System.Collections.Generic.List <string>(); cloneConfApp.UnMountCommands.Add($"killall -KILL mysqld ; sleep 3 ; umount {session.MountPath}"); Backups back = new Backups(); back.PrimaryBackup = b; body.BackupInfo = back; body.PluginCode = "SCC"; body.RestoreLastBackup = 0; body.Configuration = cloneConfApp; var response = await this.SendRequestAsync <dynamic>(Method.POST, $"api/3.0/plugins/{session.Plugin}/resources/{session.DbKey}/restore", body, false); return(response.Response.StatusCode.ToString()); } catch (Exception ex) { this.log.Error($"Error while cloning {session.DbKey}: {ex}"); throw; } }