List of usage examples for com.amazonaws.services.rds.model DBSnapshot getDBSnapshotIdentifier
public String getDBSnapshotIdentifier()
Specifies the identifier for the DB snapshot.
From source file:com.github.blacklocus.rdsecho.EchoNew.java
License:Open Source License
@Override public Boolean call() throws Exception { // Do some sanity checks to make sure we aren't generating a bunch of trouble in RDS String tagEchoManaged = echo.getTagEchoManaged(); LOG.info("Checking to see if current echo-created instance (tagged {}) was created less than 24 hours ago. " + "If so this operation will not continue.", tagEchoManaged); Optional<DBInstance> newestInstanceOpt = echo.lastEchoInstance(); if (newestInstanceOpt.isPresent()) { if (new DateTime(newestInstanceOpt.get().getInstanceCreateTime()).plusHours(24) .isAfter(DateTime.now())) { LOG.info(" Last echo-created RDS instance {} was created less than 24 hours ago. Aborting.", tagEchoManaged);//from w w w . j av a 2s . com return false; } else { LOG.info(" Last echo-created RDS instance {} was created more than 24 hours ago. Proceeding.", tagEchoManaged); } } else { LOG.info(" No prior echo-created instance found with tag {}. Proceeding.", tagEchoManaged); } // Locate a suitable snapshot to be the basis of the new instance LOG.info("Locating latest snapshot from {}", cfg.snapshotDbInstanceIdentifier()); Optional<DBSnapshot> dbSnapshotOpt = echo.latestSnapshot(); if (dbSnapshotOpt.isPresent()) { DBSnapshot snapshot = dbSnapshotOpt.get(); LOG.info(" Located snapshot {} completed on {}", snapshot.getDBSnapshotIdentifier(), new DateTime(snapshot.getSnapshotCreateTime()).toDateTimeISO().toString()); } else { LOG.info(" Could not locate a suitable snapshot. Cannot continue."); return false; } // Info summary String dbSnapshotIdentifier = dbSnapshotOpt.get().getDBSnapshotIdentifier(); String newDbInstanceIdentifier = cfg.name() + '-' + DateTime.now(DateTimeZone.UTC).toString("yyyy-MM-dd"); LOG.info( "Proposed new db instance...\n" + " engine : {}\n" + " license model : {}\n" + " db instance class: {}\n" + " multi az : {}\n" + " storage type : {}\n" + " iops : {}\n" + " db snapshot id : {}\n" + " db instance id : {}\n" + " port : {}\n" + " option group name: {}\n" + " auto minor ver up: {}", cfg.newEngine(), cfg.newLicenseModel(), cfg.newDbInstanceClass(), cfg.newMultiAz(), cfg.newStorageType(), cfg.newIops(), dbSnapshotIdentifier, newDbInstanceIdentifier, cfg.newPort(), cfg.newOptionGroupName(), cfg.newAutoMinorVersionUpgrade()); // Interactive user confirmation if (cfg.interactive()) { String format = "Proceed to create a new DB instance from this snapshot? Input %s to confirm."; if (!EchoUtil.prompt(newDbInstanceIdentifier, format, newDbInstanceIdentifier)) { LOG.info("User declined to proceed. Exiting."); return false; } } // Create the new database LOG.info("Creating new DB instance. Hold on to your butts."); RestoreDBInstanceFromDBSnapshotRequest request = new RestoreDBInstanceFromDBSnapshotRequest() .withEngine(cfg.newEngine()).withLicenseModel(cfg.newLicenseModel()) .withDBInstanceClass(cfg.newDbInstanceClass()).withMultiAZ(cfg.newMultiAz()) .withStorageType(cfg.newStorageType()).withIops(cfg.newIops()) .withDBSnapshotIdentifier(dbSnapshotIdentifier).withDBInstanceIdentifier(newDbInstanceIdentifier) .withPort(cfg.newPort()).withOptionGroupName(cfg.newOptionGroupName()) .withAutoMinorVersionUpgrade(cfg.newAutoMinorVersionUpgrade()) .withTags(new Tag().withKey(echo.getTagEchoManaged()).withValue("true"), new Tag().withKey(echo.getTagEchoStage()).withValue(EchoConst.STAGE_NEW)); DBInstance restoredInstance = rds.restoreDBInstanceFromDBSnapshot(request); Optional<String[]> newTags = cfg.newTags(); if (newTags.isPresent()) { List<Tag> tags = EchoUtil.parseTags(newTags.get()); if (tags.size() > 0) { LOG.info("Applying tags on create new: {}", Arrays.asList(tags)); AddTagsToResourceRequest tagsRequest = new AddTagsToResourceRequest() .withResourceName(RdsFind.instanceArn(cfg.region(), cfg.accountNumber(), restoredInstance.getDBInstanceIdentifier())); tagsRequest.setTags(tags); rds.addTagsToResource(tagsRequest); } } LOG.info("Created new DB instance. \n" + " https://console.aws.amazon.com/rds/home?region={}#dbinstance:id={}\n" + "Additional preparation of the instance will continue once the instance becomes available.", cfg.region(), newDbInstanceIdentifier); return true; }
From source file:com.msi.tough.rdsquery.RDSQueryUtil.java
public static void marshalDBSnapshot(XMLNode parent, DBSnapshot o) { XMLNode n = QueryUtil.addNode(parent, RDS_Constants.NODE_DBSNAPSHOT); QueryUtil.addNode(n, RDS_Constants.NODE_ALLOCATEDSTORAGE, o.getAllocatedStorage()); QueryUtil.addNode(n, RDS_Constants.NODE_AVAILABILITYZONE, o.getAvailabilityZone()); QueryUtil.addNode(n, RDS_Constants.LICENSEMODEL, o.getLicenseModel()); QueryUtil.addNode(n, RDS_Constants.NODE_DBINSTANCEIDENTIFIER, o.getDBInstanceIdentifier()); QueryUtil.addNode(n, RDS_Constants.NODE_DBSNAPSHOTIDENTIFIER, o.getDBSnapshotIdentifier()); QueryUtil.addNode(n, RDS_Constants.NODE_ENGINE, o.getEngine()); QueryUtil.addNode(n, RDS_Constants.NODE_ENGINEVERSION, o.getEngineVersion()); QueryUtil.addNode(n, RDS_Constants.NODE_INSTANCECREATETIME, o.getInstanceCreateTime()); QueryUtil.addNode(n, RDS_Constants.NODE_MASTERUSERNAME, o.getMasterUsername()); QueryUtil.addNode(n, RDS_Constants.NODE_PORT, o.getPort()); QueryUtil.addNode(n, RDS_Constants.NODE_SNAPSHOTCREATETIME, o.getSnapshotCreateTime()); QueryUtil.addNode(n, RDS_Constants.NODE_STATUS, o.getStatus()); }