示例#1
0
文件: backup.py 项目: quaddra/engage
def save_engage_files(backup_directory, deployment_home, logger, compress):
    # Save all of engage's directories.
    # These are always copied rather than moved, as the backup
    # utility itself is run from one of these directories.
    files = [os.path.join(deployment_home, subdir) for subdir in ["config", "engage", "python"]]
    if compress:
        backup_archive = os.path.join(backup_directory, "engage_files.tar.gz")
    else:
        backup_archive = os.path.join(backup_directory, "engage_files.tar")
    logger.info("Saving engage files to %s" % backup_archive)
    backup.save(files, backup_archive, move=False)
    # installed resources and config choices are used in upgrade,
    # so have convenience copies that aren't tarred
    installed_resources_file = os.path.join(deployment_home, "config/installed_resources.json")
    shutil.copyfile(installed_resources_file, os.path.join(backup_directory, "installed_resources.json"))
    config_choices_file = os.path.join(deployment_home, "config/config_choices.json")
    if os.path.exists(config_choices_file):
        shutil.copyfile(config_choices_file, os.path.join(backup_directory, "config_choices.json"))
 def backup(self, backup_to_directory, compress=True):
     backup_location = self._get_backup_location(backup_to_directory, self.id, compress)
     logger.debug("Saving resource %s files to %s" % (self.id, backup_location))
     files = self._get_backup_file_list()
     if len(files) == 0:
         raise UserError(errors[ERR_BACKUP_FILE_LIST_EMPTY], msg_args={"id": self.id})
     try:
         if os.geteuid() != 0 and backup.check_if_save_requires_superuser(files):
             logger.info("Running backup via sudo for resource %s" % self.id)
             backup.save_as_sudo_subprocess(files, backup_location, self._get_sudo_password(), move=False)
         else:
             backup.save(files, backup_location, move=False)
     except:
         exc_info = (exc_tp, exc_v, ecx_tb) = sys.exc_info()
         raise convert_exc_to_user_error(
             exc_info,
             errors[EXC_IN_BACKUP_CALL],
             msg_args={"id": self.id, "file": backup_location, "exc_typ": exc_tp.__name__, "exc_val": exc_v},
         )