def restore_snapshots(): """ Restore snapshot into correct directories. Returns: True on success, False otherwise. """ logging.info("Restoring Cassandra snapshots.") for directory in CASSANDRA_DATA_SUBDIRS: data_dir = "{0}{1}/{2}/".format(constants.APPSCALE_DATA_DIR, "cassandra", directory) logging.debug("Restoring in dir {0}".format(data_dir)) for path, _, filenames in os.walk(data_dir): for filename in filenames: logging.debug("Restoring: {0}".format(filename)) if not filename: logging.warn("skipping...") continue full_path = "{0}/{1}".format(path, filename) new_full_path = "{0}/../../{1}".format(path, filename) logging.debug("{0} -> {1}".format(full_path, new_full_path)) # Move the files up into the data directory. if not backup_recovery_helper.rename(full_path, new_full_path): logging.error("Error while moving Cassandra snapshot in place. " "Aborting restore...") return False logging.info("Done restoring Cassandra snapshots.") return True
def tar_backup_files(file_paths): """ Tars all snapshot files for a given snapshot name. Args: file_paths: A list of files to tar up. Returns: The path to the tar file, None otherwise. """ backup_file_location = BACKUP_FILE_LOCATION if not enough_disk_space(): logging.error("There's not enough available space to create another " "backup.") return None # Rename previous backup, if it exists. if not backup_recovery_helper.rename(backup_file_location, "{0}{1}". format(backup_file_location, BACKUP_ROLLBACK_SUFFIX)): logging.warning("'{0}' not found. Skipping file rename...". format(backup_file_location)) # Tar up the backup files. tar = tarfile.open(backup_file_location, "w:gz") for name in file_paths: tar.add(name) tar.close() return backup_file_location
def restore_snapshots(): """ Restore snapshot into correct directories. Returns: True on success, False otherwise. """ logging.info("Restoring Cassandra snapshots.") for directory in CASSANDRA_DATA_SUBDIRS: data_dir = "{0}{1}/{2}/".format(APPSCALE_DATA_DIR, "cassandra", directory) logging.debug("Restoring in dir {0}".format(data_dir)) for path, _, filenames in os.walk(data_dir): for filename in filenames: logging.debug("Restoring: {0}".format(filename)) if not filename: logging.warn("skipping...") continue full_path = "{0}/{1}".format(path, filename) new_full_path = "{0}/../../{1}".format(path, filename) logging.debug("{0} -> {1}".format(full_path, new_full_path)) # Move the files up into the data directory. if not backup_recovery_helper.rename(full_path, new_full_path): logging.error("Error while moving Cassandra snapshot in place. " "Aborting restore...") return False logging.info("Done restoring Cassandra snapshots.") return True
def tar_backup_files(file_paths): """ Tars all snapshot files for a given snapshot name. Args: file_paths: A list of files to tar up. Returns: The path to the tar file, None otherwise. """ backup_file_location = BACKUP_FILE_LOCATION if not enough_disk_space(): logging.error("There's not enough available space to create another " "backup.") return None # Rename previous backup, if it exists. if not backup_recovery_helper.rename( backup_file_location, "{0}{1}".format(backup_file_location, BACKUP_ROLLBACK_SUFFIX)): logging.warning("'{0}' not found. Skipping file rename...".format( backup_file_location)) # Tar up the backup files. tar = tarfile.open(backup_file_location, "w:gz") for name in file_paths: tar.add(name) tar.close() return backup_file_location
def move_secondary_backup(): """ Moves the secondary backup back in place, if it exists, upon an un successful backup attempt. """ if not backup_recovery_helper.rename( "{0}{1}".format(BACKUP_FILE_LOCATION, BACKUP_ROLLBACK_SUFFIX), BACKUP_FILE_LOCATION): logging.warning("No secondary backup to restore. Skipping...")
def move_secondary_backup(): """ Moves the secondary backup back in place, if it exists, upon an un successful backup attempt. """ if not backup_recovery_helper.rename("{0}{1}".format(BACKUP_FILE_LOCATION, BACKUP_ROLLBACK_SUFFIX), BACKUP_FILE_LOCATION): logging.warning("No secondary backup to restore. Skipping...")
def test_rename(self): flexmock(os).should_receive('rename').and_return().at_least().times(1) self.assertEquals(True, backup_recovery_helper.rename('foo', 'bar')) flexmock(os).should_receive('rename').and_raise(OSError) self.assertEquals(False, backup_recovery_helper.rename('foo', 'bar'))